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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---

 * 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);
 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]