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