]> git.ipfire.org Git - thirdparty/git.git/commitdiff
status: don't say 'HEAD detached at HEAD'
authorMatthieu Moy <Matthieu.Moy@imag.fr>
Sun, 27 Sep 2015 15:13:42 +0000 (17:13 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Oct 2015 18:29:46 +0000 (11:29 -0700)
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>
t/t3203-branch-output.sh
wt-status.c

index bf24dbf831d85703501f1a3bd962953e38804b4f..16efe7af03d210cb349337e978c6105cb22d80e8 100755 (executable)
@@ -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))
index 078a4727435b0c6b98cdc600773cb90e850e9a7f..fd9d98b39966a372ab56b2aee8e72fe99d9f0f4e 100644 (file)
@@ -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;
 }