Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ static int install_branch_config_multiple_remotes(int flag, const char *local,

advise(_("\nAfter fixing the error cause you may try to fix up\n"
"the remote tracking information by invoking:"));
if (remotes->nr == 1)
if (remotes->nr == 1) {
shortname = remotes->items[0].string;
skip_prefix(shortname, "refs/heads/", &shortname);
advise(" git branch --set-upstream-to=%s%s%s",
origin ? origin : "",
origin ? "/" : "",
remotes->items[0].string);
else {
shortname);
} else {
advise(" git config --add branch.\"%s\".remote %s",
local, origin ? origin : ".");
for_each_string_list_item(item, remotes)
Expand Down
15 changes: 15 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,21 @@ test_expect_success '--set-upstream-to fails on locked config' '
test_grep "could not lock config file .git/config" err
'

test_expect_success '--set-upstream-to hint uses short remote-tracking branch name on locked config' '
test_when_finished "git branch -D hint-local" &&
test_when_finished "git update-ref -d refs/remotes/hintremote/hintbranch" &&
test_config remote.hintremote.url . &&
test_config remote.hintremote.fetch "+refs/heads/*:refs/remotes/hintremote/*" &&
git update-ref refs/remotes/hintremote/hintbranch HEAD &&
git branch hint-local &&
test_when_finished "rm -f .git/config.lock" &&
>.git/config.lock &&
test_must_fail git -c core.configLockTimeout=0 \
branch --set-upstream-to=hintremote/hintbranch hint-local 2>err &&
test_grep "git branch --set-upstream-to=hintremote/hintbranch\$" err &&
test_grep ! "refs/heads/" err
'

test_expect_success 'use --set-upstream-to modify HEAD' '
test_config branch.main.remote foo &&
test_config branch.main.merge foo &&
Expand Down
Loading