All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roy Eldar <royeldar0@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, jonathantanmy@google.com,
	Roy Eldar <royeldar0@gmail.com>
Subject: [PATCH RESEND 2/2] status: improve info for detached HEAD after clone
Date: Wed,  8 Mar 2023 21:20:50 +0200	[thread overview]
Message-ID: <20230308192050.1291-3-royeldar0@gmail.com> (raw)
In-Reply-To: <20230308192050.1291-1-royeldar0@gmail.com>

When a remote ref or a tag is checked out, HEAD is automatically
detached, and "git status" says 'HEAD detached at ...', instead of
'Not currently on any branch.'; this is done by traversing the reflog
and parsing an entry like 'checkout: moving from ... to ...'.

In certain situations, HEAD can be detached after "git clone": for
example, when "--branch" specifies a non-branch (e.g. a tag). It is
preferable to avoid displaying 'Not currently on any branch.', so
'HEAD detached at $sha1' is shown instead.

Signed-off-by: Roy Eldar <royeldar0@gmail.com>
---
 t/t7508-status.sh | 2 +-
 wt-status.c       | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index d279157d28..0ab5bdc1e0 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -894,7 +894,7 @@ test_expect_success 'status shows detached HEAD properly after cloning a reposit
 
 	git clone -b test_tag upstream downstream &&
 	git -C downstream status >actual &&
-	grep -E "Not currently on any branch." actual
+	grep -E "HEAD detached at [0-9a-f]+" actual
 '
 
 test_expect_success 'setup status submodule summary' '
diff --git a/wt-status.c b/wt-status.c
index 3162241a57..f0a5fb578a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1632,6 +1632,13 @@ static int grab_1st_switch(struct object_id *ooid UNUSED,
 	struct grab_1st_switch_cbdata *cb = cb_data;
 	const char *target = NULL, *end;
 
+	if (skip_prefix(message, "clone: from ", &message)) {
+		oidcpy(&cb->noid, noid);
+		strbuf_reset(&cb->buf);
+		strbuf_add_unique_abbrev(&cb->buf, noid, DEFAULT_ABBREV);
+		return 1;
+	}
+
 	if (!skip_prefix(message, "checkout: moving from ", &message))
 		return 0;
 	target = strstr(message, " to ");
-- 
2.30.2


  parent reply	other threads:[~2023-03-08 19:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 19:20 [PATCH RESEND 0/2] status: improve info for detached HEAD Roy Eldar
2023-03-08 19:20 ` [PATCH RESEND 1/2] t7508: test status output for detached HEAD after clone Roy Eldar
2023-03-08 19:20 ` Roy Eldar [this message]
2023-03-08 20:42   ` [PATCH RESEND 2/2] status: improve info " Junio C Hamano
2023-03-10 16:25     ` Roy E

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230308192050.1291-3-royeldar0@gmail.com \
    --to=royeldar0@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.