Re: [PATCH] branch: strip refs/heads/ from the --set-upstream-to hint
- From
Harald Nordgren <haraldnordgren@gmail.com>
- Date
- Oct 21, 2026, 07:05 UTC
- Message-ID
- <CAHwyqnU-eQBPTht3eHJceyWMehtQ2GAyEyZ8ObmVru0Y9EVkdQ@mail.gmail.com>
- In-Reply-To
- <pull.2268.git.1792458904027.gitgitgadget@gmail.com>
Show 14 quoted lines
> When git switch fails to write the tracking config, it prints a hint > with the command to set the upstream by hand. For example, if > .git/config.lock exists: > > error: could not lock config file .git/config: File exists > error: unable to write upstream branch configuration > hint: > hint: After fixing the error cause you may try to fix up > hint: the remote tracking information by invoking: > hint: git branch --set-upstream-to=origin/refs/heads/feat > > The hint says origin/refs/heads/feat, but the correct name is > origin/feat. Running the command as printed fails, because the full > ref name is not a valid remote-tracking branch name here.
Very nice find!
Show 14 quoted lines
> +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 > +'
Would be good to test the full multiline hint message. After all, it's the point of the topic.
Right now, you are asserting that the correct form 'hintremote/hintbranch' works, but we want to make sure that the hint actually gives that.
Harald