]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1415-worktree-refs.sh
refs: new ref types to make per-worktree refs visible to all worktrees
[thirdparty/git.git] / t / t1415-worktree-refs.sh
1 #!/bin/sh
2
3 test_description='per-worktree refs'
4
5 . ./test-lib.sh
6
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
17 '
18
19 test_expect_success 'refs/worktree must not be packed' '
20 git pack-refs --all &&
21 test_path_is_missing .git/refs/tags/wt1 &&
22 test_path_is_file .git/refs/worktree/foo &&
23 test_path_is_file .git/worktrees/wt1/refs/worktree/foo &&
24 test_path_is_file .git/worktrees/wt2/refs/worktree/foo
25 '
26
27 test_expect_success 'refs/worktree are per-worktree' '
28 test_cmp_rev worktree/foo initial &&
29 ( cd wt1 && test_cmp_rev worktree/foo wt1 ) &&
30 ( cd wt2 && test_cmp_rev worktree/foo wt2 )
31 '
32
33 test_expect_success 'resolve main-worktree/HEAD' '
34 test_cmp_rev main-worktree/HEAD initial &&
35 ( cd wt1 && test_cmp_rev main-worktree/HEAD initial ) &&
36 ( cd wt2 && test_cmp_rev main-worktree/HEAD initial )
37 '
38
39 test_expect_success 'ambiguous main-worktree/HEAD' '
40 mkdir -p .git/refs/heads/main-worktree &&
41 test_when_finished rm -f .git/refs/heads/main-worktree/HEAD &&
42 cp .git/HEAD .git/refs/heads/main-worktree/HEAD &&
43 git rev-parse main-worktree/HEAD 2>warn &&
44 grep "main-worktree/HEAD.*ambiguous" warn
45 '
46
47 test_expect_success 'resolve worktrees/xx/HEAD' '
48 test_cmp_rev worktrees/wt1/HEAD wt1 &&
49 ( cd wt1 && test_cmp_rev worktrees/wt1/HEAD wt1 ) &&
50 ( cd wt2 && test_cmp_rev worktrees/wt1/HEAD wt1 )
51 '
52
53 test_expect_success 'ambiguous worktrees/xx/HEAD' '
54 mkdir -p .git/refs/heads/worktrees/wt1 &&
55 test_when_finished rm -f .git/refs/heads/worktrees/wt1/HEAD &&
56 cp .git/HEAD .git/refs/heads/worktrees/wt1/HEAD &&
57 git rev-parse worktrees/wt1/HEAD 2>warn &&
58 grep "worktrees/wt1/HEAD.*ambiguous" warn
59 '
60
61 test_expect_success 'reflog of main-worktree/HEAD' '
62 git reflog HEAD | sed "s/HEAD/main-worktree\/HEAD/" >expected &&
63 git reflog main-worktree/HEAD >actual &&
64 test_cmp expected actual &&
65 git -C wt1 reflog main-worktree/HEAD >actual.wt1 &&
66 test_cmp expected actual.wt1
67 '
68
69 test_expect_success 'reflog of worktrees/xx/HEAD' '
70 git -C wt2 reflog HEAD | sed "s/HEAD/worktrees\/wt2\/HEAD/" >expected &&
71 git reflog worktrees/wt2/HEAD >actual &&
72 test_cmp expected actual &&
73 git -C wt1 reflog worktrees/wt2/HEAD >actual.wt1 &&
74 test_cmp expected actual.wt1 &&
75 git -C wt2 reflog worktrees/wt2/HEAD >actual.wt2 &&
76 test_cmp expected actual.wt2
77 '
78
79 test_done