clone: read new remote name from remote_name instead of option_origin
In a future patch, the name of the remote created by `git clone` may come from multiple sources. To avoid confusion, convert most uses of option_origin to remote_name, leaving option_origin to exclusively represent the -o/--origin option. Helped-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Sean Barag <sean@barag.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sean Barag committed
Oct 1, 2020 at 03:46 UTC
75ca3906b1ea6a00a20ef16c889e9d6a15a8defc
1 file changed
+16
-15
builtin/clone.c
+16
-15
@@ -53,6 +53,7 @@ static int option_shallow_submodules;
53
static int deepen;
54
static char *option_template, *option_depth, *option_since;
55
static char *option_origin = NULL;
56
+static char *remote_name = "origin";
57
static char *option_branch = NULL;
58
static struct string_list option_not = STRING_LIST_INIT_NODUP;
59
static const char *real_git_dir;
@@ -721,7 +722,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
722
if (!option_bare) {
723
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
724
UPDATE_REFS_DIE_ON_ERR);
724
- install_branch_config(0, head, option_origin, our->name);
725
+ install_branch_config(0, head, remote_name, our->name);
726
}
727
} else if (our) {
728
struct commit *c = lookup_commit_reference(the_repository,
@@ -919,12 +920,12 @@ static void write_refspec_config(const char *src_ref_prefix,
920
}
921
/* Configure the remote */
922
if (value.len) {
922
- strbuf_addf(&key, "remote.%s.fetch", option_origin);
923
+ strbuf_addf(&key, "remote.%s.fetch", remote_name);
924
git_config_set_multivar(key.buf, value.buf, "^$", 0);
925
strbuf_reset(&key);
926
927
if (option_mirror) {
927
- strbuf_addf(&key, "remote.%s.mirror", option_origin);
928
+ strbuf_addf(&key, "remote.%s.mirror", remote_name);
929
git_config_set(key.buf, "true");
930
strbuf_reset(&key);
931
}
@@ -1009,11 +1010,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1010
option_no_checkout = 1;
1011
}
1012
1012
- if (!option_origin)
1013
- option_origin = "origin";
1013
+ if (option_origin)
1014
+ remote_name = option_origin;
1015
1015
- if (!valid_remote_name(option_origin))
1016
- die(_("'%s' is not a valid remote name"), option_origin);
1016
+ if (!valid_remote_name(remote_name))
1017
+ die(_("'%s' is not a valid remote name"), remote_name);
1018
1019
repo_name = argv[0];
1020
@@ -1164,15 +1165,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1165
1166
git_config_set("core.bare", "true");
1167
} else {
1167
- strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
1168
+ strbuf_addf(&branch_top, "refs/remotes/%s/", remote_name);
1169
}
1170
1170
- strbuf_addf(&key, "remote.%s.url", option_origin);
1171
+ strbuf_addf(&key, "remote.%s.url", remote_name);
1172
git_config_set(key.buf, repo);
1173
strbuf_reset(&key);
1174
1175
if (option_no_tags) {
1175
- strbuf_addf(&key, "remote.%s.tagOpt", option_origin);
1176
+ strbuf_addf(&key, "remote.%s.tagOpt", remote_name);
1177
git_config_set(key.buf, "--no-tags");
1178
strbuf_reset(&key);
1179
}
@@ -1183,7 +1184,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1184
if (option_sparse_checkout && git_sparse_checkout_init(dir))
1185
return 1;
1186
1186
- remote = remote_get(option_origin);
1187
+ remote = remote_get(remote_name);
1188
1189
strbuf_addf(&default_refspec, "+%s*:%s*", src_ref_prefix,
1190
branch_top.buf);
@@ -1296,7 +1297,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1297
1298
if (!our_head_points_at)
1299
die(_("Remote branch %s not found in upstream %s"),
1299
- option_branch, option_origin);
1300
+ option_branch, remote_name);
1301
}
1302
else
1303
our_head_points_at = remote_head_points_at;
@@ -1304,7 +1305,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1305
else {
1306
if (option_branch)
1307
die(_("Remote branch %s not found in upstream %s"),
1307
- option_branch, option_origin);
1308
+ option_branch, remote_name);
1309
1310
warning(_("You appear to have cloned an empty repository."));
1311
mapped_refs = NULL;
@@ -1316,7 +1317,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1317
const char *branch = git_default_branch_name();
1318
char *ref = xstrfmt("refs/heads/%s", branch);
1319
1319
- install_branch_config(0, branch, option_origin, ref);
1320
+ install_branch_config(0, branch, remote_name, ref);
1321
free(ref);
1322
}
1323
}
@@ -1325,7 +1326,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1326
remote_head_points_at, &branch_top);
1327
1328
if (filter_options.choice)
1328
- partial_clone_register(option_origin, &filter_options);
1329
+ partial_clone_register(remote_name, &filter_options);
1330
1331
if (is_local)
1332
clone_local(path, git_dir);