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 20, 2022, 22:29 UTC
Message-ID
<xmqqee52ghwg.fsf@gitster.g>
In-Reply-To
<patch-1.1-21ddf7c628d-20220120T212233Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 10 quoted lines
> Fix a regression in my 9081a421a6d (checkout: fix "branch info" memory
> leaks, 2021-11-16) where I'd assumed that the old_branch_info.path
> would have to start with refs/heads/*, but as has been reported[1]
> that's not the case.
>
> As a test case[2] to reproduce this shows the second "git checkout"
> here runs into the BUG() in the pre-image. The test being added is
> amended from[2] and will pass both with this change, and before
> 9081a421a6. I.e. our behavior now is again the same as before that
> commit.
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 am not sure if this is a sensible test case to begin with.
It sets up recursive symbolic ref in this way:
	HEAD points at refs/heads/a-branch
	refs/heads/a-branch points at refs/remotes/origin/HEAD
	refs/remotes/origin/HEAD points at refs/remotes/origin/branch1

The checked out branch (i.e. what HEAD points at) is nominally a local branch, but it totally violates the spirit of the safety valve that says "HEAD" MUST point at a local branch or otherwise it is detached. Creating a commit while "a-branch" is checked out would not affect *ANY* local branch state and instead makes an update to the remote tracking branch that does not reflect *any* past states at the remote repository. Even worse, a "git fetch" that updates the remote tracking branches will make the HEAD, the index and the working tree into an inconsistent state.

Simply put, I think the BUG() is catching a case where we should have been diagnosing as a broken repository.

So from my point of view, BUG() is indeed inappropriate because what the conditional statement noticed was a broken repository, and not a programming bug.

What we should never do is to promise this "only kosher in letter but not in spirit" violation of "HEAD must point at a local branch" rule will be supported.

So, unless I hear more convincing arguments (and Todd's example or anything similar that makes "git commit" from that state update a ref outside local branches is *not*), I am hesitant to call the new behaviour and 9081a421a6d a regression.

What did the code before that BUG() do when faced with this nonsense configuration? If forbidding outright broke a sensible workflow that happened to have been "working", I am OK to demote it to warning() and restore the previous behaviour temporarily, whatever it was (I think it was just old_branch_info.name was left unset because we were not on local branch, but I don't know if the missing .name was making any irrecoverable damage). But the longer term direction should be that we treat the "update HEAD ends up updating some ref outside refs/heads/" a longstanding bug that needs to be fixed.

Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 4 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.