grep: turn off gitlink detection for --no-index
[gitweb.git] / builtin / clone.c
index 2dabce9816cdd5a98c45c7fca968a8a98ec945e9..661639255c564acf3f811e20a0ca3141805cde5d 100644 (file)
@@ -47,6 +47,7 @@ static const char *real_git_dir;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress = -1;
+static enum transport_family family;
 static struct string_list option_config;
 static struct string_list option_reference;
 static int option_dissociate;
@@ -92,6 +93,10 @@ static struct option builtin_clone_options[] = {
                   N_("separate git dir from working tree")),
        OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
                        N_("set config inside the new repository")),
+       OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
+                       TRANSPORT_FAMILY_IPV4),
+       OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
+                       TRANSPORT_FAMILY_IPV6),
        OPT_END()
 };
 
@@ -231,8 +236,8 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
        strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git");
 
        if (!len || (len == 1 && *start == '/'))
-           die("No directory name could be guessed.\n"
-               "Please specify a directory on the command line");
+               die(_("No directory name could be guessed.\n"
+                     "Please specify a directory on the command line"));
 
        if (is_bare)
                dir = xstrfmt("%.*s.git", (int)len, start);
@@ -339,7 +344,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
        FILE *in = fopen(src->buf, "r");
        struct strbuf line = STRBUF_INIT;
 
-       while (strbuf_getline(&line, in, '\n') != EOF) {
+       while (strbuf_getline(&line, in) != EOF) {
                char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
@@ -636,9 +641,11 @@ static void update_remote_refs(const struct ref *refs,
                struct strbuf head_ref = STRBUF_INIT;
                strbuf_addstr(&head_ref, branch_top);
                strbuf_addstr(&head_ref, "HEAD");
-               create_symref(head_ref.buf,
-                             remote_head_points_at->peer_ref->name,
-                             msg);
+               if (create_symref(head_ref.buf,
+                                 remote_head_points_at->peer_ref->name,
+                                 msg) < 0)
+                       die(_("unable to update %s"), head_ref.buf);
+               strbuf_release(&head_ref);
        }
 }
 
@@ -648,7 +655,8 @@ static void update_head(const struct ref *our, const struct ref *remote,
        const char *head;
        if (our && skip_prefix(our->name, "refs/heads/", &head)) {
                /* Local default branch link */
-               create_symref("HEAD", our->name, NULL);
+               if (create_symref("HEAD", our->name, NULL) < 0)
+                       die(_("unable to update HEAD"));
                if (!option_bare) {
                        update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0,
                                   UPDATE_REFS_DIE_ON_ERR);
@@ -732,7 +740,7 @@ static int checkout(void)
 
 static int write_one_config(const char *key, const char *value, void *data)
 {
-       return git_config_set_multivar(key, value ? value : "true", "^$", 0);
+       return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0);
 }
 
 static void write_config(struct string_list *config)
@@ -742,7 +750,7 @@ static void write_config(struct string_list *config)
        for (i = 0; i < config->nr; i++) {
                if (git_config_parse_parameter(config->items[i].string,
                                               write_one_config, NULL) < 0)
-                       die("unable to write parameters to config file");
+                       die(_("unable to write parameters to config file"));
        }
 }
 
@@ -783,12 +791,12 @@ static void write_refspec_config(const char *src_ref_prefix,
                /* Configure the remote */
                if (value.len) {
                        strbuf_addf(&key, "remote.%s.fetch", option_origin);
-                       git_config_set_multivar_or_die(key.buf, value.buf, "^$", 0);
+                       git_config_set_multivar(key.buf, value.buf, "^$", 0);
                        strbuf_reset(&key);
 
                        if (option_mirror) {
                                strbuf_addf(&key, "remote.%s.mirror", option_origin);
-                               git_config_set_or_die(key.buf, "true");
+                               git_config_set(key.buf, "true");
                                strbuf_reset(&key);
                        }
                }
@@ -946,14 +954,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        src_ref_prefix = "refs/";
                strbuf_addstr(&branch_top, src_ref_prefix);
 
-               git_config_set_or_die("core.bare", "true");
+               git_config_set("core.bare", "true");
        } else {
                strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
        }
 
        strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
        strbuf_addf(&key, "remote.%s.url", option_origin);
-       git_config_set_or_die(key.buf, repo);
+       git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
        if (option_reference.nr)
@@ -967,6 +975,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        remote = remote_get(option_origin);
        transport = transport_get(remote, remote->url[0]);
        transport_set_verbosity(transport, option_verbosity, option_progress);
+       transport->family = family;
 
        path = get_repo_path(remote->url[0], &is_bundle);
        is_local = option_local != 0 && path && !is_bundle;