]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1407-worktree-ref-store.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t1407-worktree-ref-store.sh
1 #!/bin/sh
2
3 test_description='test worktree ref store api'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 RWT="test-tool ref-store worktree:wt"
12 RMAIN="test-tool ref-store worktree:main"
13
14 test_expect_success 'setup' '
15 test_commit first &&
16 git worktree add -b wt-main wt &&
17 (
18 cd wt &&
19 test_commit second
20 )
21 '
22
23 test_expect_success 'resolve_ref(<shared-ref>)' '
24 SHA1=`git rev-parse main` &&
25 echo "$SHA1 refs/heads/main 0x0" >expected &&
26 $RWT resolve-ref refs/heads/main 0 >actual &&
27 test_cmp expected actual &&
28 $RMAIN resolve-ref refs/heads/main 0 >actual &&
29 test_cmp expected actual
30 '
31
32 test_expect_success 'resolve_ref(<per-worktree-ref>)' '
33 SHA1=`git -C wt rev-parse HEAD` &&
34 echo "$SHA1 refs/heads/wt-main 0x1" >expected &&
35 $RWT resolve-ref HEAD 0 >actual &&
36 test_cmp expected actual &&
37
38 SHA1=`git rev-parse HEAD` &&
39 echo "$SHA1 refs/heads/main 0x1" >expected &&
40 $RMAIN resolve-ref HEAD 0 >actual &&
41 test_cmp expected actual
42 '
43
44 test_expect_success 'create_symref(FOO, refs/heads/main)' '
45 $RWT create-symref FOO refs/heads/main nothing &&
46 echo refs/heads/main >expected &&
47 git -C wt symbolic-ref FOO >actual &&
48 test_cmp expected actual &&
49
50 $RMAIN create-symref FOO refs/heads/wt-main nothing &&
51 echo refs/heads/wt-main >expected &&
52 git symbolic-ref FOO >actual &&
53 test_cmp expected actual
54 '
55
56 # Some refs (refs/bisect/*, pseudorefs) are kept per worktree, so they should
57 # only appear in the for-each-reflog output if it is called from the correct
58 # worktree, which is exercised in this test. This test is poorly written (and
59 # therefore marked REFFILES) for mulitple reasons: 1) it creates invalidly
60 # formatted log entres. 2) it uses direct FS access for creating the reflogs. 3)
61 # PSEUDO-WT and refs/bisect/random do not create reflogs by default, so it is
62 # not testing a realistic scenario.
63 test_expect_success REFFILES 'for_each_reflog()' '
64 echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
65 mkdir -p .git/logs/refs/bisect &&
66 echo $ZERO_OID > .git/logs/refs/bisect/random &&
67
68 echo $ZERO_OID > .git/worktrees/wt/logs/PSEUDO-WT &&
69 mkdir -p .git/worktrees/wt/logs/refs/bisect &&
70 echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
71
72 $RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
73 cat >expected <<-\EOF &&
74 HEAD 0x1
75 PSEUDO-WT 0x0
76 refs/bisect/wt-random 0x0
77 refs/heads/main 0x0
78 refs/heads/wt-main 0x0
79 EOF
80 test_cmp expected actual &&
81
82 $RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
83 cat >expected <<-\EOF &&
84 HEAD 0x1
85 PSEUDO-MAIN 0x0
86 refs/bisect/random 0x0
87 refs/heads/main 0x0
88 refs/heads/wt-main 0x0
89 EOF
90 test_cmp expected actual
91 '
92
93 test_done