tests: don't swallow Git errors upstream of pipes
[git/git.git] / t / t5317-pack-objects-filter-objects.sh
CommitLineData
9535ce73
JH
1#!/bin/sh
2
3test_description='git pack-objects using object filtering'
4
5. ./test-lib.sh
6
7# Test blob:none filter.
8
9test_expect_success 'setup r1' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
12
13 git init r1 &&
14 for n in 1 2 3 4 5
15 do
16 echo "This is file: $n" > r1/file.$n
17 git -C r1 add file.$n
18 git -C r1 commit -m "$n"
19 done
20'
21
22test_expect_success 'verify blob count in normal packfile' '
61de0ff6
MD
23 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
24 >ls_files_result &&
25 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
26 sort >expected &&
27
9535ce73
JH
28 git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
29 HEAD
30 EOF
31 git -C r1 index-pack ../all.pack &&
bdbc17e8 32
61de0ff6
MD
33 git -C r1 verify-pack -v ../all.pack >verify_result &&
34 grep blob verify_result |
bdbc17e8
MD
35 awk -f print_1.awk |
36 sort >observed &&
37
dcbaa0b3 38 test_cmp expected observed
9535ce73
JH
39'
40
41test_expect_success 'verify blob:none packfile has no blobs' '
42 git -C r1 pack-objects --rev --stdout --filter=blob:none >filter.pack <<-EOF &&
43 HEAD
44 EOF
45 git -C r1 index-pack ../filter.pack &&
bdbc17e8 46
61de0ff6
MD
47 git -C r1 verify-pack -v ../filter.pack >verify_result &&
48 grep blob verify_result |
bdbc17e8
MD
49 awk -f print_1.awk |
50 sort >observed &&
51
9535ce73
JH
52 nr=$(wc -l <observed) &&
53 test 0 -eq $nr
54'
55
56test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
61de0ff6
MD
57 git -C r1 verify-pack -v ../all.pack >verify_result &&
58 grep -E "commit|tree" verify_result |
bdbc17e8
MD
59 awk -f print_1.awk |
60 sort >expected &&
61
61de0ff6
MD
62 git -C r1 verify-pack -v ../filter.pack >verify_result &&
63 grep -E "commit|tree" verify_result |
bdbc17e8
MD
64 awk -f print_1.awk |
65 sort >observed &&
66
dcbaa0b3 67 test_cmp expected observed
9535ce73
JH
68'
69
70# Test blob:limit=<n>[kmg] filter.
71# We boundary test around the size parameter. The filter is strictly less than
72# the value, so size 500 and 1000 should have the same results, but 1001 should
73# filter more.
74
75test_expect_success 'setup r2' '
76 git init r2 &&
77 for n in 1000 10000
78 do
79 printf "%"$n"s" X > r2/large.$n
80 git -C r2 add large.$n
81 git -C r2 commit -m "$n"
82 done
83'
84
85test_expect_success 'verify blob count in normal packfile' '
61de0ff6
MD
86 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
87 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
88 sort >expected &&
89
9535ce73
JH
90 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
91 HEAD
92 EOF
93 git -C r2 index-pack ../all.pack &&
bdbc17e8 94
61de0ff6
MD
95 git -C r2 verify-pack -v ../all.pack >verify_result &&
96 grep blob verify_result |
bdbc17e8
MD
97 awk -f print_1.awk |
98 sort >observed &&
99
dcbaa0b3 100 test_cmp expected observed
9535ce73
JH
101'
102
103test_expect_success 'verify blob:limit=500 omits all blobs' '
104 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
105 HEAD
106 EOF
107 git -C r2 index-pack ../filter.pack &&
bdbc17e8 108
61de0ff6
MD
109 git -C r2 verify-pack -v ../filter.pack >verify_result &&
110 grep blob verify_result |
bdbc17e8
MD
111 awk -f print_1.awk |
112 sort >observed &&
113
9535ce73
JH
114 nr=$(wc -l <observed) &&
115 test 0 -eq $nr
116'
117
118test_expect_success 'verify blob:limit=1000' '
119 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
120 HEAD
121 EOF
122 git -C r2 index-pack ../filter.pack &&
bdbc17e8 123
61de0ff6
MD
124 git -C r2 verify-pack -v ../filter.pack >verify_result &&
125 grep blob verify_result |
bdbc17e8
MD
126 awk -f print_1.awk |
127 sort >observed &&
128
9535ce73
JH
129 nr=$(wc -l <observed) &&
130 test 0 -eq $nr
131'
132
133test_expect_success 'verify blob:limit=1001' '
61de0ff6
MD
134 git -C r2 ls-files -s large.1000 >ls_files_result &&
135 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
136 sort >expected &&
137
9535ce73
JH
138 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
139 HEAD
140 EOF
141 git -C r2 index-pack ../filter.pack &&
bdbc17e8 142
61de0ff6
MD
143 git -C r2 verify-pack -v ../filter.pack >verify_result &&
144 grep blob verify_result |
bdbc17e8
MD
145 awk -f print_1.awk |
146 sort >observed &&
147
dcbaa0b3 148 test_cmp expected observed
9535ce73
JH
149'
150
151test_expect_success 'verify blob:limit=10001' '
61de0ff6
MD
152 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
153 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
154 sort >expected &&
155
9535ce73
JH
156 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
157 HEAD
158 EOF
159 git -C r2 index-pack ../filter.pack &&
bdbc17e8 160
61de0ff6
MD
161 git -C r2 verify-pack -v ../filter.pack >verify_result &&
162 grep blob verify_result |
bdbc17e8
MD
163 awk -f print_1.awk |
164 sort >observed &&
165
dcbaa0b3 166 test_cmp expected observed
9535ce73
JH
167'
168
169test_expect_success 'verify blob:limit=1k' '
61de0ff6
MD
170 git -C r2 ls-files -s large.1000 >ls_files_result &&
171 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
172 sort >expected &&
173
9535ce73
JH
174 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
175 HEAD
176 EOF
177 git -C r2 index-pack ../filter.pack &&
bdbc17e8 178
61de0ff6
MD
179 git -C r2 verify-pack -v ../filter.pack >verify_result &&
180 grep blob verify_result |
bdbc17e8
MD
181 awk -f print_1.awk |
182 sort >observed &&
183
dcbaa0b3 184 test_cmp expected observed
a0c9016a
JT
185'
186
187test_expect_success 'verify explicitly specifying oversized blob in input' '
61de0ff6
MD
188 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
189 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
190 sort >expected &&
191
a0c9016a
JT
192 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
193 HEAD
194 $(git -C r2 rev-parse HEAD:large.10000)
195 EOF
196 git -C r2 index-pack ../filter.pack &&
bdbc17e8 197
61de0ff6
MD
198 git -C r2 verify-pack -v ../filter.pack >verify_result &&
199 grep blob verify_result |
bdbc17e8
MD
200 awk -f print_1.awk |
201 sort >observed &&
202
dcbaa0b3 203 test_cmp expected observed
9535ce73
JH
204'
205
206test_expect_success 'verify blob:limit=1m' '
61de0ff6
MD
207 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
208 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
209 sort >expected &&
210
9535ce73
JH
211 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
212 HEAD
213 EOF
214 git -C r2 index-pack ../filter.pack &&
bdbc17e8 215
61de0ff6
MD
216 git -C r2 verify-pack -v ../filter.pack >verify_result &&
217 grep blob verify_result |
bdbc17e8
MD
218 awk -f print_1.awk |
219 sort >observed &&
220
dcbaa0b3 221 test_cmp expected observed
9535ce73
JH
222'
223
224test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
61de0ff6
MD
225 git -C r2 verify-pack -v ../all.pack >verify_result &&
226 grep -E "commit|tree" verify_result |
bdbc17e8
MD
227 awk -f print_1.awk |
228 sort >expected &&
229
61de0ff6
MD
230 git -C r2 verify-pack -v ../filter.pack >verify_result &&
231 grep -E "commit|tree" verify_result |
bdbc17e8
MD
232 awk -f print_1.awk |
233 sort >observed &&
234
dcbaa0b3 235 test_cmp expected observed
9535ce73
JH
236'
237
238# Test sparse:path=<path> filter.
239# Use a local file containing a sparse-checkout specification to filter
240# out blobs not required for the corresponding sparse-checkout. We do not
241# require sparse-checkout to actually be enabled.
242
243test_expect_success 'setup r3' '
244 git init r3 &&
245 mkdir r3/dir1 &&
246 for n in sparse1 sparse2
247 do
248 echo "This is file: $n" > r3/$n
249 git -C r3 add $n
250 echo "This is file: dir1/$n" > r3/dir1/$n
251 git -C r3 add dir1/$n
252 done &&
253 git -C r3 commit -m "sparse" &&
254 echo dir1/ >pattern1 &&
255 echo sparse1 >pattern2
256'
257
258test_expect_success 'verify blob count in normal packfile' '
61de0ff6
MD
259 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
260 >ls_files_result &&
261 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
262 sort >expected &&
263
9535ce73
JH
264 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
265 HEAD
266 EOF
267 git -C r3 index-pack ../all.pack &&
bdbc17e8 268
61de0ff6
MD
269 git -C r3 verify-pack -v ../all.pack >verify_result &&
270 grep blob verify_result |
bdbc17e8
MD
271 awk -f print_1.awk |
272 sort >observed &&
273
dcbaa0b3 274 test_cmp expected observed
9535ce73
JH
275'
276
277test_expect_success 'verify sparse:path=pattern1' '
61de0ff6
MD
278 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
279 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
280 sort >expected &&
281
9535ce73
JH
282 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
283 HEAD
284 EOF
285 git -C r3 index-pack ../filter.pack &&
bdbc17e8 286
61de0ff6
MD
287 git -C r3 verify-pack -v ../filter.pack >verify_result &&
288 grep blob verify_result |
bdbc17e8
MD
289 awk -f print_1.awk |
290 sort >observed &&
291
dcbaa0b3 292 test_cmp expected observed
9535ce73
JH
293'
294
295test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
61de0ff6
MD
296 git -C r3 verify-pack -v ../all.pack >verify_result &&
297 grep -E "commit|tree" verify_result |
bdbc17e8
MD
298 awk -f print_1.awk |
299 sort >expected &&
300
61de0ff6
MD
301 git -C r3 verify-pack -v ../filter.pack >verify_result &&
302 grep -E "commit|tree" verify_result |
bdbc17e8
MD
303 awk -f print_1.awk |
304 sort >observed &&
305
dcbaa0b3 306 test_cmp expected observed
9535ce73
JH
307'
308
309test_expect_success 'verify sparse:path=pattern2' '
61de0ff6
MD
310 git -C r3 ls-files -s sparse1 dir1/sparse1 >ls_files_result &&
311 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
312 sort >expected &&
313
9535ce73
JH
314 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
315 HEAD
316 EOF
317 git -C r3 index-pack ../filter.pack &&
bdbc17e8 318
61de0ff6
MD
319 git -C r3 verify-pack -v ../filter.pack >verify_result &&
320 grep blob verify_result |
bdbc17e8
MD
321 awk -f print_1.awk |
322 sort >observed &&
323
dcbaa0b3 324 test_cmp expected observed
9535ce73
JH
325'
326
327test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
61de0ff6
MD
328 git -C r3 verify-pack -v ../all.pack >verify_result &&
329 grep -E "commit|tree" verify_result |
bdbc17e8
MD
330 awk -f print_1.awk |
331 sort >expected &&
332
61de0ff6
MD
333 git -C r3 verify-pack -v ../filter.pack >verify_result &&
334 grep -E "commit|tree" verify_result |
bdbc17e8
MD
335 awk -f print_1.awk |
336 sort >observed &&
337
dcbaa0b3 338 test_cmp expected observed
9535ce73
JH
339'
340
341# Test sparse:oid=<oid-ish> filter.
342# Like sparse:path, but we get the sparse-checkout specification from
343# a blob rather than a file on disk.
344
345test_expect_success 'setup r4' '
346 git init r4 &&
347 mkdir r4/dir1 &&
348 for n in sparse1 sparse2
349 do
350 echo "This is file: $n" > r4/$n
351 git -C r4 add $n
352 echo "This is file: dir1/$n" > r4/dir1/$n
353 git -C r4 add dir1/$n
354 done &&
355 echo dir1/ >r4/pattern &&
356 git -C r4 add pattern &&
357 git -C r4 commit -m "pattern"
358'
359
360test_expect_success 'verify blob count in normal packfile' '
61de0ff6
MD
361 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
362 >ls_files_result &&
363 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
364 sort >expected &&
365
9535ce73
JH
366 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
367 HEAD
368 EOF
369 git -C r4 index-pack ../all.pack &&
bdbc17e8 370
61de0ff6
MD
371 git -C r4 verify-pack -v ../all.pack >verify_result &&
372 grep blob verify_result |
bdbc17e8
MD
373 awk -f print_1.awk |
374 sort >observed &&
375
dcbaa0b3 376 test_cmp expected observed
9535ce73
JH
377'
378
379test_expect_success 'verify sparse:oid=OID' '
61de0ff6
MD
380 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
381 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
382 sort >expected &&
383
9535ce73
JH
384 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
385 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
386 HEAD
387 EOF
388 git -C r4 index-pack ../filter.pack &&
bdbc17e8 389
61de0ff6
MD
390 git -C r4 verify-pack -v ../filter.pack >verify_result &&
391 grep blob verify_result |
bdbc17e8
MD
392 awk -f print_1.awk |
393 sort >observed &&
394
dcbaa0b3 395 test_cmp expected observed
9535ce73
JH
396'
397
398test_expect_success 'verify sparse:oid=oid-ish' '
61de0ff6
MD
399 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
400 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
401 sort >expected &&
402
9535ce73
JH
403 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
404 HEAD
405 EOF
406 git -C r4 index-pack ../filter.pack &&
bdbc17e8 407
61de0ff6
MD
408 git -C r4 verify-pack -v ../filter.pack >verify_result &&
409 grep blob verify_result |
bdbc17e8
MD
410 awk -f print_1.awk |
411 sort >observed &&
412
dcbaa0b3 413 test_cmp expected observed
9535ce73
JH
414'
415
416# Delete some loose objects and use pack-objects, but WITHOUT any filtering.
417# This models previously omitted objects that we did not receive.
418
419test_expect_success 'setup r1 - delete loose blobs' '
61de0ff6
MD
420 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
421 >ls_files_result &&
422 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
423 sort >expected &&
424
9535ce73
JH
425 for id in `cat expected | sed "s|..|&/|"`
426 do
427 rm r1/.git/objects/$id
428 done
429'
430
431test_expect_success 'verify pack-objects fails w/ missing objects' '
432 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
433 HEAD
434 EOF
435'
436
437test_expect_success 'verify pack-objects fails w/ --missing=error' '
438 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
439 HEAD
440 EOF
441'
442
443test_expect_success 'verify pack-objects w/ --missing=allow-any' '
444 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
445 HEAD
446 EOF
447'
448
449test_done