Merge branch 'bc/more-git-var'
[alt-git.git] / t / t6101-rev-parse-parents.sh
blobd20723d627629f5379f35c33c74ff22d1082152e
1 #!/bin/sh
3 # Copyright (c) 2005 Johannes Schindelin
6 test_description='Test git rev-parse with different parent options'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK=true
12 TEST_CREATE_REPO_NO_TEMPLATE=1
13 . ./test-lib.sh
15 test_cmp_rev_output () {
16 git rev-parse --verify "$1" >expect &&
17 eval "$2" >actual &&
18 test_cmp expect actual
21 test_expect_success 'setup' '
22 test_commit start &&
23 test_commit second &&
24 git checkout --orphan tmp &&
25 test_commit start2 &&
26 git checkout main &&
27 git merge -m next --allow-unrelated-histories start2 &&
28 test_commit final &&
30 mkdir .git/info &&
31 test_seq 40 |
32 while read i
34 git checkout --orphan "b$i" &&
35 test_tick &&
36 git commit --allow-empty -m "$i" &&
37 commit=$(git rev-parse --verify HEAD) &&
38 printf "$commit " >>.git/info/grafts || return 1
39 done
42 test_expect_success 'start is valid' '
43 git rev-parse start | grep "^$OID_REGEX$"
46 test_expect_success 'start^0' '
47 test_cmp_rev_output tags/start "git rev-parse start^0"
50 test_expect_success 'start^1 not valid' '
51 test_must_fail git rev-parse --verify start^1
54 test_expect_success 'second^1 = second^' '
55 test_cmp_rev_output second^ "git rev-parse second^1"
58 test_expect_success 'final^1^1^1' '
59 test_cmp_rev_output start "git rev-parse final^1^1^1"
62 test_expect_success 'final^1^1^1 = final^^^' '
63 test_cmp_rev_output final^^^ "git rev-parse final^1^1^1"
66 test_expect_success 'final^1^2' '
67 test_cmp_rev_output start2 "git rev-parse final^1^2"
70 test_expect_success 'final^1^2 != final^1^1' '
71 test $(git rev-parse final^1^2) != $(git rev-parse final^1^1)
74 test_expect_success 'final^1^3 not valid' '
75 test_must_fail git rev-parse --verify final^1^3
78 test_expect_success '--verify start2^1' '
79 test_must_fail git rev-parse --verify start2^1
82 test_expect_success '--verify start2^0' '
83 git rev-parse --verify start2^0
86 test_expect_success 'final^1^@ = final^1^1 final^1^2' '
87 git rev-parse final^1^1 final^1^2 >expect &&
88 git rev-parse final^1^@ >actual &&
89 test_cmp expect actual
92 test_expect_success 'symbolic final^1^@ = final^1^1 final^1^2' '
93 git rev-parse --symbolic final^1^1 final^1^2 >expect &&
94 git rev-parse --symbolic final^1^@ >actual &&
95 test_cmp expect actual
98 test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' '
99 git rev-parse final^1 ^final^1^1 ^final^1^2 >expect &&
100 git rev-parse final^1^! >actual &&
101 test_cmp expect actual
104 test_expect_success 'symbolic final^1^! = final^1 ^final^1^1 ^final^1^2' '
105 git rev-parse --symbolic final^1 ^final^1^1 ^final^1^2 >expect &&
106 git rev-parse --symbolic final^1^! >actual &&
107 test_cmp expect actual
110 test_expect_success 'large graft octopus' '
111 test_cmp_rev_output b31 "git rev-parse --verify b1^30"
114 test_expect_success 'repack for next test' '
115 git repack -a -d
118 test_expect_success 'short SHA-1 works' '
119 start=$(git rev-parse --verify start) &&
120 test_cmp_rev_output start "git rev-parse ${start%?}"
123 # rev^- tests; we can use a simpler setup for these
125 test_expect_success 'setup for rev^- tests' '
126 test_commit one &&
127 test_commit two &&
128 test_commit three &&
130 # Merge in a branch for testing rev^-
131 git checkout -b branch &&
132 git checkout HEAD^^ &&
133 git merge -m merge --no-edit --no-ff branch &&
134 git checkout -b merge
137 # The merged branch has 2 commits + the merge
138 test_expect_success 'rev-list --count merge^- = merge^..merge' '
139 git rev-list --count merge^..merge >expect &&
140 echo 3 >actual &&
141 test_cmp expect actual
144 # All rev^- rev-parse tests
146 test_expect_success 'rev-parse merge^- = merge^..merge' '
147 git rev-parse merge^..merge >expect &&
148 git rev-parse merge^- >actual &&
149 test_cmp expect actual
152 test_expect_success 'rev-parse merge^-1 = merge^..merge' '
153 git rev-parse merge^1..merge >expect &&
154 git rev-parse merge^-1 >actual &&
155 test_cmp expect actual
158 test_expect_success 'rev-parse merge^-2 = merge^2..merge' '
159 git rev-parse merge^2..merge >expect &&
160 git rev-parse merge^-2 >actual &&
161 test_cmp expect actual
164 test_expect_success 'symbolic merge^-1 = merge^1..merge' '
165 git rev-parse --symbolic merge^1..merge >expect &&
166 git rev-parse --symbolic merge^-1 >actual &&
167 test_cmp expect actual
170 test_expect_success 'rev-parse merge^-0 (invalid parent)' '
171 test_must_fail git rev-parse merge^-0
174 test_expect_success 'rev-parse merge^-3 (invalid parent)' '
175 test_must_fail git rev-parse merge^-3
178 test_expect_success 'rev-parse merge^-^ (garbage after ^-)' '
179 test_must_fail git rev-parse merge^-^
182 test_expect_success 'rev-parse merge^-1x (garbage after ^-1)' '
183 test_must_fail git rev-parse merge^-1x
186 # All rev^- rev-list tests (should be mostly the same as rev-parse; the reason
187 # for the duplication is that rev-parse and rev-list use different parsers).
189 test_expect_success 'rev-list merge^- = merge^..merge' '
190 git rev-list merge^..merge >expect &&
191 git rev-list merge^- >actual &&
192 test_cmp expect actual
195 test_expect_success 'rev-list merge^-1 = merge^1..merge' '
196 git rev-list merge^1..merge >expect &&
197 git rev-list merge^-1 >actual &&
198 test_cmp expect actual
201 test_expect_success 'rev-list merge^-2 = merge^2..merge' '
202 git rev-list merge^2..merge >expect &&
203 git rev-list merge^-2 >actual &&
204 test_cmp expect actual
207 test_expect_success 'rev-list merge^-0 (invalid parent)' '
208 test_must_fail git rev-list merge^-0
211 test_expect_success 'rev-list merge^-3 (invalid parent)' '
212 test_must_fail git rev-list merge^-3
215 test_expect_success 'rev-list merge^-^ (garbage after ^-)' '
216 test_must_fail git rev-list merge^-^
219 test_expect_success 'rev-list merge^-1x (garbage after ^-1)' '
220 test_must_fail git rev-list merge^-1x
223 test_expect_success 'rev-parse $garbage^@ does not segfault' '
224 test_must_fail git rev-parse $EMPTY_TREE^@
227 test_expect_success 'rev-parse $garbage...$garbage does not segfault' '
228 test_must_fail git rev-parse $EMPTY_TREE...$EMPTY_BLOB
231 test_done