{"thread":{"id":"59305","subject":"[RFC PATCH 0/2] status: improve info for detached HEAD","startedAt":"2023-02-24T23:39:23Z","lastAt":"2023-02-24T23:39:36Z","messageCount":3,"participants":["Roy Eldar"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"472686","messageId":"20230224232841.21297-1-royeldar0@gmail.com","threadId":"59305","inReplyTo":null,"subject":"[RFC PATCH 0/2] status: improve info for detached HEAD","fromName":"Roy Eldar","fromEmail":"royeldar0@gmail.com","sentAt":"2023-02-24T23:28:39Z","receivedAt":"2023-02-24T23:39:23Z","isPatch":true,"sender":{"key":"royeldar0@gmail.com","avatar":null},"body":"When a repository is cloned using \"git clone -b\" and a tag is specified,\nHEAD is automatically detached. As a result, \"git status\" shows\n\"currently not on any branch\", which is not very useful.\n\nTeach \"git status\" to generate the \"HEAD detached at\" message in this\ncase as well, in a similar way to when a tag is checked out.\n\nIn the case of \"git checkout\", the name of the ref that was checked out\nis retrieved from the reflog; for \"git clone\", the name of the ref isn't\npresent in the reflog entry, so we use the abbreviated hash instead.\nThis is also consistent with the \"detached HEAD\" advice.\n\nRoy Eldar (2):\n  t7508: test status output for detached HEAD after clone\n  status: improve info for detached HEAD after clone\n\n t/t7508-status.sh | 12 ++++++++++++\n wt-status.c       |  7 +++++++\n 2 files changed, 19 insertions(+)\n\n-- \n2.30.2\n\n"},{"id":"472687","messageId":"20230224232841.21297-2-royeldar0@gmail.com","threadId":"59305","inReplyTo":"20230224232841.21297-1-royeldar0@gmail.com","subject":"[RFC PATCH 1/2] t7508: test status output for detached HEAD after clone","fromName":"Roy Eldar","fromEmail":"royeldar0@gmail.com","sentAt":"2023-02-24T23:28:40Z","receivedAt":"2023-02-24T23:39:30Z","isPatch":true,"sender":{"key":"royeldar0@gmail.com","avatar":null},"body":"After cloning a repository, HEAD might be detached: for example, when\n\"--branch\" specifies a non-branch (e.g. a tag). In this case, running\n\"git status\" prints 'Not currently on any branch'.\n\nSigned-off-by: Roy Eldar <royeldar0@gmail.com>\n---\n t/t7508-status.sh | 12 ++++++++++++\n 1 file changed, 12 insertions(+)\n\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex aed07c5b62..d279157d28 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -885,6 +885,18 @@ test_expect_success 'status shows detached HEAD properly after checking out non-\n \tgrep -E \"HEAD detached at [0-9a-f]+\" actual\n '\n \n+test_expect_success 'status shows detached HEAD properly after cloning a repository' '\n+\ttest_when_finished rm -rf upstream downstream actual &&\n+\n+\tgit init upstream &&\n+\ttest_commit -C upstream foo &&\n+\tgit -C upstream tag test_tag &&\n+\n+\tgit clone -b test_tag upstream downstream &&\n+\tgit -C downstream status >actual &&\n+\tgrep -E \"Not currently on any branch.\" actual\n+'\n+\n test_expect_success 'setup status submodule summary' '\n \ttest_create_repo sm && (\n \t\tcd sm &&\n-- \n2.30.2\n\n"},{"id":"472688","messageId":"20230224232841.21297-3-royeldar0@gmail.com","threadId":"59305","inReplyTo":"20230224232841.21297-1-royeldar0@gmail.com","subject":"[RFC PATCH 2/2] status: improve info for detached HEAD after clone","fromName":"Roy Eldar","fromEmail":"royeldar0@gmail.com","sentAt":"2023-02-24T23:28:41Z","receivedAt":"2023-02-24T23:39:36Z","isPatch":true,"sender":{"key":"royeldar0@gmail.com","avatar":null},"body":"When a remote ref or a tag is checked out, HEAD is automatically\ndetached, and \"git status\" says 'HEAD detached at ...', instead of\n'Not currently on any branch.'; this is done by traversing the reflog\nand parsing an entry like 'checkout: moving from ... to ...'.\n\nIn certain situations, HEAD can be detached after \"git clone\": for\nexample, when \"--branch\" specifies a non-branch (e.g. a tag). It is\npreferable to avoid displaying 'Not currently on any branch.', so\n'HEAD detached at $sha1' is shown instead.\n\nSigned-off-by: Roy Eldar <royeldar0@gmail.com>\n---\n t/t7508-status.sh | 2 +-\n wt-status.c       | 7 +++++++\n 2 files changed, 8 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex d279157d28..0ab5bdc1e0 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -894,7 +894,7 @@ test_expect_success 'status shows detached HEAD properly after cloning a reposit\n \n \tgit clone -b test_tag upstream downstream &&\n \tgit -C downstream status >actual &&\n-\tgrep -E \"Not currently on any branch.\" actual\n+\tgrep -E \"HEAD detached at [0-9a-f]+\" actual\n '\n \n test_expect_success 'setup status submodule summary' '\ndiff --git a/wt-status.c b/wt-status.c\nindex 3162241a57..f0a5fb578a 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1632,6 +1632,13 @@ static int grab_1st_switch(struct object_id *ooid UNUSED,\n \tstruct grab_1st_switch_cbdata *cb = cb_data;\n \tconst char *target = NULL, *end;\n \n+\tif (skip_prefix(message, \"clone: from \", &message)) {\n+\t\toidcpy(&cb->noid, noid);\n+\t\tstrbuf_reset(&cb->buf);\n+\t\tstrbuf_add_unique_abbrev(&cb->buf, noid, DEFAULT_ABBREV);\n+\t\treturn 1;\n+\t}\n+\n \tif (!skip_prefix(message, \"checkout: moving from \", &message))\n \t\treturn 0;\n \ttarget = strstr(message, \" to \");\n-- \n2.30.2\n\n"}]}