ci: skip GitHub workflow runs for already-tested commits/trees
[git.git] / t / t5317-pack-objects-filter-objects.sh
blobdc0446574b3fe2bbc40b0a4d749ace8d868713ef
1 #!/bin/sh
3 test_description='git pack-objects using object filtering'
5 . ./test-lib.sh
7 # Test blob:none filter.
9 test_expect_success 'setup r1' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
13 git init r1 &&
14 for n in 1 2 3 4 5
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
22 test_expect_success 'verify blob count in normal packfile' '
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 |
26 sort >expected &&
28 git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
29 HEAD
30 EOF
31 git -C r1 index-pack ../all.pack &&
33 git -C r1 verify-pack -v ../all.pack >verify_result &&
34 grep blob verify_result |
35 awk -f print_1.awk |
36 sort >observed &&
38 test_cmp expected observed
41 test_expect_success 'verify blob:none packfile has no blobs' '
42 git -C r1 pack-objects --revs --stdout --filter=blob:none >filter.pack <<-EOF &&
43 HEAD
44 EOF
45 git -C r1 index-pack ../filter.pack &&
47 git -C r1 verify-pack -v ../filter.pack >verify_result &&
48 ! grep blob verify_result
51 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
52 git -C r1 verify-pack -v ../all.pack >verify_result &&
53 grep -E "commit|tree" verify_result |
54 awk -f print_1.awk |
55 sort >expected &&
57 git -C r1 verify-pack -v ../filter.pack >verify_result &&
58 grep -E "commit|tree" verify_result |
59 awk -f print_1.awk |
60 sort >observed &&
62 test_cmp expected observed
65 test_expect_success 'get an error for missing tree object' '
66 git init r5 &&
67 echo foo >r5/foo &&
68 git -C r5 add foo &&
69 git -C r5 commit -m "foo" &&
70 git -C r5 rev-parse HEAD^{tree} >tree &&
71 del=$(sed "s|..|&/|" tree) &&
72 rm r5/.git/objects/$del &&
73 test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
74 HEAD
75 EOF
76 grep "bad tree object" bad_tree
79 test_expect_success 'setup for tests of tree:0' '
80 mkdir r1/subtree &&
81 echo "This is a file in a subtree" >r1/subtree/file &&
82 git -C r1 add subtree/file &&
83 git -C r1 commit -m subtree
86 test_expect_success 'verify tree:0 packfile has no blobs or trees' '
87 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
88 HEAD
89 EOF
90 git -C r1 index-pack ../commitsonly.pack &&
91 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
92 ! grep -E "tree|blob" objs
95 test_expect_success 'grab tree directly when using tree:0' '
96 # We should get the tree specified directly but not its blobs or subtrees.
97 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
98 HEAD:
99 EOF
100 git -C r1 index-pack ../commitsonly.pack &&
101 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
102 awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
103 git -C r1 rev-parse HEAD: >expected &&
104 test_cmp expected trees_and_blobs
107 # Test blob:limit=<n>[kmg] filter.
108 # We boundary test around the size parameter. The filter is strictly less than
109 # the value, so size 500 and 1000 should have the same results, but 1001 should
110 # filter more.
112 test_expect_success 'setup r2' '
113 git init r2 &&
114 for n in 1000 10000
116 printf "%"$n"s" X > r2/large.$n
117 git -C r2 add large.$n
118 git -C r2 commit -m "$n"
119 done
122 test_expect_success 'verify blob count in normal packfile' '
123 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
124 awk -f print_2.awk ls_files_result |
125 sort >expected &&
127 git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
128 HEAD
130 git -C r2 index-pack ../all.pack &&
132 git -C r2 verify-pack -v ../all.pack >verify_result &&
133 grep blob verify_result |
134 awk -f print_1.awk |
135 sort >observed &&
137 test_cmp expected observed
140 test_expect_success 'verify blob:limit=500 omits all blobs' '
141 git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
142 HEAD
144 git -C r2 index-pack ../filter.pack &&
146 git -C r2 verify-pack -v ../filter.pack >verify_result &&
147 ! grep blob verify_result
150 test_expect_success 'verify blob:limit=1000' '
151 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
152 HEAD
154 git -C r2 index-pack ../filter.pack &&
156 git -C r2 verify-pack -v ../filter.pack >verify_result &&
157 ! grep blob verify_result
160 test_expect_success 'verify blob:limit=1001' '
161 git -C r2 ls-files -s large.1000 >ls_files_result &&
162 awk -f print_2.awk ls_files_result |
163 sort >expected &&
165 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
166 HEAD
168 git -C r2 index-pack ../filter.pack &&
170 git -C r2 verify-pack -v ../filter.pack >verify_result &&
171 grep blob verify_result |
172 awk -f print_1.awk |
173 sort >observed &&
175 test_cmp expected observed
178 test_expect_success 'verify blob:limit=10001' '
179 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
180 awk -f print_2.awk ls_files_result |
181 sort >expected &&
183 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
184 HEAD
186 git -C r2 index-pack ../filter.pack &&
188 git -C r2 verify-pack -v ../filter.pack >verify_result &&
189 grep blob verify_result |
190 awk -f print_1.awk |
191 sort >observed &&
193 test_cmp expected observed
196 test_expect_success 'verify blob:limit=1k' '
197 git -C r2 ls-files -s large.1000 >ls_files_result &&
198 awk -f print_2.awk ls_files_result |
199 sort >expected &&
201 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
202 HEAD
204 git -C r2 index-pack ../filter.pack &&
206 git -C r2 verify-pack -v ../filter.pack >verify_result &&
207 grep blob verify_result |
208 awk -f print_1.awk |
209 sort >observed &&
211 test_cmp expected observed
214 test_expect_success 'verify explicitly specifying oversized blob in input' '
215 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
216 awk -f print_2.awk ls_files_result |
217 sort >expected &&
219 echo HEAD >objects &&
220 git -C r2 rev-parse HEAD:large.10000 >>objects &&
221 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
222 git -C r2 index-pack ../filter.pack &&
224 git -C r2 verify-pack -v ../filter.pack >verify_result &&
225 grep blob verify_result |
226 awk -f print_1.awk |
227 sort >observed &&
229 test_cmp expected observed
232 test_expect_success 'verify blob:limit=1m' '
233 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
234 awk -f print_2.awk ls_files_result |
235 sort >expected &&
237 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
238 HEAD
240 git -C r2 index-pack ../filter.pack &&
242 git -C r2 verify-pack -v ../filter.pack >verify_result &&
243 grep blob verify_result |
244 awk -f print_1.awk |
245 sort >observed &&
247 test_cmp expected observed
250 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
251 git -C r2 verify-pack -v ../all.pack >verify_result &&
252 grep -E "commit|tree" verify_result |
253 awk -f print_1.awk |
254 sort >expected &&
256 git -C r2 verify-pack -v ../filter.pack >verify_result &&
257 grep -E "commit|tree" verify_result |
258 awk -f print_1.awk |
259 sort >observed &&
261 test_cmp expected observed
264 # Test sparse:path=<path> filter.
265 # !!!!
266 # NOTE: sparse:path filter support has been dropped for security reasons,
267 # so the tests have been changed to make sure that using it fails.
268 # !!!!
269 # Use a local file containing a sparse-checkout specification to filter
270 # out blobs not required for the corresponding sparse-checkout. We do not
271 # require sparse-checkout to actually be enabled.
273 test_expect_success 'setup r3' '
274 git init r3 &&
275 mkdir r3/dir1 &&
276 for n in sparse1 sparse2
278 echo "This is file: $n" > r3/$n
279 git -C r3 add $n
280 echo "This is file: dir1/$n" > r3/dir1/$n
281 git -C r3 add dir1/$n
282 done &&
283 git -C r3 commit -m "sparse" &&
284 echo dir1/ >pattern1 &&
285 echo sparse1 >pattern2
288 test_expect_success 'verify blob count in normal packfile' '
289 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
290 >ls_files_result &&
291 awk -f print_2.awk ls_files_result |
292 sort >expected &&
294 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
295 HEAD
297 git -C r3 index-pack ../all.pack &&
299 git -C r3 verify-pack -v ../all.pack >verify_result &&
300 grep blob verify_result |
301 awk -f print_1.awk |
302 sort >observed &&
304 test_cmp expected observed
307 test_expect_success 'verify sparse:path=pattern1 fails' '
308 test_must_fail git -C r3 pack-objects --revs --stdout \
309 --filter=sparse:path=../pattern1 <<-EOF
310 HEAD
314 test_expect_success 'verify sparse:path=pattern2 fails' '
315 test_must_fail git -C r3 pack-objects --revs --stdout \
316 --filter=sparse:path=../pattern2 <<-EOF
317 HEAD
321 # Test sparse:oid=<oid-ish> filter.
322 # Use a blob containing a sparse-checkout specification to filter
323 # out blobs not required for the corresponding sparse-checkout. We do not
324 # require sparse-checkout to actually be enabled.
326 test_expect_success 'setup r4' '
327 git init r4 &&
328 mkdir r4/dir1 &&
329 for n in sparse1 sparse2
331 echo "This is file: $n" > r4/$n
332 git -C r4 add $n
333 echo "This is file: dir1/$n" > r4/dir1/$n
334 git -C r4 add dir1/$n
335 done &&
336 echo dir1/ >r4/pattern &&
337 git -C r4 add pattern &&
338 git -C r4 commit -m "pattern"
341 test_expect_success 'verify blob count in normal packfile' '
342 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
343 >ls_files_result &&
344 awk -f print_2.awk ls_files_result |
345 sort >expected &&
347 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
348 HEAD
350 git -C r4 index-pack ../all.pack &&
352 git -C r4 verify-pack -v ../all.pack >verify_result &&
353 grep blob verify_result |
354 awk -f print_1.awk |
355 sort >observed &&
357 test_cmp expected observed
360 test_expect_success 'verify sparse:oid=OID' '
361 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
362 awk -f print_2.awk ls_files_result |
363 sort >expected &&
365 git -C r4 ls-files -s pattern >staged &&
366 oid=$(awk -f print_2.awk staged) &&
367 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
368 HEAD
370 git -C r4 index-pack ../filter.pack &&
372 git -C r4 verify-pack -v ../filter.pack >verify_result &&
373 grep blob verify_result |
374 awk -f print_1.awk |
375 sort >observed &&
377 test_cmp expected observed
380 test_expect_success 'verify sparse:oid=oid-ish' '
381 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
382 awk -f print_2.awk ls_files_result |
383 sort >expected &&
385 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
386 HEAD
388 git -C r4 index-pack ../filter.pack &&
390 git -C r4 verify-pack -v ../filter.pack >verify_result &&
391 grep blob verify_result |
392 awk -f print_1.awk |
393 sort >observed &&
395 test_cmp expected observed
398 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
399 # This models previously omitted objects that we did not receive.
401 test_expect_success 'setup r1 - delete loose blobs' '
402 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
403 >ls_files_result &&
404 awk -f print_2.awk ls_files_result |
405 sort >expected &&
407 for id in `cat expected | sed "s|..|&/|"`
409 rm r1/.git/objects/$id
410 done
413 test_expect_success 'verify pack-objects fails w/ missing objects' '
414 test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
415 HEAD
419 test_expect_success 'verify pack-objects fails w/ --missing=error' '
420 test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
421 HEAD
425 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
426 git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF
427 HEAD
431 test_done