Skip to content

Commit df64186

Browse files
committed
Merge branch 'mm/detach-at-HEAD-reflog' into maint
After "git checkout --detach", "git status" reported a fairly useless "HEAD detached at HEAD", instead of saying at which exact commit. * mm/detach-at-HEAD-reflog: status: don't say 'HEAD detached at HEAD' t3203: test 'detached at' after checkout --detach
2 parents 19d11d4 + 0eb8548 commit df64186

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

t/t3203-branch-output.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ EOF
106106
test_i18ncmp expect actual
107107
'
108108

109+
test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
110+
git checkout master &&
111+
cat >expect <<EOF &&
112+
* (HEAD detached at $(git rev-parse --short HEAD^0))
113+
branch-one
114+
branch-two
115+
master
116+
EOF
117+
git checkout --detach &&
118+
git branch >actual &&
119+
test_i18ncmp expect actual
120+
'
121+
109122
test_expect_success 'git branch shows detached HEAD properly after moving' '
110123
cat >expect <<EOF &&
111124
* (HEAD detached from $(git rev-parse --short HEAD))

wt-status.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
13191319
hashcpy(cb->nsha1, nsha1);
13201320
for (end = target; *end && *end != '\n'; end++)
13211321
;
1322+
if (!memcmp(target, "HEAD", end - target)) {
1323+
/* HEAD is relative. Resolve it to the right reflog entry. */
1324+
strbuf_addstr(&cb->buf,
1325+
find_unique_abbrev(nsha1, DEFAULT_ABBREV));
1326+
return 1;
1327+
}
13221328
strbuf_add(&cb->buf, target, end - target);
13231329
return 1;
13241330
}

0 commit comments

Comments
 (0)