Skip to content

Commit 75ca390

Browse files
sjbaraggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Sean Barag <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebe7e28 commit 75ca390

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

builtin/clone.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static int option_shallow_submodules;
5353
static int deepen;
5454
static char *option_template, *option_depth, *option_since;
5555
static char *option_origin = NULL;
56+
static char *remote_name = "origin";
5657
static char *option_branch = NULL;
5758
static struct string_list option_not = STRING_LIST_INIT_NODUP;
5859
static const char *real_git_dir;
@@ -721,7 +722,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
721722
if (!option_bare) {
722723
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
723724
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);
725726
}
726727
} else if (our) {
727728
struct commit *c = lookup_commit_reference(the_repository,
@@ -919,12 +920,12 @@ static void write_refspec_config(const char *src_ref_prefix,
919920
}
920921
/* Configure the remote */
921922
if (value.len) {
922-
strbuf_addf(&key, "remote.%s.fetch", option_origin);
923+
strbuf_addf(&key, "remote.%s.fetch", remote_name);
923924
git_config_set_multivar(key.buf, value.buf, "^$", 0);
924925
strbuf_reset(&key);
925926

926927
if (option_mirror) {
927-
strbuf_addf(&key, "remote.%s.mirror", option_origin);
928+
strbuf_addf(&key, "remote.%s.mirror", remote_name);
928929
git_config_set(key.buf, "true");
929930
strbuf_reset(&key);
930931
}
@@ -1009,11 +1010,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10091010
option_no_checkout = 1;
10101011
}
10111012

1012-
if (!option_origin)
1013-
option_origin = "origin";
1013+
if (option_origin)
1014+
remote_name = option_origin;
10141015

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);
10171018

10181019
repo_name = argv[0];
10191020

@@ -1164,15 +1165,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11641165

11651166
git_config_set("core.bare", "true");
11661167
} else {
1167-
strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
1168+
strbuf_addf(&branch_top, "refs/remotes/%s/", remote_name);
11681169
}
11691170

1170-
strbuf_addf(&key, "remote.%s.url", option_origin);
1171+
strbuf_addf(&key, "remote.%s.url", remote_name);
11711172
git_config_set(key.buf, repo);
11721173
strbuf_reset(&key);
11731174

11741175
if (option_no_tags) {
1175-
strbuf_addf(&key, "remote.%s.tagOpt", option_origin);
1176+
strbuf_addf(&key, "remote.%s.tagOpt", remote_name);
11761177
git_config_set(key.buf, "--no-tags");
11771178
strbuf_reset(&key);
11781179
}
@@ -1183,7 +1184,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11831184
if (option_sparse_checkout && git_sparse_checkout_init(dir))
11841185
return 1;
11851186

1186-
remote = remote_get(option_origin);
1187+
remote = remote_get(remote_name);
11871188

11881189
strbuf_addf(&default_refspec, "+%s*:%s*", src_ref_prefix,
11891190
branch_top.buf);
@@ -1296,15 +1297,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12961297

12971298
if (!our_head_points_at)
12981299
die(_("Remote branch %s not found in upstream %s"),
1299-
option_branch, option_origin);
1300+
option_branch, remote_name);
13001301
}
13011302
else
13021303
our_head_points_at = remote_head_points_at;
13031304
}
13041305
else {
13051306
if (option_branch)
13061307
die(_("Remote branch %s not found in upstream %s"),
1307-
option_branch, option_origin);
1308+
option_branch, remote_name);
13081309

13091310
warning(_("You appear to have cloned an empty repository."));
13101311
mapped_refs = NULL;
@@ -1316,7 +1317,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13161317
const char *branch = git_default_branch_name();
13171318
char *ref = xstrfmt("refs/heads/%s", branch);
13181319

1319-
install_branch_config(0, branch, option_origin, ref);
1320+
install_branch_config(0, branch, remote_name, ref);
13201321
free(ref);
13211322
}
13221323
}
@@ -1325,7 +1326,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13251326
remote_head_points_at, &branch_top);
13261327

13271328
if (filter_options.choice)
1328-
partial_clone_register(option_origin, &filter_options);
1329+
partial_clone_register(remote_name, &filter_options);
13291330

13301331
if (is_local)
13311332
clone_local(path, git_dir);

0 commit comments

Comments
 (0)