git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH] checkout: indicate when a detached head is checked out for a branch
Date: Fri, 18 Jul 2014 11:50:42 +0200	[thread overview]
Message-ID: <35dbe7e3f3e4566d775bea19d816adc44db8ed5c.1405676303.git.git@drmicha.warpmail.net> (raw)

In a setup with more than 1 workdir, it can happen that a user requests
to checkout a branch that is already checked out somewhere else. The
current "hint" about this gives the impression that it is merely warning
about this fact.

Actually, "checkout" changes its behavior in such a situation from
checking out the requested branch to checking out its head as a detached
head. The only indication is the usual checkout message which appears
before the hint.

Change the hint to make it clearer that checkout changed its behavior to
something that is possible to do in that situation, but may or may not
be what the user intended.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
I really like the new --to feature and will convert all my "new workdir"
checkouts to that. But that detached checkout is so easy to miss - in fact
I noticed it only when I compared "new-workdir" to "checkout --to" for a
test repo with one branch, to see what a converter would need to do.

I'm even wondering whether we should do this DWIMmery at all, given how
"dangerous" a detached head is for those who are not aware of it
before gc kicks in.

(Sorry if that dupes something on the list, can't keep up these days;
so this is coming from a "mere user" ;-)

 builtin/checkout.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index cfc6db7..38a5670 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -645,9 +645,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
 				detach_advice(new->name);
 			describe_detached_head(_("HEAD is now at"), new->commit);
 			if (new->checkout && !*new->checkout)
-				fprintf(stderr, _("hint: the main checkout is holding this branch\n"));
+				fprintf(stderr, _("hint: the main checkout is holding this branch; detaching branch head instead.\n"));
 			else if (new->checkout)
-				fprintf(stderr, _("hint: the linked checkout %s is holding this branch\n"),
+				fprintf(stderr, _("hint: the linked checkout %s is holding this branch; detaching branch head instead.\n"),
 					new->checkout);
 		}
 	} else if (new->path) {	/* Switch branches. */
-- 
2.0.1.583.gbe96573

             reply	other threads:[~2014-07-18  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-18  9:50 Michael J Gruber [this message]
2014-07-18 10:58 ` [PATCH] checkout: indicate when a detached head is checked out for a branch Duy Nguyen
2014-07-18 13:27   ` Michael J Gruber
2014-07-18 14:13     ` Max Kirillov
2014-07-18 17:36 ` Junio C Hamano
2014-07-18 21:54   ` Dennis Kaarsemaker
2014-07-18 22:18     ` Junio C Hamano
2014-07-21 13:03       ` Michael J Gruber

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=35dbe7e3f3e4566d775bea19d816adc44db8ed5c.1405676303.git.git@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).