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

Re: bug? in checkout with ambiguous refnames

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 7, 2011, 19:44 UTC
Message-ID
<7vzkrc5wil.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20110107104650.GA5399@pengutronix.de>
Uwe Kleine-König  <u.kleine-koenig@pengutronix.de> writes:
> So working copy and cache are at refs/tags/sgu/mxs-amba-uart, HEAD
> points to refs/heads/sgu/mxs-amba-uart

I somehow thought that we had an explicit logic to favor an exact branch name for "git checkout $branch" even when refs/something-other-than-head/$branch exists, while issuing the ambiguity warning.

Ahh, what this part of the code in builtin/checkout.c does is totally wrong:

	/* we can't end up being in (2) anymore, eat the argument */
	argv++;
	argc--;
	new.name = arg;
	if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
		setup_branch_path(&new);
		if ((check_ref_format(new.path) == CHECK_REF_FORMAT_OK) &&
		    resolve_ref(new.path, rev, 1, NULL))
			;
		else
			new.path = NULL;
		parse_commit(new.commit);
		source_tree = new.commit->tree;
	} else
		source_tree = parse_tree_indirect(rev);

It uses lookup_commit_reference_gently() that follows the usual tags-then-heads preference order, but then uses setup_branch_path() to prefix the raw name with "refs/heads", which is totally backwards. It should do something like:

 - use setup-branch-path to get refs/heads/$name
 - check-ref-format and resolve it; if these fail, then we are detaching
   head at rev;
 - otherwise, if the result of the resolution is not the same as rev, what
   we have in rev is incorrect (it was taken from the usual
   tags-then-heads rule but "checkout $name" must favor local branches).
   update the rev with the result of resolving refs/heads/$name
 - parse new.commit out of rev.  we are checking out the branch $name.
Previous: Uwe Kleine-KönigNext: Jeff King
Message 2 of 23 in “bug? in checkout with ambiguous refnames”
  1. Uwe Kleine-KönigJan 7, 2011
  2. Junio C HamanoJan 7, 2011
  3. Jeff KingJan 7, 2011
  4. Jeff KingJan 7, 2011
  5. Junio C HamanoJan 7, 2011
  6. Junio C HamanoJan 7, 2011
  7. Jeff KingJan 11, 2011
  8. Junio C HamanoJan 11, 2011
  9. Jeff KingJan 11, 2011
  10. Jeff KingJan 12, 2011
  11. Junio C HamanoJan 12, 2011
  12. Jeff KingJan 12, 2011
  13. Jeff KingJan 11, 2011
  14. Jeff KingJan 11, 2011
  15. Jeff KingJan 11, 2011
  16. Martin von ZweigbergkJan 8, 2011
  17. Jeff KingJan 8, 2011
  18. Martin von ZweigbergkJan 9, 2011
  19. Junio C HamanoJan 9, 2011
  20. Martin von ZweigbergkJan 9, 2011
  21. Uwe Kleine-KönigJan 12, 2011
  22. Jeff KingJan 12, 2011
  23. Uwe Kleine-KönigJan 12, 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.