3 test_description
='per-worktree refs'
7 test_expect_success
'setup' '
11 git worktree add wt1 wt1 &&
12 git worktree add wt2 wt2 &&
13 git checkout initial &&
14 git update-ref refs/worktree/foo HEAD &&
15 git -C wt1 update-ref refs/worktree/foo HEAD &&
16 git -C wt2 update-ref refs/worktree/foo HEAD
19 # The 'packed-refs' file is stored directly in .git/. This means it is global
20 # to the repository, and can only contain refs that are shared across all
22 test_expect_success REFFILES
'refs/worktree must not be packed' '
23 git pack-refs --all &&
24 test_path_is_missing .git/refs/tags/wt1 &&
25 test_path_is_file .git/refs/worktree/foo &&
26 test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
27 test_path_is_file .git/worktrees/wt2/refs/worktree/foo
30 test_expect_success
'refs/worktree are per-worktree' '
31 test_cmp_rev worktree/foo initial &&
32 ( cd wt1 && test_cmp_rev worktree/foo wt1 ) &&
33 ( cd wt2 && test_cmp_rev worktree/foo wt2 )
36 test_expect_success
'resolve main-worktree/HEAD' '
37 test_cmp_rev main-worktree/HEAD initial &&
38 ( cd wt1 && test_cmp_rev main-worktree/HEAD initial ) &&
39 ( cd wt2 && test_cmp_rev main-worktree/HEAD initial )
42 test_expect_success
'ambiguous main-worktree/HEAD' '
43 mkdir -p .git/refs/heads/main-worktree &&
44 test_when_finished rm -f .git/refs/heads/main-worktree/HEAD &&
45 cp .git/HEAD .git/refs/heads/main-worktree/HEAD &&
46 git rev-parse main-worktree/HEAD 2>warn &&
47 grep "main-worktree/HEAD.*ambiguous" warn
50 test_expect_success
'resolve worktrees/xx/HEAD' '
51 test_cmp_rev worktrees/wt1/HEAD wt1 &&
52 ( cd wt1 && test_cmp_rev worktrees/wt1/HEAD wt1 ) &&
53 ( cd wt2 && test_cmp_rev worktrees/wt1/HEAD wt1 )
56 test_expect_success
'ambiguous worktrees/xx/HEAD' '
57 mkdir -p .git/refs/heads/worktrees/wt1 &&
58 test_when_finished rm -f .git/refs/heads/worktrees/wt1/HEAD &&
59 cp .git/HEAD .git/refs/heads/worktrees/wt1/HEAD &&
60 git rev-parse worktrees/wt1/HEAD 2>warn &&
61 grep "worktrees/wt1/HEAD.*ambiguous" warn
64 test_expect_success
'reflog of main-worktree/HEAD' '
65 git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
66 git reflog main-worktree/HEAD >actual &&
67 test_cmp expected actual &&
68 git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
69 test_cmp expected actual.wt1
72 test_expect_success
'reflog of worktrees/xx/HEAD' '
73 git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
74 git reflog worktrees/wt2/HEAD >actual &&
75 test_cmp expected actual &&
76 git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
77 test_cmp expected actual.wt1 &&
78 git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
79 test_cmp expected actual.wt2
82 test_expect_success
'for-each-ref from main worktree' '
84 git -C fer1 init repo &&
85 test_commit -C fer1/repo initial &&
86 git -C fer1/repo worktree add ../second &&
87 git -C fer1/repo update-ref refs/bisect/first HEAD &&
88 git -C fer1/repo update-ref refs/rewritten/first HEAD &&
89 git -C fer1/repo update-ref refs/worktree/first HEAD &&
90 git -C fer1/repo for-each-ref --format="%(refname)" | grep first >actual &&
91 cat >expected <<-\EOF &&
96 test_cmp expected actual
99 test_expect_success
'for-each-ref from linked worktree' '
101 git -C fer2 init repo &&
102 test_commit -C fer2/repo initial &&
103 git -C fer2/repo worktree add ../second &&
104 git -C fer2/second update-ref refs/bisect/second HEAD &&
105 git -C fer2/second update-ref refs/rewritten/second HEAD &&
106 git -C fer2/second update-ref refs/worktree/second HEAD &&
107 git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
108 cat >expected <<-\EOF &&
111 refs/rewritten/second
114 test_cmp expected actual