t1092: stress test 'git sparse-checkout set'
[git/debian.git] / t / t1415-worktree-refs.sh
bloba3e6ea08088b15ee461c53e2baebe7d0dfb19664
1 #!/bin/sh
3 test_description='per-worktree refs'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit initial &&
9 test_commit wt1 &&
10 test_commit wt2 &&
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
21 # worktrees.
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 test_when_finished git update-ref -d refs/heads/main-worktree/HEAD &&
44 git update-ref refs/heads/main-worktree/HEAD $(git rev-parse HEAD) &&
45 git rev-parse main-worktree/HEAD 2>warn &&
46 grep "main-worktree/HEAD.*ambiguous" warn
49 test_expect_success 'resolve worktrees/xx/HEAD' '
50 test_cmp_rev worktrees/wt1/HEAD wt1 &&
51 ( cd wt1 && test_cmp_rev worktrees/wt1/HEAD wt1 ) &&
52 ( cd wt2 && test_cmp_rev worktrees/wt1/HEAD wt1 )
55 test_expect_success 'ambiguous worktrees/xx/HEAD' '
56 git update-ref refs/heads/worktrees/wt1/HEAD $(git rev-parse HEAD) &&
57 test_when_finished git update-ref -d refs/heads/worktrees/wt1/HEAD &&
58 git rev-parse worktrees/wt1/HEAD 2>warn &&
59 grep "worktrees/wt1/HEAD.*ambiguous" warn
62 test_expect_success 'reflog of main-worktree/HEAD' '
63 git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
64 git reflog main-worktree/HEAD >actual &&
65 test_cmp expected actual &&
66 git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
67 test_cmp expected actual.wt1
70 test_expect_success 'reflog of worktrees/xx/HEAD' '
71 git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
72 git reflog worktrees/wt2/HEAD >actual &&
73 test_cmp expected actual &&
74 git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
75 test_cmp expected actual.wt1 &&
76 git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
77 test_cmp expected actual.wt2
80 test_expect_success 'for-each-ref from main worktree' '
81 mkdir fer1 &&
82 git -C fer1 init repo &&
83 test_commit -C fer1/repo initial &&
84 git -C fer1/repo worktree add ../second &&
85 git -C fer1/repo update-ref refs/bisect/first HEAD &&
86 git -C fer1/repo update-ref refs/rewritten/first HEAD &&
87 git -C fer1/repo update-ref refs/worktree/first HEAD &&
88 git -C fer1/repo for-each-ref --format="%(refname)" | grep first >actual &&
89 cat >expected <<-\EOF &&
90 refs/bisect/first
91 refs/rewritten/first
92 refs/worktree/first
93 EOF
94 test_cmp expected actual
97 test_expect_success 'for-each-ref from linked worktree' '
98 mkdir fer2 &&
99 git -C fer2 init repo &&
100 test_commit -C fer2/repo initial &&
101 git -C fer2/repo worktree add ../second &&
102 git -C fer2/second update-ref refs/bisect/second HEAD &&
103 git -C fer2/second update-ref refs/rewritten/second HEAD &&
104 git -C fer2/second update-ref refs/worktree/second HEAD &&
105 git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
106 cat >expected <<-\EOF &&
107 refs/bisect/second
108 refs/heads/second
109 refs/rewritten/second
110 refs/worktree/second
112 test_cmp expected actual
115 test_done