Skip to content

Commit

Permalink
status: don't say 'HEAD detached at HEAD'
Browse files Browse the repository at this point in the history
After using "git checkout --detach", the reflog is left with an entry
like

  checkout: moving from ... to HEAD

This message is parsed to generate the 'HEAD detached at' message in
'git branch' and 'git status', which leads to the not-so-useful message
'HEAD detached at HEAD'.

Instead, when parsing such reflog entry, resolve HEAD to the
corresponding commit in the reflog, so that the message becomes 'HEAD
detached at $sha1'.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Matthieu Moy authored and Junio C Hamano committed Oct 2, 2015
1 parent 9cb07d8 commit 0eb8548
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion t/t3203-branch-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ EOF
test_i18ncmp expect actual
'

test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '
test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
git checkout master &&
cat >expect <<EOF &&
* (HEAD detached at $(git rev-parse --short HEAD^0))
Expand Down
6 changes: 6 additions & 0 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
hashcpy(cb->nsha1, nsha1);
for (end = target; *end && *end != '\n'; end++)
;
if (!memcmp(target, "HEAD", end - target)) {
/* HEAD is relative. Resolve it to the right reflog entry. */
strbuf_addstr(&cb->buf,
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
return 1;
}
strbuf_add(&cb->buf, target, end - target);
return 1;
}
Expand Down

0 comments on commit 0eb8548

Please sign in to comment.