Skip to content

Commit d6370f7

Browse files
committed
Merge branch 'ti/branch-set-upstream-hint-fix'
The hint printed when tracking configuration fails to be written has been corrected to produce a valid remote-tracking branch name. * ti/branch-set-upstream-hint-fix: branch: strip refs/heads/ from the --set-upstream-to hint
2 parents a04194e + 91ef176 commit d6370f7

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎branch.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ static int install_branch_config_multiple_remotes(int flag, const char *local,
186186

187187
advise(_("\nAfter fixing the error cause you may try to fix up\n"
188188
"the remote tracking information by invoking:"));
189-
if (remotes->nr == 1)
189+
if (remotes->nr == 1) {
190+
shortname = remotes->items[0].string;
191+
skip_prefix(shortname, "refs/heads/", &shortname);
190192
advise(" git branch --set-upstream-to=%s%s%s",
191193
origin ? origin : "",
192194
origin ? "/" : "",
193-
remotes->items[0].string);
194-
else {
195+
shortname);
196+
} else {
195197
advise(" git config --add branch.\"%s\".remote %s",
196198
local, origin ? origin : ".");
197199
for_each_string_list_item(item, remotes)

‎t/t3200-branch.sh‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,31 @@ test_expect_success '--set-upstream-to fails on locked config' '
10801080
test_grep "could not lock config file .git/config" err
10811081
'
10821082

1083+
test_expect_success '--set-upstream-to hint uses short remote-tracking branch name on locked config' '
1084+
test_when_finished "git branch -D hint-local" &&
1085+
test_when_finished "git update-ref -d refs/remotes/hintremote/hintbranch" &&
1086+
test_config remote.hintremote.url . &&
1087+
test_config remote.hintremote.fetch "+refs/heads/*:refs/remotes/hintremote/*" &&
1088+
git update-ref refs/remotes/hintremote/hintbranch HEAD &&
1089+
git branch hint-local &&
1090+
test_when_finished "rm -f .git/config.lock" &&
1091+
>.git/config.lock &&
1092+
test_must_fail git -c core.configLockTimeout=0 \
1093+
branch --set-upstream-to=hintremote/hintbranch hint-local 2>err &&
1094+
cat >expect <<-\EOF &&
1095+
hint:
1096+
hint: After fixing the error cause you may try to fix up
1097+
hint: the remote tracking information by invoking:
1098+
hint: git branch --set-upstream-to=hintremote/hintbranch
1099+
EOF
1100+
grep "^hint:" err >actual &&
1101+
test_cmp expect actual &&
1102+
rm -f .git/config.lock &&
1103+
git branch --set-upstream-to=hintremote/hintbranch hint-local &&
1104+
test_cmp_config hintremote branch.hint-local.remote &&
1105+
test_cmp_config refs/heads/hintbranch branch.hint-local.merge
1106+
'
1107+
10831108
test_expect_success 'use --set-upstream-to modify HEAD' '
10841109
test_config branch.main.remote foo &&
10851110
test_config branch.main.merge foo &&

0 commit comments

Comments
 (0)