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

Re: bug? in checkout with ambiguous refnames

From
Jeff King <peff@peff.net>
Date
Jan 11, 2011, 19:20 UTC
Message-ID
<20110111192020.GA15608@sigill.intra.peff.net>
In-Reply-To
<20110111065509.GG10094@sigill.intra.peff.net>
On Tue, Jan 11, 2011 at 01:55:09AM -0500, Jeff King wrote:
Show 8 quoted lines
> On Fri, Jan 07, 2011 at 02:54:17PM -0500, Jeff King wrote:
> 
> > +test_expect_success 'checkout reports switch to detached HEAD' '
> > +	grep "Switched to branch" stderr &&
> > +	! grep "^HEAD is now at" stderr
> 
> Junio, one minor fixup here. The test is correct, but the description
> should read "checkout reports switch to branch", not "...detached HEAD".

Hmm. One other thing to note on these ambiguity tests. Apparently we did already have a test for this in t7201 (which should perhaps be renamed into the t20* area with the other checkout tests), but it was passing.

The problem is that the current behavior is way more broken than just "accidentally choose tag over branch". It actually writes the branch ref into HEAD, but checks out the tree from the tag! The test in 7201 only checks the former, but our new test checked the latter.

Probably we should be checking both, just to be sure (and yes, with your patch it does the right thing):

diff --git a/t/t2019-checkout-amiguous-ref.sh b/t/t2019-checkout-amiguous-ref.sh
index e2b330b..606081b 100755
--- a/t/t2019-checkout-amiguous-ref.sh
+++ b/t/t2019-checkout-amiguous-ref.sh
@@ -22,6 +22,9 @@ test_expect_success 'checkout produces ambiguity warning' '
 '
 
 test_expect_success 'checkout chooses branch over tag' '
+	echo refs/heads/ambiguity >expect &&
+	git symbolic-ref HEAD >actual &&
+	test_cmp expect actual &&
 	echo branch >expect &&
 	test_cmp expect file
 '
@@ -41,6 +44,9 @@ test_expect_success VAGUENESS_SUCCESS 'checkout produces ambiguity warning' '
 '
 
 test_expect_success VAGUENESS_SUCCESS 'checkout chooses branch over tag' '
+	echo refs/heads/vagueness >expect &&
+	git symbolic-ref HEAD >actual &&
+	test_cmp expect actual &&
 	echo branch >expect &&
 	test_cmp expect file
 '
Previous: Jeff KingNext: Jeff King
Message 14 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.