t[01]*: adjust the references to the default branch name "main"
[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-lib.sh
9
10 RWT="test-tool ref-store worktree:wt"
11 RMAIN="test-tool ref-store worktree:main"
12
13 test_expect_success 'setup' '
14         test_commit first &&
15         git worktree add -b wt-main wt &&
16         (
17                 cd wt &&
18                 test_commit second
19         )
20 '
21
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
29 '
30
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 &&
36
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
41 '
42
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 &&
48
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
53 '
54
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 &&
59
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 &&
63
64         $RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
65         cat >expected <<-\EOF &&
66         HEAD 0x1
67         PSEUDO-WT 0x0
68         refs/bisect/wt-random 0x0
69         refs/heads/main 0x0
70         refs/heads/wt-main 0x0
71         EOF
72         test_cmp expected actual &&
73
74         $RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
75         cat >expected <<-\EOF &&
76         HEAD 0x1
77         PSEUDO-MAIN 0x0
78         refs/bisect/random 0x0
79         refs/heads/main 0x0
80         refs/heads/wt-main 0x0
81         EOF
82         test_cmp expected actual
83 '
84
85 test_done