{"thread":{"id":"40436","subject":"[PATCH 1/2] t3203: test 'detached at' after checkout --detach","startedAt":"2015-09-27T15:13:41Z","lastAt":"2015-10-01T16:53:24Z","messageCount":4,"participants":["Matthieu Moy","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"270794","messageId":"1443366822-1753-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"40436","inReplyTo":null,"subject":"[PATCH 1/2] t3203: test 'detached at' after checkout --detach","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2015-09-27T15:13:41Z","receivedAt":"2015-09-27T15:13:41Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"This currently fails: the output is 'HEAD detached at HEAD'.\n---\n t/t3203-branch-output.sh | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh\nindex f51d0f3..bf24dbf 100755\n--- a/t/t3203-branch-output.sh\n+++ b/t/t3203-branch-output.sh\n@@ -106,6 +106,19 @@ EOF\n \ttest_i18ncmp expect actual\n '\n \n+test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '\n+\tgit checkout master &&\n+\tcat >expect <<EOF &&\n+* (HEAD detached at $(git rev-parse --short HEAD^0))\n+  branch-one\n+  branch-two\n+  master\n+EOF\n+\tgit checkout --detach &&\n+\tgit branch >actual &&\n+\ttest_i18ncmp expect actual\n+'\n+\n test_expect_success 'git branch shows detached HEAD properly after moving' '\n \tcat >expect <<EOF &&\n * (HEAD detached from $(git rev-parse --short HEAD))\n-- \n2.5.0.402.g8854c44\n"},{"id":"270795","messageId":"1443366822-1753-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"40436","inReplyTo":"1443366822-1753-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/2] status: don't say 'HEAD detached at HEAD'","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2015-09-27T15:13:42Z","receivedAt":"2015-09-27T15:13:42Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"After using \"git checkout --detach\", the reflog is left with an entry\nlike\n\n  checkout: moving from ... to HEAD\n\nThis message is parsed to generate the 'HEAD detached at' message in\n'git branch' and 'git status', which leads to the not-so-useful message\n'HEAD detached at HEAD'.\n\nInstead, when parsing such reflog entry, resolve HEAD to the\ncorresponding commit in the reflog, so that the message becomes 'HEAD\ndetached at $sha1'.\n---\nAnother possible fix is to avoid creating such reflog entry. But\nanyway, this patch remains a good thing to do and it does fix the\nissue.\n\nI won't have time to work on fixing the reflog soon, but it may be a\nnice microproject.\n\n t/t3203-branch-output.sh | 2 +-\n wt-status.c              | 6 ++++++\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh\nindex bf24dbf..16efe7a 100755\n--- a/t/t3203-branch-output.sh\n+++ b/t/t3203-branch-output.sh\n@@ -106,7 +106,7 @@ EOF\n \ttest_i18ncmp expect actual\n '\n \n-test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '\n+test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '\n \tgit checkout master &&\n \tcat >expect <<EOF &&\n * (HEAD detached at $(git rev-parse --short HEAD^0))\ndiff --git a/wt-status.c b/wt-status.c\nindex c327fe8..3e3b8c0 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1319,6 +1319,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,\n \thashcpy(cb->nsha1, nsha1);\n \tfor (end = target; *end && *end != '\\n'; end++)\n \t\t;\n+\tif (!memcmp(target, \"HEAD\", end - target)) {\n+\t\t/* HEAD is relative. Resolve it to the right reflog entry. */\n+\t\tstrbuf_addstr(&cb->buf,\n+\t\t\t      find_unique_abbrev(nsha1, DEFAULT_ABBREV));\n+\t\treturn 1;\n+\t}\n \tstrbuf_add(&cb->buf, target, end - target);\n \treturn 1;\n }\n-- \n2.5.0.402.g8854c44\n"},{"id":"270978","messageId":"560D154F.9000809@drmicha.warpmail.net","threadId":"40436","inReplyTo":"1443366822-1753-2-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 2/2] status: don't say 'HEAD detached at HEAD'","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-10-01T11:13:19Z","receivedAt":"2015-10-01T11:13:19Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Matthieu Moy venit, vidit, dixit 27.09.2015 17:13:\n> After using \"git checkout --detach\", the reflog is left with an entry\n> like\n> \n>   checkout: moving from ... to HEAD\n> \n> This message is parsed to generate the 'HEAD detached at' message in\n> 'git branch' and 'git status', which leads to the not-so-useful message\n> 'HEAD detached at HEAD'.\n> \n> Instead, when parsing such reflog entry, resolve HEAD to the\n> corresponding commit in the reflog, so that the message becomes 'HEAD\n> detached at $sha1'.\n> ---\n> Another possible fix is to avoid creating such reflog entry. But\n> anyway, this patch remains a good thing to do and it does fix the\n> issue.\n> \n> I won't have time to work on fixing the reflog soon, but it may be a\n> nice microproject.\n> \n>  t/t3203-branch-output.sh | 2 +-\n>  wt-status.c              | 6 ++++++\n>  2 files changed, 7 insertions(+), 1 deletion(-)\n> \n> diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh\n> index bf24dbf..16efe7a 100755\n> --- a/t/t3203-branch-output.sh\n> +++ b/t/t3203-branch-output.sh\n> @@ -106,7 +106,7 @@ EOF\n>  \ttest_i18ncmp expect actual\n>  '\n>  \n> -test_expect_failure 'git branch shows detached HEAD properly after checkout --detach' '\n> +test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '\n>  \tgit checkout master &&\n>  \tcat >expect <<EOF &&\n>  * (HEAD detached at $(git rev-parse --short HEAD^0))\n> diff --git a/wt-status.c b/wt-status.c\n> index c327fe8..3e3b8c0 100644\n> --- a/wt-status.c\n> +++ b/wt-status.c\n> @@ -1319,6 +1319,12 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,\n>  \thashcpy(cb->nsha1, nsha1);\n>  \tfor (end = target; *end && *end != '\\n'; end++)\n>  \t\t;\n> +\tif (!memcmp(target, \"HEAD\", end - target)) {\n> +\t\t/* HEAD is relative. Resolve it to the right reflog entry. */\n> +\t\tstrbuf_addstr(&cb->buf,\n> +\t\t\t      find_unique_abbrev(nsha1, DEFAULT_ABBREV));\n> +\t\treturn 1;\n> +\t}\n>  \tstrbuf_add(&cb->buf, target, end - target);\n>  \treturn 1;\n>  }\n> \n\nReviewed and compile tested, thanks.\n\nJunio will also want your s-o-by, though ;)\n\n(Typically we don't introduce a failing test separately like 1/2 any\nmore and do it in 1 patch, but I don't care either way.)\n\nMichael\n"},{"id":"270981","messageId":"vpq8u7mbke3.fsf@grenoble-inp.fr","threadId":"40436","inReplyTo":"560D154F.9000809@drmicha.warpmail.net","subject":"Re: [PATCH 2/2] status: don't say 'HEAD detached at HEAD'","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2015-10-01T16:53:24Z","receivedAt":"2015-10-01T16:53:24Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> Junio will also want your s-o-by, though ;)\n\nArgh, sorry. I normally have an alias to do this for me, but my\ngit-send-email is temporarily broken and I forget to sign-off\nexplicitly.\n\nI see that Junio already queued the patches in pu.\n\nIn case it matters, both patches are\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n\nand I can resend if needed.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}