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

Re: [PATCH] checkout: fix BUG() case in 9081a421a6

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 22, 2022, 00:45 UTC
Message-ID
<xmqqlez8d2e6.fsf@gitster.g>
In-Reply-To
<patch-1.1-21ddf7c628d-20220120T212233Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 6 quoted lines
> +test_expect_success REFFILES 'checkout a branch without refs/heads/* prefix' '
> +	git clone --no-tags . repo-odd-prefix &&
> +	(
> +		cd repo-odd-prefix &&
> +
> +		cp .git/refs/remotes/origin/HEAD .git/refs/heads/a-branch &&

I already said that I do not think we want the exact behaviour (like "remote-tracking branches are moved when we change the local branch") to be cast in stone like this, but we should be able to lose the REFFILES prerequisite by using proper plumbing, e.g. these two lines

		origin=$(git symbolic-ref refs/remotes/origin/HEAD) &&
		git symbolic-ref refs/heads/a-branch "$origin" &&
instead of the direct manipulation of filesystem with "cp".

I am tempted to say that checking the command does not trigger BUG(), like the attached, may be sufficient. I do not care too deeply either way, though.

diff --git i/t/t2018-checkout-branch.sh w/t/t2018-checkout-branch.sh
index 93be1c0eae..5dda5ad4cb 100755
--- i/t/t2018-checkout-branch.sh
+++ w/t/t2018-checkout-branch.sh
@@ -85,6 +85,19 @@ test_expect_success 'setup' '
 	git branch -m branch1
 '
 
+test_expect_success 'checkout a branch without refs/heads/* prefix' '
+	git clone --no-tags . repo-odd-prefix &&
+	(
+		cd repo-odd-prefix &&
+
+		origin=$(git symbolic-ref refs/remotes/origin/HEAD) &&
+		git symbolic-ref refs/heads/a-branch "$origin" &&
+
+		git checkout -f a-branch &&
+		git checkout -f a-branch
+	)
+'
+
 test_expect_success 'checkout -b to a new branch, set to HEAD' '
 	test_when_finished "
 		git checkout branch1 &&
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 16 in “[BUG] builtin/checkout.c:1098: should be able to skip past 'refs/heads/'”
  1. Todd ZullingerJan 20, 2022
  2. Todd ZullingerJan 20, 2022
  3. checkout: fix BUG() case in 9081a421a6Ævar Arnfjörð Bjarmason, Jan 20, 2022
  4. Junio C HamanoJan 20, 2022
  5. Junio C HamanoJan 20, 2022
  6. Ævar Arnfjörð BjarmasonJan 21, 2022
  7. Petr ŠplíchalJan 21, 2022
  8. Todd ZullingerJan 21, 2022
  9. Junio C HamanoJan 21, 2022
  10. Todd ZullingerJan 20, 2022
  11. Junio C HamanoJan 22, 2022
  12. Junio C HamanoJan 22, 2022
  13. checkout: avoid BUG() when hitting a broken repositoryJunio C Hamano, Jan 22, 2022
  14. Johannes SixtJan 22, 2022
  15. Ævar Arnfjörð BjarmasonJan 22, 2022
  16. Johannes SchindelinJan 23, 2022

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.