3 test_description='test worktree ref store api'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 RWT="test-tool ref-store worktree:wt"
11 RMAIN="test-tool ref-store worktree:main"
13 test_expect_success 'setup' '
15 git worktree add -b wt-main wt &&
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 test_expect_success 'for_each_reflog()' '
56 echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
57 mkdir -p .git/logs/refs/bisect &&
58 echo $ZERO_OID > .git/logs/refs/bisect/random &&
60 echo $ZERO_OID > .git/worktrees/wt/logs/PSEUDO-WT &&
61 mkdir -p .git/worktrees/wt/logs/refs/bisect &&
62 echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
64 $RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
65 cat >expected <<-\EOF &&
68 refs/bisect/wt-random 0x0
70 refs/heads/wt-main 0x0
72 test_cmp expected actual &&
74 $RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
75 cat >expected <<-\EOF &&
78 refs/bisect/random 0x0
80 refs/heads/wt-main 0x0
82 test_cmp expected actual