remote set-head: set followRemoteHEAD to "warn" if "always"
When running "remote set-head" manually it is unlikely, that the user would actually like to have "fetch" always update the remote/HEAD. On the contrary, it is more likely, that the user would expect remote/HEAD to stay the way they manually set it, and just forgot about having "followRemoteHEAD" set to "always". When "followRemoteHEAD" is set to "always" make running "remote set-head" change the config to "warn". Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
9e2b7005be
commit
012bc566ba
@@ -1433,6 +1433,7 @@ static int set_head(int argc, const char **argv, const char *prefix)
|
|||||||
b_local_head = STRBUF_INIT;
|
b_local_head = STRBUF_INIT;
|
||||||
char *head_name = NULL;
|
char *head_name = NULL;
|
||||||
struct ref_store *refs = get_main_ref_store(the_repository);
|
struct ref_store *refs = get_main_ref_store(the_repository);
|
||||||
|
struct remote *remote;
|
||||||
|
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_BOOL('a', "auto", &opt_a,
|
OPT_BOOL('a', "auto", &opt_a,
|
||||||
@@ -1443,8 +1444,10 @@ static int set_head(int argc, const char **argv, const char *prefix)
|
|||||||
};
|
};
|
||||||
argc = parse_options(argc, argv, prefix, options,
|
argc = parse_options(argc, argv, prefix, options,
|
||||||
builtin_remote_sethead_usage, 0);
|
builtin_remote_sethead_usage, 0);
|
||||||
if (argc)
|
if (argc) {
|
||||||
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]);
|
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]);
|
||||||
|
remote = remote_get(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!opt_a && !opt_d && argc == 2) {
|
if (!opt_a && !opt_d && argc == 2) {
|
||||||
head_name = xstrdup(argv[1]);
|
head_name = xstrdup(argv[1]);
|
||||||
@@ -1483,6 +1486,13 @@ static int set_head(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
if (opt_a)
|
if (opt_a)
|
||||||
report_set_head_auto(argv[0], head_name, &b_local_head, was_detached);
|
report_set_head_auto(argv[0], head_name, &b_local_head, was_detached);
|
||||||
|
if (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) {
|
||||||
|
struct strbuf config_name = STRBUF_INIT;
|
||||||
|
strbuf_addf(&config_name,
|
||||||
|
"remote.%s.followremotehead", remote->name);
|
||||||
|
git_config_set(config_name.buf, "warn");
|
||||||
|
strbuf_release(&config_name);
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(head_name);
|
free(head_name);
|
||||||
|
|||||||
@@ -505,6 +505,17 @@ test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'set-head changes followRemoteHEAD always to warn' '
|
||||||
|
(
|
||||||
|
cd test &&
|
||||||
|
git config set remote.origin.followRemoteHEAD "always" &&
|
||||||
|
git remote set-head --auto origin &&
|
||||||
|
git config get remote.origin.followRemoteHEAD >actual &&
|
||||||
|
echo "warn" >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
cat >test/expect <<\EOF
|
cat >test/expect <<\EOF
|
||||||
refs/remotes/origin/side2
|
refs/remotes/origin/side2
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user