From 9cb07d81b3b268dc5f88f7048f54ce51d363d2d5 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Sun, 27 Sep 2015 17:13:41 +0200 Subject: [PATCH 1/2] t3203: test 'detached at' after checkout --detach This currently fails: the output is 'HEAD detached at HEAD'. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t3203-branch-output.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index f51d0f3cad..bf24dbf831 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -106,6 +106,19 @@ EOF test_i18ncmp expect actual ' +test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' ' + git checkout master && + cat >expect <actual && + test_i18ncmp expect actual +' + test_expect_success 'git branch shows detached HEAD properly after moving' ' cat >expect < Date: Sun, 27 Sep 2015 17:13:42 +0200 Subject: [PATCH 2/2] 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 Signed-off-by: Junio C Hamano --- t/t3203-branch-output.sh | 2 +- wt-status.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index bf24dbf831..16efe7af03 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -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 <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; }