On Mon, Oct 21, 2024 at 10:56:30AM -0500, karthik nayak wrote: > shejialuo <shejialuo@xxxxxxxxx> writes: > > [snip] > > > diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh > > index 0aee377439..6eb1385c50 100755 > > --- a/t/t0602-reffiles-fsck.sh > > +++ b/t/t0602-reffiles-fsck.sh > > @@ -105,4 +105,63 @@ test_expect_success 'ref name check should be adapted into fsck messages' ' > > 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 && > > + > > + cd repo && > > + test_commit initial && > > + git checkout -b branch-1 && > > + test_commit second && > > + git checkout -b branch-2 && > > + test_commit third && > > + git checkout -b branch-3 && > > + git worktree add ./worktree-1 branch-1 && > > + git worktree add ./worktree-2 branch-2 && > > + worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && > > + worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && > > + > > + ( > > + cd worktree-1 && > > + git update-ref refs/worktree/branch-4 refs/heads/branch-3 > > + ) && > > + ( > > + cd worktree-2 && > > + git update-ref refs/worktree/branch-4 refs/heads/branch-3 > > + ) && > > + > > + cp $worktree1_refdir_prefix/branch-4 $worktree1_refdir_prefix/'\'' branch-5'\'' && > > + cp $worktree2_refdir_prefix/branch-4 $worktree2_refdir_prefix/'\''~branch-6'\'' && > > + > > + test_must_fail git refs verify 2>err && > > + cat >expect <<-EOF && > > + error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format > > + error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format > > + EOF > > + sort err >sorted_err && > > + test_cmp expect sorted_err && > > + > > + ( > > + cd worktree-1 && > > + test_must_fail git refs verify 2>err && > > + cat >expect <<-EOF && > > + error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format > > + error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format > > + EOF > > + sort err >sorted_err && > > + test_cmp expect sorted_err > > + ) && > > + > > + ( > > + cd worktree-2 && > > + test_must_fail git refs verify 2>err && > > + cat >expect <<-EOF && > > + error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format > > + error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format > > + EOF > > + sort err >sorted_err && > > + test_cmp expect sorted_err > > + ) > > These last three loops are the same, couldn't we loop? > > for dir in "." "worktree-1" "worktree-2" > do > ... > done > Actually, I guess all the tests could be written with that way. I need to refactor in the next version to make the tests cleaner. Thanks, Jialuo