Git 2.38
[alt-git.git] / t / t1415-worktree-refs.sh
blob3b531842dd4c864b45bfd89c36e14f9327d6b29e
1 #!/bin/sh
3 test_description='per-worktree refs'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 test_commit initial &&
10 test_commit wt1 &&
11 test_commit wt2 &&
12 git worktree add wt1 wt1 &&
13 git worktree add wt2 wt2 &&
14 git checkout initial &&
15 git update-ref refs/worktree/foo HEAD &&
16 git -C wt1 update-ref refs/worktree/foo HEAD &&
17 git -C wt2 update-ref refs/worktree/foo HEAD
20 # The 'packed-refs' file is stored directly in .git/. This means it is global
21 # to the repository, and can only contain refs that are shared across all
22 # worktrees.
23 test_expect_success REFFILES 'refs/worktree must not be packed' '
24 git pack-refs --all &&
25 test_path_is_missing .git/refs/tags/wt1 &&
26 test_path_is_file .git/refs/worktree/foo &&
27 test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
28 test_path_is_file .git/worktrees/wt2/refs/worktree/foo
31 test_expect_success 'refs/worktree are per-worktree' '
32 test_cmp_rev worktree/foo initial &&
33 ( cd wt1 && test_cmp_rev worktree/foo wt1 ) &&
34 ( cd wt2 && test_cmp_rev worktree/foo wt2 )
37 test_expect_success 'resolve main-worktree/HEAD' '
38 test_cmp_rev main-worktree/HEAD initial &&
39 ( cd wt1 && test_cmp_rev main-worktree/HEAD initial ) &&
40 ( cd wt2 && test_cmp_rev main-worktree/HEAD initial )
43 test_expect_success 'ambiguous main-worktree/HEAD' '
44 test_when_finished git update-ref -d refs/heads/main-worktree/HEAD &&
45 git update-ref refs/heads/main-worktree/HEAD $(git rev-parse 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 git update-ref refs/heads/worktrees/wt1/HEAD $(git rev-parse HEAD) &&
58 test_when_finished git update-ref -d refs/heads/worktrees/wt1/HEAD &&
59 git rev-parse worktrees/wt1/HEAD 2>warn &&
60 grep "worktrees/wt1/HEAD.*ambiguous" warn
63 test_expect_success 'reflog of main-worktree/HEAD' '
64 git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
65 git reflog main-worktree/HEAD >actual &&
66 test_cmp expected actual &&
67 git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
68 test_cmp expected actual.wt1
71 test_expect_success 'reflog of worktrees/xx/HEAD' '
72 git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
73 git reflog worktrees/wt2/HEAD >actual &&
74 test_cmp expected actual &&
75 git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
76 test_cmp expected actual.wt1 &&
77 git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
78 test_cmp expected actual.wt2
81 test_expect_success 'for-each-ref from main worktree' '
82 mkdir fer1 &&
83 git -C fer1 init repo &&
84 test_commit -C fer1/repo initial &&
85 git -C fer1/repo worktree add ../second &&
86 git -C fer1/repo update-ref refs/bisect/first HEAD &&
87 git -C fer1/repo update-ref refs/rewritten/first HEAD &&
88 git -C fer1/repo update-ref refs/worktree/first HEAD &&
89 git -C fer1/repo for-each-ref --format="%(refname)" | grep first >actual &&
90 cat >expected <<-\EOF &&
91 refs/bisect/first
92 refs/rewritten/first
93 refs/worktree/first
94 EOF
95 test_cmp expected actual
98 test_expect_success 'for-each-ref from linked worktree' '
99 mkdir fer2 &&
100 git -C fer2 init repo &&
101 test_commit -C fer2/repo initial &&
102 git -C fer2/repo worktree add ../second &&
103 git -C fer2/second update-ref refs/bisect/second HEAD &&
104 git -C fer2/second update-ref refs/rewritten/second HEAD &&
105 git -C fer2/second update-ref refs/worktree/second HEAD &&
106 git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
107 cat >expected <<-\EOF &&
108 refs/bisect/second
109 refs/heads/second
110 refs/rewritten/second
111 refs/worktree/second
113 test_cmp expected actual
116 test_done