[BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kristoffer Haugsbakk <code@xxxxxxxxxxxxxxx>

(regular git-bugreport(1) follows after this, then a demo patch)

git-refs-verify(1) checks worktree refs since v2.47.0-111-g7c78d819e6a
(ref: support multiple worktrees check for refs, 2024-11-20).  This
causes the command to always exit with code `255` and stderr output
lines for each worktree created on v2.43.0 or older that does not have
worktree refs:

    error: cannot open directory .git/worktrees/<worktree name>/refs: No such file or directory

This is apparently caused by worktrees created on Git v2.43.0 or older.
Apparently these worktrees don’t have this directory unless there exist
worktree refs:

    .git/worktrees/<worktree name>/refs

Again: any such worktrees work fine if you for example have bisect refs.
But the command will always fail if you have one or more v2.43.0 or
older worktrees with no worktree refs.

git-fsck(1) also now prints the same warnings because of the default
`--reference`.  But the operation of the command seems unaffected.

So to reproduce (also see patch at the end)

1. Make a worktree on v2.43.0 or just make a worktree and delete the
   `refs/` directory for the worktree
2. Run `git refs verify`
   • On your regular git(1): not on v2.43.0
3. Expected: succeeds without output
4. Actual: exit code `255`, `cannot open directory` on stderr

Or reproduce with this script (replace with clone with worktree if
you prefer):

    git config set --global safe.directory /tmp &&
    cd /tmp &&
    dir=$(mktemp -d)
    cd $dir
    git clone https://github.com/git/git git-older &&
    cd git-older &&
    git checkout v2.43.0 &&
    make &&
    # use Git v2.43.0
    ./git worktree add --detach worktree1234 &&
    # will fail
    git refs verify
    # Cleanup
    git config unset --global safe.directory

§ Testing on `seen` and `next`

• seen: bfa90786bc5 (Merge branch 'jk/diff-no-index-with-pathspec' into
  seen, 2025-05-29)
• next: d4ff7b7c865 (Sync with 'master', 2025-05-29)

§ Regular report

> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)

Using a repository with worktrees that were apparently made on v2.43.0
or older, based on testing.  Some of them have no worktree refs which is
what triggers this behavior.

> What did you expect to happen? (Expected behavior)

`git refs verify` with exit code `0` and no output.

> What happened instead? (Actual behavior)

The same command exits with exit code `255` and output like

    error: cannot open directory .git/worktrees/<worktree name>/refs: No such file or directory

What's different between what you expected and what actually happened?

See above.

> Anything else you want to add:
>
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.50.0.rc0
cpu: x86_64
built from commit: b32feae0f1b21faaf8e191e8d3314a32470a536b
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 7.81.0
OpenSSL: OpenSSL 3.0.2 15 Mar 2022
zlib: 1.2.11
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
uname: Linux 6.8.0-59-generic #61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:03:15 UTC 2 x86_64
compiler info: gnuc: 11.4
libc info: glibc: 2.35
$SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
post-rewrite
sendemail-validate

-- 8< --
From: Kristoffer Haugsbakk <code@xxxxxxxxxxxxxxx>
Subject: [PATCH] t0602: demo v2.43.0 worktree problem

Signed-off-by: Kristoffer Haugsbakk <code@xxxxxxxxxxxxxxx>
---
 t/t0602-reffiles-fsck.sh | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
diff --git a/t/t0602-reffiles-fsck.sh b/t/t0602-reffiles-fsck.sh
index f671ac4d3ab..90b68f6561e 100755
--- a/t/t0602-reffiles-fsck.sh
+++ b/t/t0602-reffiles-fsck.sh
@@ -886,4 +886,47 @@ test_expect_success '--[no-]references option should apply to fsck' '
 	)
 '
 
+# These worktrees will not have a refs/ directory unless there
+# actually exist worktree refs
+test_expect_failure 'works with worktrees from v2.43.0 or older without worktree refs' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		git checkout -b default-branch &&
+		git worktree add --detach ./worktree &&
+		# Simulate old directory layout
+		rmdir .git/worktrees/worktree/refs &&
+		git refs verify 2>err &&
+		test_must_be_empty err
+	)
+'
+
+test_expect_success 'works with worktrees from v2.43.0 or older with worktree refs' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		test_commit second &&
+		git checkout -b default-branch &&
+		git worktree add --detach ./worktree &&
+		(
+			cd worktree &&
+			git bisect start &&
+			git bisect bad HEAD &&
+			git bisect good initial &&
+			# Simulate old directory layout: delete if empty
+			# But there should exist a refs/bisect/ directory now
+			if [ ! -e ../.git/worktrees/worktree/refs/bisect ]
+			then
+				rmdir ../.git/worktrees/worktree/refs
+			fi &&
+			git refs verify 2>err &&
+			test_must_be_empty err
+		)
+	)
+'
+
 test_done
-- 
Don’t cry because the bug is fixed. Smile because it happened.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux