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

From: shejialuo <[email-masked]>
Date: Mon, 2 Jun 2025 22:11:23 +0800

On Mon, Jun 02, 2025 at 03:59:01PM +0200, Kristoffer Haugsbakk wrote:
> > +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?
> 

We should change directory into the `worktree`. This is because now in
the test, we use "git rev-parse --git-dir" to get the git directory. We
need to find `gitdir` of the linked worktree but not the `gitdir` of the
main worktree. If we do not cd into the directory, we would get the
`gitdir` of the main worktree.

And I agree with you that we need to spawn a subshell. Let me update the
code. Thanks for reminding me, I forgot about that.

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

Thanks for the feedback.

Jialuo