git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, "Todd Zullinger" <tmz@pobox.com>,
	"Petr Šplíchal" <psplicha@redhat.com>
Subject: Re: [PATCH] checkout: fix BUG() case in 9081a421a6
Date: Fri, 21 Jan 2022 16:45:21 -0800	[thread overview]
Message-ID: <xmqqlez8d2e6.fsf@gitster.g> (raw)
In-Reply-To: <patch-1.1-21ddf7c628d-20220120T212233Z-avarab@gmail.com> ("Ævar	Arnfjörð Bjarmason"'s message of "Thu, 20 Jan 2022 22:26:57 +0100")

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> +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 &&

  parent reply	other threads:[~2022-01-22  0:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20 16:51 [BUG] builtin/checkout.c:1098: should be able to skip past 'refs/heads/' Todd Zullinger
2022-01-20 17:04 ` Todd Zullinger
2022-01-20 21:26 ` [PATCH] checkout: fix BUG() case in 9081a421a6 Ævar Arnfjörð Bjarmason
2022-01-20 22:29   ` Junio C Hamano
2022-01-20 22:33     ` Junio C Hamano
2022-01-21 11:14     ` Ævar Arnfjörð Bjarmason
2022-01-21 14:29       ` Petr Šplíchal
2022-01-21 21:58         ` Todd Zullinger
2022-01-21 21:19       ` Junio C Hamano
2022-01-20 22:33   ` Todd Zullinger
2022-01-22  0:33   ` Junio C Hamano
2022-01-22  0:45   ` Junio C Hamano [this message]
2022-01-22  0:58     ` [PATCH] checkout: avoid BUG() when hitting a broken repository Junio C Hamano
2022-01-22  8:10       ` Johannes Sixt
2022-01-22 11:55       ` Ævar Arnfjörð Bjarmason
2022-01-23 16:38       ` Johannes Schindelin

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=xmqqlez8d2e6.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=psplicha@redhat.com \
    --cc=tmz@pobox.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).