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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Sep 27, 2015 at 17:13 UTC
0eb8548f45cc51bff9b70f551f4c472af353a814
2 files changed
+7
-1
t/t3203-branch-output.sh
+1
-1
@@ -106,7 +106,7 @@ EOF
106
test_i18ncmp expect actual
107
'
108
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' '
110
git checkout master &&
111
cat >expect <<EOF &&
112
* (HEAD detached at $(git rev-parse --short HEAD^0))
wt-status.c
+6
@@ -1204,6 +1204,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
1204
hashcpy(cb->nsha1, nsha1);
1205
for (end = target; *end && *end != '\n'; end++)
1206
;
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
+ }
1213
strbuf_add(&cb->buf, target, end - target);
1214
return 1;
1215
}