git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] checkout: honor advice.detachedHead when reattaching to a branch

From
Junio C Hamano <gitster@pobox.com>
Date
May 6, 2011, 20:35 UTC
Message-ID
<7vei4bzhwm.fsf@alter.siamese.dyndns.org>

When switching away from a detached HEAD with "git checkout", we give a final warning to tell how to resurrect the commits being left behind since 8e2dc6a (commit: give final warning when reattaching HEAD to leave commits behind, 2011-02-18) rather loudly.

This is a good safety measure for people who are not comfortable with the detached HEAD state, but the warning was given even to those who set the advice.detachedHead to false to decline the warning given when detaching, resulting in an asymmetric experience. Silent when going detached, and very loud when coming back.

Make the call to orphan check and warning conditional to the advice setting to correct this.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Admittedly, going into the detached HEAD state is much less warn-worthy
   event than coming out of it, especially if you made any commit that
   will become unreachable, so there is an inherent asymmetry and some
   people may want to have a silent entry and loud exit (i.e. the current
   behaviour).  I do not mind a separate "advice.abouttolosecommit", but
   with this weatherbaloon I am trying to see if we can get away without
   adding yet another knob that the user has to tweak.
 builtin/checkout.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index eece5d6..eb92250 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -723,8 +723,13 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
 	if (ret)
 		return ret;
 
-	if (!opts->quiet && !old.path && old.commit && new->commit != old.commit)
-		orphaned_commit_warning(old.commit);
+	if (!opts->quiet && !old.path && old.commit && new->commit != old.commit) {
+		if (advice_detached_head)
+			orphaned_commit_warning(old.commit);
+		else
+			describe_detached_head(_("Previous HEAD position was"),
+					       old.commit);
+	}
 
 	update_refs_for_switch(opts, &old, new);
 
Next: Jeff King
Message 1 of 8 in “checkout: honor advice.detachedHead when reattaching to a branch”
  1. checkout: honor advice.detachedHead when reattaching to a branchJunio C Hamano, May 6, 2011
  2. Jeff KingMay 6, 2011
  3. Junio C HamanoMay 6, 2011
  4. Jeff KingMay 6, 2011
  5. Jeff KingMay 7, 2011
  6. Junio C HamanoMay 24, 2011
  7. Jeff KingMay 24, 2011
  8. Junio C HamanoMay 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.