blob: c571fa517978818703e29c72e36faf52643a8ee5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
#!/bin/sh
#
# Copyright (c) 2005 Johannes Schindelin
#
test_description='Test git rev-parse with different parent options'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_cmp_rev_output () {
git rev-parse --verify "$1" >expect &&
eval "$2" >actual &&
test_cmp expect actual
}
test_expect_success 'setup' '
test_commit start &&
test_commit second &&
git checkout --orphan tmp &&
test_commit start2 &&
git checkout main &&
git merge -m next --allow-unrelated-histories start2 &&
test_commit final &&
test_seq 40 |
while read i
do
git checkout --orphan "b$i" &&
test_tick &&
git commit --allow-empty -m "$i" &&
commit=$(git rev-parse --verify HEAD) &&
printf "$commit " >>.git/info/grafts || return 1
done
'
test_expect_success 'start is valid' '
git rev-parse start | grep "^$OID_REGEX$"
'
test_expect_success 'start^0' '
test_cmp_rev_output tags/start "git rev-parse start^0"
'
test_expect_success 'start^1 not valid' '
test_must_fail git rev-parse --verify start^1
'
test_expect_success 'second^1 = second^' '
test_cmp_rev_output second^ "git rev-parse second^1"
'
test_expect_success 'final^1^1^1' '
test_cmp_rev_output start "git rev-parse final^1^1^1"
'
test_expect_success 'final^1^1^1 = final^^^' '
test_cmp_rev_output final^^^ "git rev-parse final^1^1^1"
'
test_expect_success 'final^1^2' '
test_cmp_rev_output start2 "git rev-parse final^1^2"
'
test_expect_success 'final^1^2 != final^1^1' '
test $(git rev-parse final^1^2) != $(git rev-parse final^1^1)
'
test_expect_success 'final^1^3 not valid' '
test_must_fail git rev-parse --verify final^1^3
'
test_expect_success '--verify start2^1' '
test_must_fail git rev-parse --verify start2^1
'
test_expect_success '--verify start2^0' '
git rev-parse --verify start2^0
'
test_expect_success 'final^1^@ = final^1^1 final^1^2' '
git rev-parse final^1^1 final^1^2 >expect &&
git rev-parse final^1^@ >actual &&
test_cmp expect actual
'
test_expect_success 'symbolic final^1^@ = final^1^1 final^1^2' '
git rev-parse --symbolic final^1^1 final^1^2 >expect &&
git rev-parse --symbolic final^1^@ >actual &&
test_cmp expect actual
'
test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' '
git rev-parse final^1 ^final^1^1 ^final^1^2 >expect &&
git rev-parse final^1^! >actual &&
test_cmp expect actual
'
test_expect_success 'symbolic final^1^! = final^1 ^final^1^1 ^final^1^2' '
git rev-parse --symbolic final^1 ^final^1^1 ^final^1^2 >expect &&
git rev-parse --symbolic final^1^! >actual &&
test_cmp expect actual
'
test_expect_success 'large graft octopus' '
test_cmp_rev_output b31 "git rev-parse --verify b1^30"
'
test_expect_success 'repack for next test' '
git repack -a -d
'
test_expect_success 'short SHA-1 works' '
start=$(git rev-parse --verify start) &&
test_cmp_rev_output start "git rev-parse ${start%?}"
'
# rev^- tests; we can use a simpler setup for these
test_expect_success 'setup for rev^- tests' '
test_commit one &&
test_commit two &&
test_commit three &&
# Merge in a branch for testing rev^-
git checkout -b branch &&
git checkout HEAD^^ &&
git merge -m merge --no-edit --no-ff branch &&
git checkout -b merge
'
# The merged branch has 2 commits + the merge
test_expect_success 'rev-list --count merge^- = merge^..merge' '
git rev-list --count merge^..merge >expect &&
echo 3 >actual &&
test_cmp expect actual
'
# All rev^- rev-parse tests
test_expect_success 'rev-parse merge^- = merge^..merge' '
git rev-parse merge^..merge >expect &&
git rev-parse merge^- >actual &&
test_cmp expect actual
'
test_expect_success 'rev-parse merge^-1 = merge^..merge' '
git rev-parse merge^1..merge >expect &&
git rev-parse merge^-1 >actual &&
test_cmp expect actual
'
test_expect_success 'rev-parse merge^-2 = merge^2..merge' '
git rev-parse merge^2..merge >expect &&
git rev-parse merge^-2 >actual &&
test_cmp expect actual
'
test_expect_success 'symbolic merge^-1 = merge^1..merge' '
git rev-parse --symbolic merge^1..merge >expect &&
git rev-parse --symbolic merge^-1 >actual &&
test_cmp expect actual
'
test_expect_success 'rev-parse merge^-0 (invalid parent)' '
test_must_fail git rev-parse merge^-0
'
test_expect_success 'rev-parse merge^-3 (invalid parent)' '
test_must_fail git rev-parse merge^-3
'
test_expect_success 'rev-parse merge^-^ (garbage after ^-)' '
test_must_fail git rev-parse merge^-^
'
test_expect_success 'rev-parse merge^-1x (garbage after ^-1)' '
test_must_fail git rev-parse merge^-1x
'
# All rev^- rev-list tests (should be mostly the same as rev-parse; the reason
# for the duplication is that rev-parse and rev-list use different parsers).
test_expect_success 'rev-list merge^- = merge^..merge' '
git rev-list merge^..merge >expect &&
git rev-list merge^- >actual &&
test_cmp expect actual
'
test_expect_success 'rev-list merge^-1 = merge^1..merge' '
git rev-list merge^1..merge >expect &&
git rev-list merge^-1 >actual &&
test_cmp expect actual
'
test_expect_success 'rev-list merge^-2 = merge^2..merge' '
git rev-list merge^2..merge >expect &&
git rev-list merge^-2 >actual &&
test_cmp expect actual
'
test_expect_success 'rev-list merge^-0 (invalid parent)' '
test_must_fail git rev-list merge^-0
'
test_expect_success 'rev-list merge^-3 (invalid parent)' '
test_must_fail git rev-list merge^-3
'
test_expect_success 'rev-list merge^-^ (garbage after ^-)' '
test_must_fail git rev-list merge^-^
'
test_expect_success 'rev-list merge^-1x (garbage after ^-1)' '
test_must_fail git rev-list merge^-1x
'
test_expect_success 'rev-parse $garbage^@ does not segfault' '
test_must_fail git rev-parse $EMPTY_TREE^@
'
test_expect_success 'rev-parse $garbage...$garbage does not segfault' '
test_must_fail git rev-parse $EMPTY_TREE...$EMPTY_BLOB
'
test_done
|