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

Re: [PATCH] checkout: indicate when a detached head is checked out for a branch

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 18, 2014, 17:36 UTC
Message-ID
<xmqqr41imuwk.fsf@gitster.dls.corp.google.com>
In-Reply-To
<35dbe7e3f3e4566d775bea19d816adc44db8ed5c.1405676303.git.git@drmicha.warpmail.net>
Michael J Gruber <git@drmicha.warpmail.net> writes:
Show 8 quoted lines
> 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.

As long as the amount of warning about 'detached HEAD' is about the same between this case and a "git checkout v1.2.3" in a normal repository, I do not think there is no additional "danger" you need to be worried about.

But I do agree that there should not be any DWIM here.

The reason to introduce this new set of rather intrusive changes is so that working trees can be aware of branches other working trees have checked out. And the whole point of wanting to have that mutual awareness is to enable us to forbid users from mucking with the same branch from two different places.

But Git is not in the position to dictate which alternative action the user would want to take, when her "git checkout foo" is prevented by this mechanism. In one scenario, she may say "I only wanted to take a peek" and run "git checkout foo^0" instead. In another, she may say "Ah, I forgot I already was doing this change in the other one" and run "cd ../foo". There may be other classes of alternative actions.

Don't make it easier for the first class of scenario and make it less useful and more dangerous for the second class, especially the second class involve forgetful users who are likely to forget seeing the "we've warned you that we detached without being asked" message.

Please fix it to always just error out.
Show 22 quoted lines
> (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. */
Previous: Max KirillovNext: Dennis Kaarsemaker
Message 5 of 8 in “checkout: indicate when a detached head is checked out for a branch”
  1. checkout: indicate when a detached head is checked out for a branchMichael J Gruber, Jul 18, 2014
  2. Duy NguyenJul 18, 2014
  3. Michael J GruberJul 18, 2014
  4. Max KirillovJul 18, 2014
  5. Junio C HamanoJul 18, 2014
  6. Dennis KaarsemakerJul 18, 2014
  7. Junio C HamanoJul 18, 2014
  8. Michael J GruberJul 21, 2014

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.