Skip to content

Commit 012bc56

Browse files
ferdinandybgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9e2b700 commit 012bc56

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

builtin/remote.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ static int set_head(int argc, const char **argv, const char *prefix)
14331433
b_local_head = STRBUF_INIT;
14341434
char *head_name = NULL;
14351435
struct ref_store *refs = get_main_ref_store(the_repository);
1436+
struct remote *remote;
14361437

14371438
struct option options[] = {
14381439
OPT_BOOL('a', "auto", &opt_a,
@@ -1443,8 +1444,10 @@ static int set_head(int argc, const char **argv, const char *prefix)
14431444
};
14441445
argc = parse_options(argc, argv, prefix, options,
14451446
builtin_remote_sethead_usage, 0);
1446-
if (argc)
1447+
if (argc) {
14471448
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]);
1449+
remote = remote_get(argv[0]);
1450+
}
14481451

14491452
if (!opt_a && !opt_d && argc == 2) {
14501453
head_name = xstrdup(argv[1]);
@@ -1483,6 +1486,13 @@ static int set_head(int argc, const char **argv, const char *prefix)
14831486
}
14841487
if (opt_a)
14851488
report_set_head_auto(argv[0], head_name, &b_local_head, was_detached);
1489+
if (remote->follow_remote_head == FOLLOW_REMOTE_ALWAYS) {
1490+
struct strbuf config_name = STRBUF_INIT;
1491+
strbuf_addf(&config_name,
1492+
"remote.%s.followremotehead", remote->name);
1493+
git_config_set(config_name.buf, "warn");
1494+
strbuf_release(&config_name);
1495+
}
14861496

14871497
cleanup:
14881498
free(head_name);

t/t5505-remote.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
505505
)
506506
'
507507

508+
test_expect_success 'set-head changes followRemoteHEAD always to warn' '
509+
(
510+
cd test &&
511+
git config set remote.origin.followRemoteHEAD "always" &&
512+
git remote set-head --auto origin &&
513+
git config get remote.origin.followRemoteHEAD >actual &&
514+
echo "warn" >expect &&
515+
test_cmp expect actual
516+
)
517+
'
518+
508519
cat >test/expect <<\EOF
509520
refs/remotes/origin/side2
510521
EOF

0 commit comments

Comments
 (0)