Code

do not depend on signed integer overflow
[git.git] / builtin / clone.c
index 3a3625b2ad97472c8486c9fbdd4ac6333699a37d..19ed64041d0575ee1ad49071dfe1e671114b8ae3 100644 (file)
@@ -361,7 +361,7 @@ static void write_remote_refs(const struct ref *local_refs)
 
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
-       int is_bundle = 0;
+       int is_bundle = 0, is_local;
        struct stat buf;
        const char *repo_name, *repo, *work_tree, *git_dir;
        char *path, *dir;
@@ -414,6 +414,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                repo = xstrdup(make_absolute_path(repo_name));
        else
                repo = repo_name;
+       is_local = path && !is_bundle;
+       if (is_local && option_depth)
+               warning("--depth is ignored in local clones; use file:// instead.");
 
        if (argc == 2)
                dir = xstrdup(argv[1]);
@@ -475,9 +478,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
         */
        unsetenv(CONFIG_ENVIRONMENT);
 
-       if (option_reference)
-               setup_reference(git_dir);
-
        git_config(git_default_config, NULL);
 
        if (option_bare) {
@@ -503,22 +503,25 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        git_config_set(key.buf, "true");
                        strbuf_reset(&key);
                }
-
-               strbuf_addf(&key, "remote.%s.url", option_origin);
-               git_config_set(key.buf, repo);
-               strbuf_reset(&key);
        }
 
+       strbuf_addf(&key, "remote.%s.url", option_origin);
+       git_config_set(key.buf, repo);
+       strbuf_reset(&key);
+
+       if (option_reference)
+               setup_reference(git_dir);
+
        fetch_pattern = value.buf;
        refspec = parse_fetch_refspec(1, &fetch_pattern);
 
        strbuf_reset(&value);
 
-       if (path && !is_bundle) {
+       if (is_local) {
                refs = clone_local(path, git_dir);
                mapped_refs = wanted_peer_refs(refs, refspec);
        } else {
-               struct remote *remote = remote_get(argv[0]);
+               struct remote *remote = remote_get(option_origin);
                transport = transport_get(remote, remote->url[0]);
 
                if (!transport->get_refs_list || !transport->fetch)