Merge branch 'fz/po-2.36.0-round2' of github.com:fangyi-zhou/git-po
[alt-git.git] / t / t6101-rev-parse-parents.sh
blobc571fa517978818703e29c72e36faf52643a8ee5
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-lib.sh
13 test_cmp_rev_output () {
14 git rev-parse --verify "$1" >expect &&
15 eval "$2" >actual &&
16 test_cmp expect actual
19 test_expect_success 'setup' '
20 test_commit start &&
21 test_commit second &&
22 git checkout --orphan tmp &&
23 test_commit start2 &&
24 git checkout main &&
25 git merge -m next --allow-unrelated-histories start2 &&
26 test_commit final &&
28 test_seq 40 |
29 while read i
31 git checkout --orphan "b$i" &&
32 test_tick &&
33 git commit --allow-empty -m "$i" &&
34 commit=$(git rev-parse --verify HEAD) &&
35 printf "$commit " >>.git/info/grafts || return 1
36 done
39 test_expect_success 'start is valid' '
40 git rev-parse start | grep "^$OID_REGEX$"
43 test_expect_success 'start^0' '
44 test_cmp_rev_output tags/start "git rev-parse start^0"
47 test_expect_success 'start^1 not valid' '
48 test_must_fail git rev-parse --verify start^1
51 test_expect_success 'second^1 = second^' '
52 test_cmp_rev_output second^ "git rev-parse second^1"
55 test_expect_success 'final^1^1^1' '
56 test_cmp_rev_output start "git rev-parse final^1^1^1"
59 test_expect_success 'final^1^1^1 = final^^^' '
60 test_cmp_rev_output final^^^ "git rev-parse final^1^1^1"
63 test_expect_success 'final^1^2' '
64 test_cmp_rev_output start2 "git rev-parse final^1^2"
67 test_expect_success 'final^1^2 != final^1^1' '
68 test $(git rev-parse final^1^2) != $(git rev-parse final^1^1)
71 test_expect_success 'final^1^3 not valid' '
72 test_must_fail git rev-parse --verify final^1^3
75 test_expect_success '--verify start2^1' '
76 test_must_fail git rev-parse --verify start2^1
79 test_expect_success '--verify start2^0' '
80 git rev-parse --verify start2^0
83 test_expect_success 'final^1^@ = final^1^1 final^1^2' '
84 git rev-parse final^1^1 final^1^2 >expect &&
85 git rev-parse final^1^@ >actual &&
86 test_cmp expect actual
89 test_expect_success 'symbolic final^1^@ = final^1^1 final^1^2' '
90 git rev-parse --symbolic final^1^1 final^1^2 >expect &&
91 git rev-parse --symbolic final^1^@ >actual &&
92 test_cmp expect actual
95 test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' '
96 git rev-parse final^1 ^final^1^1 ^final^1^2 >expect &&
97 git rev-parse final^1^! >actual &&
98 test_cmp expect actual
101 test_expect_success 'symbolic final^1^! = final^1 ^final^1^1 ^final^1^2' '
102 git rev-parse --symbolic final^1 ^final^1^1 ^final^1^2 >expect &&
103 git rev-parse --symbolic final^1^! >actual &&
104 test_cmp expect actual
107 test_expect_success 'large graft octopus' '
108 test_cmp_rev_output b31 "git rev-parse --verify b1^30"
111 test_expect_success 'repack for next test' '
112 git repack -a -d
115 test_expect_success 'short SHA-1 works' '
116 start=$(git rev-parse --verify start) &&
117 test_cmp_rev_output start "git rev-parse ${start%?}"
120 # rev^- tests; we can use a simpler setup for these
122 test_expect_success 'setup for rev^- tests' '
123 test_commit one &&
124 test_commit two &&
125 test_commit three &&
127 # Merge in a branch for testing rev^-
128 git checkout -b branch &&
129 git checkout HEAD^^ &&
130 git merge -m merge --no-edit --no-ff branch &&
131 git checkout -b merge
134 # The merged branch has 2 commits + the merge
135 test_expect_success 'rev-list --count merge^- = merge^..merge' '
136 git rev-list --count merge^..merge >expect &&
137 echo 3 >actual &&
138 test_cmp expect actual
141 # All rev^- rev-parse tests
143 test_expect_success 'rev-parse merge^- = merge^..merge' '
144 git rev-parse merge^..merge >expect &&
145 git rev-parse merge^- >actual &&
146 test_cmp expect actual
149 test_expect_success 'rev-parse merge^-1 = merge^..merge' '
150 git rev-parse merge^1..merge >expect &&
151 git rev-parse merge^-1 >actual &&
152 test_cmp expect actual
155 test_expect_success 'rev-parse merge^-2 = merge^2..merge' '
156 git rev-parse merge^2..merge >expect &&
157 git rev-parse merge^-2 >actual &&
158 test_cmp expect actual
161 test_expect_success 'symbolic merge^-1 = merge^1..merge' '
162 git rev-parse --symbolic merge^1..merge >expect &&
163 git rev-parse --symbolic merge^-1 >actual &&
164 test_cmp expect actual
167 test_expect_success 'rev-parse merge^-0 (invalid parent)' '
168 test_must_fail git rev-parse merge^-0
171 test_expect_success 'rev-parse merge^-3 (invalid parent)' '
172 test_must_fail git rev-parse merge^-3
175 test_expect_success 'rev-parse merge^-^ (garbage after ^-)' '
176 test_must_fail git rev-parse merge^-^
179 test_expect_success 'rev-parse merge^-1x (garbage after ^-1)' '
180 test_must_fail git rev-parse merge^-1x
183 # All rev^- rev-list tests (should be mostly the same as rev-parse; the reason
184 # for the duplication is that rev-parse and rev-list use different parsers).
186 test_expect_success 'rev-list merge^- = merge^..merge' '
187 git rev-list merge^..merge >expect &&
188 git rev-list merge^- >actual &&
189 test_cmp expect actual
192 test_expect_success 'rev-list merge^-1 = merge^1..merge' '
193 git rev-list merge^1..merge >expect &&
194 git rev-list merge^-1 >actual &&
195 test_cmp expect actual
198 test_expect_success 'rev-list merge^-2 = merge^2..merge' '
199 git rev-list merge^2..merge >expect &&
200 git rev-list merge^-2 >actual &&
201 test_cmp expect actual
204 test_expect_success 'rev-list merge^-0 (invalid parent)' '
205 test_must_fail git rev-list merge^-0
208 test_expect_success 'rev-list merge^-3 (invalid parent)' '
209 test_must_fail git rev-list merge^-3
212 test_expect_success 'rev-list merge^-^ (garbage after ^-)' '
213 test_must_fail git rev-list merge^-^
216 test_expect_success 'rev-list merge^-1x (garbage after ^-1)' '
217 test_must_fail git rev-list merge^-1x
220 test_expect_success 'rev-parse $garbage^@ does not segfault' '
221 test_must_fail git rev-parse $EMPTY_TREE^@
224 test_expect_success 'rev-parse $garbage...$garbage does not segfault' '
225 test_must_fail git rev-parse $EMPTY_TREE...$EMPTY_BLOB
228 test_done