This should work more consistently with Git 2.29 (Q4 2020): "git status
"(man) has trouble showing where it came from by interpreting reflog entries that record certain events, e.g. "checkout @{u}
", and gives a hard/fatal error.
Even though it inherently is impossible to give a correct answer because the reflog entries lose some information (e.g. "@{u}
" does not record what branch the user was on hence which branch 'the upstream' needs to be computed, and even if the record were available, the relationship between branches may have changed), at least hide the error to allow "status
" show its output.
That also influences git branch
.
See commit f24c30e, commit ec06b05, commit a4f66a7 (01 Sep 2020) by Jonathan Tan (jhowtan
).
(Merged by Junio C Hamano -- gitster
-- in commit 0df670b, 09 Sep 2020)
wt-status
: tolerate dangling marks
Signed-off-by: Jonathan Tan
When a user checks out the upstream branch of HEAD, the upstream branch not being a local branch, and then runs "git status
"(man) , like this:
git clone $URL client
cd client
git checkout @{u}
git status
no status is printed, but instead an error message:
fatal: HEAD does not point to a branch
(This error message when running "git branch
"(man) persists even after checking out other things - it only stops after checking out a branch.)
This is because "git status
"(man) reads the reflog when determining the "HEAD detached" message, and thus attempts to DWIM "@{u}
", but that doesn't work because HEAD no longer points to a branch.
Therefore, when calculating the status of a worktree, tolerate dangling marks. This is done by adding an additional parameter to dwim_ref()
and repo_dwim_ref()
.