]>
Commit | Line | Data |
---|---|---|
fa099d23 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='test worktree ref store api' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
3e3b9321 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
fa099d23 NTND |
9 | . ./test-lib.sh |
10 | ||
65370d81 NTND |
11 | RWT="test-tool ref-store worktree:wt" |
12 | RMAIN="test-tool ref-store worktree:main" | |
fa099d23 NTND |
13 | |
14 | test_expect_success 'setup' ' | |
15 | test_commit first && | |
06d53148 | 16 | git worktree add -b wt-main wt && |
fa099d23 NTND |
17 | ( |
18 | cd wt && | |
19 | test_commit second | |
20 | ) | |
21 | ' | |
22 | ||
23 | test_expect_success 'resolve_ref(<shared-ref>)' ' | |
06d53148 JS |
24 | SHA1=`git rev-parse main` && |
25 | echo "$SHA1 refs/heads/main 0x0" >expected && | |
26 | $RWT resolve-ref refs/heads/main 0 >actual && | |
fa099d23 | 27 | test_cmp expected actual && |
06d53148 | 28 | $RMAIN resolve-ref refs/heads/main 0 >actual && |
fa099d23 NTND |
29 | test_cmp expected actual |
30 | ' | |
31 | ||
32 | test_expect_success 'resolve_ref(<per-worktree-ref>)' ' | |
33 | SHA1=`git -C wt rev-parse HEAD` && | |
06d53148 | 34 | echo "$SHA1 refs/heads/wt-main 0x1" >expected && |
fa099d23 NTND |
35 | $RWT resolve-ref HEAD 0 >actual && |
36 | test_cmp expected actual && | |
37 | ||
38 | SHA1=`git rev-parse HEAD` && | |
06d53148 | 39 | echo "$SHA1 refs/heads/main 0x1" >expected && |
fa099d23 NTND |
40 | $RMAIN resolve-ref HEAD 0 >actual && |
41 | test_cmp expected actual | |
42 | ' | |
43 | ||
06d53148 JS |
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 && | |
d026a256 NTND |
47 | git -C wt symbolic-ref FOO >actual && |
48 | test_cmp expected actual && | |
49 | ||
06d53148 JS |
50 | $RMAIN create-symref FOO refs/heads/wt-main nothing && |
51 | echo refs/heads/wt-main >expected && | |
d026a256 NTND |
52 | git symbolic-ref FOO >actual && |
53 | test_cmp expected actual | |
54 | ' | |
55 | ||
759d02d1 HWN |
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()' ' | |
8125a58b | 64 | echo $ZERO_OID > .git/logs/PSEUDO-MAIN && |
944b4e30 | 65 | mkdir -p .git/logs/refs/bisect && |
8125a58b | 66 | echo $ZERO_OID > .git/logs/refs/bisect/random && |
944b4e30 | 67 | |
8125a58b | 68 | echo $ZERO_OID > .git/worktrees/wt/logs/PSEUDO-WT && |
944b4e30 | 69 | mkdir -p .git/worktrees/wt/logs/refs/bisect && |
8125a58b | 70 | echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random && |
944b4e30 | 71 | |
43c94bbf | 72 | $RWT for-each-reflog | cut -d" " -f 2- | sort >actual && |
944b4e30 NTND |
73 | cat >expected <<-\EOF && |
74 | HEAD 0x1 | |
75 | PSEUDO-WT 0x0 | |
76 | refs/bisect/wt-random 0x0 | |
06d53148 JS |
77 | refs/heads/main 0x0 |
78 | refs/heads/wt-main 0x0 | |
944b4e30 NTND |
79 | EOF |
80 | test_cmp expected actual && | |
81 | ||
43c94bbf | 82 | $RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual && |
944b4e30 NTND |
83 | cat >expected <<-\EOF && |
84 | HEAD 0x1 | |
85 | PSEUDO-MAIN 0x0 | |
86 | refs/bisect/random 0x0 | |
06d53148 JS |
87 | refs/heads/main 0x0 |
88 | refs/heads/wt-main 0x0 | |
944b4e30 NTND |
89 | EOF |
90 | test_cmp expected actual | |
91 | ' | |
92 | ||
fa099d23 | 93 | test_done |