t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t1415-worktree-refs.sh
blobeb4eec8becbfa64efcde4e866334363a866c01a2
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 test_expect_success 'refs/worktree are per-worktree' '
21 test_cmp_rev worktree/foo initial &&
22 ( cd wt1 && test_cmp_rev worktree/foo wt1 ) &&
23 ( cd wt2 && test_cmp_rev worktree/foo wt2 )
26 test_expect_success 'resolve main-worktree/HEAD' '
27 test_cmp_rev main-worktree/HEAD initial &&
28 ( cd wt1 && test_cmp_rev main-worktree/HEAD initial ) &&
29 ( cd wt2 && test_cmp_rev main-worktree/HEAD initial )
32 test_expect_success 'ambiguous main-worktree/HEAD' '
33 test_when_finished git update-ref -d refs/heads/main-worktree/HEAD &&
34 git update-ref refs/heads/main-worktree/HEAD $(git rev-parse HEAD) &&
35 git rev-parse main-worktree/HEAD 2>warn &&
36 grep "main-worktree/HEAD.*ambiguous" warn
39 test_expect_success 'resolve worktrees/xx/HEAD' '
40 test_cmp_rev worktrees/wt1/HEAD wt1 &&
41 ( cd wt1 && test_cmp_rev worktrees/wt1/HEAD wt1 ) &&
42 ( cd wt2 && test_cmp_rev worktrees/wt1/HEAD wt1 )
45 test_expect_success 'ambiguous worktrees/xx/HEAD' '
46 git update-ref refs/heads/worktrees/wt1/HEAD $(git rev-parse HEAD) &&
47 test_when_finished git update-ref -d refs/heads/worktrees/wt1/HEAD &&
48 git rev-parse worktrees/wt1/HEAD 2>warn &&
49 grep "worktrees/wt1/HEAD.*ambiguous" warn
52 test_expect_success 'reflog of main-worktree/HEAD' '
53 git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
54 git reflog main-worktree/HEAD >actual &&
55 test_cmp expected actual &&
56 git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
57 test_cmp expected actual.wt1
60 test_expect_success 'reflog of worktrees/xx/HEAD' '
61 git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
62 git reflog worktrees/wt2/HEAD >actual &&
63 test_cmp expected actual &&
64 git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
65 test_cmp expected actual.wt1 &&
66 git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
67 test_cmp expected actual.wt2
70 test_expect_success 'for-each-ref from main worktree' '
71 mkdir fer1 &&
72 git -C fer1 init repo &&
73 test_commit -C fer1/repo initial &&
74 git -C fer1/repo worktree add ../second &&
75 git -C fer1/repo update-ref refs/bisect/first HEAD &&
76 git -C fer1/repo update-ref refs/rewritten/first HEAD &&
77 git -C fer1/repo update-ref refs/worktree/first HEAD &&
78 git -C fer1/repo for-each-ref --format="%(refname)" | grep first >actual &&
79 cat >expected <<-\EOF &&
80 refs/bisect/first
81 refs/rewritten/first
82 refs/worktree/first
83 EOF
84 test_cmp expected actual
87 test_expect_success 'for-each-ref from linked worktree' '
88 mkdir fer2 &&
89 git -C fer2 init repo &&
90 test_commit -C fer2/repo initial &&
91 git -C fer2/repo worktree add ../second &&
92 git -C fer2/second update-ref refs/bisect/second HEAD &&
93 git -C fer2/second update-ref refs/rewritten/second HEAD &&
94 git -C fer2/second update-ref refs/worktree/second HEAD &&
95 git -C fer2/second for-each-ref --format="%(refname)" | grep second >actual &&
96 cat >expected <<-\EOF &&
97 refs/bisect/second
98 refs/heads/second
99 refs/rewritten/second
100 refs/worktree/second
102 test_cmp expected actual
105 test_done