Skip to content

Commit 0eb8548

Browse files
moygitster
authored andcommitted
status: don't say 'HEAD detached at HEAD'
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9cb07d8 commit 0eb8548

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

t/t3203-branch-output.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ EOF
106106
test_i18ncmp expect actual
107107
'
108108

109-
test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '
109+
test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
110110
git checkout master &&
111111
cat >expect <<EOF &&
112112
* (HEAD detached at $(git rev-parse --short HEAD^0))

wt-status.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
12041204
hashcpy(cb->nsha1, nsha1);
12051205
for (end = target; *end && *end != '\n'; end++)
12061206
;
1207+
if (!memcmp(target, "HEAD", end - target)) {
1208+
/* HEAD is relative. Resolve it to the right reflog entry. */
1209+
strbuf_addstr(&cb->buf,
1210+
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
1211+
return 1;
1212+
}
12071213
strbuf_add(&cb->buf, target, end - target);
12081214
return 1;
12091215
}

0 commit comments

Comments
 (0)