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

Re: [PATCH v2 1/1] fsck: ignore missing "refs" directory for linked worktrees

From
Kristoffer Haugsbakk <code@khaugsbakk.name>
Date
Jun 2, 2025, 13:59 UTC
Message-ID
<21461585-273f-46a9-a750-6ae7b414fcdc@app.fastmail.com>
In-Reply-To
<aD2nPXIXugVXfIpg@ArchLinux>
On Mon, Jun 2, 2025, at 15:29, shejialuo wrote:
Show 6 quoted lines
> "git refs verify" doesn't work if there are worktrees created on Git
> v2.43.0 or older versions. These versions don't automatically create the
> "refs" directory, causing the error:
>
>     error: cannot open directory .git/worktrees/<worktree name>/refs:
>     No such file or directory
Good.
Show 6 quoted lines
> Since 8f4c00de95 (builtin/worktree: create refdb via ref backend,
> 2024-01-08), we automatically create the "refs" directory for new
> worktrees. And in 7c78d819e6 (ref: support multiple worktrees check for
> refs, 2024-11-20), we assume that all linked worktrees have this
> directory and would wrongly report an error to the user, thus
> introducing compatibility issue.

Okay, you don’t mention c1cf918d3ad (builtin/fsck: add `git refs verify` child process, 2025-02-28) in the commit message because of your reply:

> > Because we would call "git refs verify" subprocess in "git-fsck(1)"
> > in this release cycle, I just want to fix this problem before the
> > release.  Thus, it won't affect the users.
https://lore.kernel.org/git/a2a50127-6ab9-4d8a-abcc-b1a741df293e@app.fastmail.com/T/#m01231abb77735b0f480743e0d2adecc172e1f170
Which I just mention here for completeness and my own memory.  ;)
All good.
Show 15 quoted lines
> Check for ENOENT errno before reporting directory access errors for
> linked worktrees to maintain backward compatibility.
>
> Reported-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> Signed-off-by: shejialuo <shejialuo@gmail.com>
> [snip]
> +test_expect_success 'no refs directory of worktree should not cause problems' '
> +	test_when_finished "rm -rf repo" &&
> +	git init repo &&
> +	(
> +		cd repo &&
> +		test_commit initial &&
> +		git worktree add --detach ./worktree &&
> +
> +		cd worktree &&

Now in this version you change-directory into `worktree`. You would need a new subshell for that (test style). But I don’t see the need to chdir in the first place?

Show 13 quoted lines
> +		worktree_refdir="$(git rev-parse --git-dir)/refs" &&
> +		# Simulate old directory layout
> +		rmdir "$worktree_refdir" &&
> +		git refs verify 2>err &&
> +		test_must_be_empty err
> +	)
> +'
> +
>  test_expect_success 'ref name check should work for multiple worktrees' '
>  	test_when_finished "rm -rf repo" &&
>  	git init repo &&
> --
> 2.49.0

The test passes for me. Also when applying only the test (and not the fix) the test fails as expected. Good.

Previous: shejialuoNext: shejialuo
Message 17 of 21 in “[BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs”
  1. kristofferhaugsbakk@fastmail.comMay 30, 2025
  2. Eric SunshineMay 30, 2025
  3. shejialuoMay 31, 2025
  4. Kristoffer HaugsbakkMay 31, 2025
  5. fsck: ignore missing "refs" directory for linked worktreesshejialuo, May 31, 2025
  6. Kristoffer HaugsbakkMay 31, 2025
  7. Junio C HamanoJun 2, 2025
  8. shejialuoJun 2, 2025
  9. Phillip WoodJun 2, 2025
  10. Patrick SteinhardtJun 2, 2025
  11. phillip.wood123@gmail.comJun 2, 2025
  12. Junio C HamanoJun 2, 2025
  13. shejialuoJun 2, 2025
  14. shejialuoJun 2, 2025
  15. 0/1 [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refsshejialuo, Jun 2, 2025
  16. 1/1 fsck: ignore missing "refs" directory for linked worktreesshejialuo, Jun 2, 2025
  17. Kristoffer HaugsbakkJun 2, 2025
  18. shejialuoJun 2, 2025
  19. 0/1 [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refsshejialuo, Jun 2, 2025
  20. 1/1 fsck: ignore missing "refs" directory for linked worktreesshejialuo, Jun 2, 2025
  21. Kristoffer HaugsbakkJun 2, 2025

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.