Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t5317-pack-objects-filter-objects.sh
blob79552d6ef7f69751b8cfa1bd71edfda47973257b
1 #!/bin/sh
3 test_description='git pack-objects using object filtering'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 # Test blob:none filter.
13 test_expect_success 'setup r1' '
14 git init r1 &&
15 for n in 1 2 3 4 5
17 echo "This is file: $n" > r1/file.$n &&
18 git -C r1 add file.$n &&
19 git -C r1 commit -m "$n" || return 1
20 done
23 parse_verify_pack_blob_oid () {
24 awk '{print $1}' -
27 test_expect_success 'verify blob count in normal packfile' '
28 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
29 >ls_files_result &&
30 test_parse_ls_files_stage_oids <ls_files_result |
31 sort >expected &&
33 git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
34 HEAD
35 EOF
36 git -C r1 index-pack ../all.pack &&
38 git -C r1 verify-pack -v ../all.pack >verify_result &&
39 grep blob verify_result |
40 parse_verify_pack_blob_oid |
41 sort >observed &&
43 test_cmp expected observed
46 test_expect_success 'verify blob:none packfile has no blobs' '
47 git -C r1 pack-objects --revs --stdout --filter=blob:none >filter.pack <<-EOF &&
48 HEAD
49 EOF
50 git -C r1 index-pack ../filter.pack &&
52 git -C r1 verify-pack -v ../filter.pack >verify_result &&
53 ! grep blob verify_result
56 test_expect_success 'verify blob:none packfile without --stdout' '
57 git -C r1 pack-objects --revs --filter=blob:none mypackname >packhash <<-EOF &&
58 HEAD
59 EOF
60 git -C r1 verify-pack -v "mypackname-$(cat packhash).pack" >verify_result &&
61 ! grep blob verify_result
64 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
65 git -C r1 verify-pack -v ../all.pack >verify_result &&
66 grep -E "commit|tree" verify_result |
67 parse_verify_pack_blob_oid |
68 sort >expected &&
70 git -C r1 verify-pack -v ../filter.pack >verify_result &&
71 grep -E "commit|tree" verify_result |
72 parse_verify_pack_blob_oid |
73 sort >observed &&
75 test_cmp expected observed
78 test_expect_success 'get an error for missing tree object' '
79 git init r5 &&
80 echo foo >r5/foo &&
81 git -C r5 add foo &&
82 git -C r5 commit -m "foo" &&
83 git -C r5 rev-parse HEAD^{tree} >tree &&
84 del=$(sed "s|..|&/|" tree) &&
85 rm r5/.git/objects/$del &&
86 test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
87 HEAD
88 EOF
89 grep "bad tree object" bad_tree
92 test_expect_success 'setup for tests of tree:0' '
93 mkdir r1/subtree &&
94 echo "This is a file in a subtree" >r1/subtree/file &&
95 git -C r1 add subtree/file &&
96 git -C r1 commit -m subtree
99 test_expect_success 'verify tree:0 packfile has no blobs or trees' '
100 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
101 HEAD
103 git -C r1 index-pack ../commitsonly.pack &&
104 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
105 ! grep -E "tree|blob" objs
108 test_expect_success 'grab tree directly when using tree:0' '
109 # We should get the tree specified directly but not its blobs or subtrees.
110 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
111 HEAD:
113 git -C r1 index-pack ../commitsonly.pack &&
114 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
115 awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
116 git -C r1 rev-parse HEAD: >expected &&
117 test_cmp expected trees_and_blobs
120 # Test blob:limit=<n>[kmg] filter.
121 # We boundary test around the size parameter. The filter is strictly less than
122 # the value, so size 500 and 1000 should have the same results, but 1001 should
123 # filter more.
125 test_expect_success 'setup r2' '
126 git init r2 &&
127 for n in 1000 10000
129 printf "%"$n"s" X > r2/large.$n &&
130 git -C r2 add large.$n &&
131 git -C r2 commit -m "$n" || return 1
132 done
135 test_expect_success 'verify blob count in normal packfile' '
136 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
137 test_parse_ls_files_stage_oids <ls_files_result |
138 sort >expected &&
140 git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
141 HEAD
143 git -C r2 index-pack ../all.pack &&
145 git -C r2 verify-pack -v ../all.pack >verify_result &&
146 grep blob verify_result |
147 parse_verify_pack_blob_oid |
148 sort >observed &&
150 test_cmp expected observed
153 test_expect_success 'verify blob:limit=500 omits all blobs' '
154 git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
155 HEAD
157 git -C r2 index-pack ../filter.pack &&
159 git -C r2 verify-pack -v ../filter.pack >verify_result &&
160 ! grep blob verify_result
163 test_expect_success 'verify blob:limit=1000' '
164 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
165 HEAD
167 git -C r2 index-pack ../filter.pack &&
169 git -C r2 verify-pack -v ../filter.pack >verify_result &&
170 ! grep blob verify_result
173 test_expect_success 'verify blob:limit=1001' '
174 git -C r2 ls-files -s large.1000 >ls_files_result &&
175 test_parse_ls_files_stage_oids <ls_files_result |
176 sort >expected &&
178 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
179 HEAD
181 git -C r2 index-pack ../filter.pack &&
183 git -C r2 verify-pack -v ../filter.pack >verify_result &&
184 grep blob verify_result |
185 parse_verify_pack_blob_oid |
186 sort >observed &&
188 test_cmp expected observed
191 test_expect_success 'verify blob:limit=10001' '
192 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
193 test_parse_ls_files_stage_oids <ls_files_result |
194 sort >expected &&
196 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
197 HEAD
199 git -C r2 index-pack ../filter.pack &&
201 git -C r2 verify-pack -v ../filter.pack >verify_result &&
202 grep blob verify_result |
203 parse_verify_pack_blob_oid |
204 sort >observed &&
206 test_cmp expected observed
209 test_expect_success 'verify blob:limit=1k' '
210 git -C r2 ls-files -s large.1000 >ls_files_result &&
211 test_parse_ls_files_stage_oids <ls_files_result |
212 sort >expected &&
214 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
215 HEAD
217 git -C r2 index-pack ../filter.pack &&
219 git -C r2 verify-pack -v ../filter.pack >verify_result &&
220 grep blob verify_result |
221 parse_verify_pack_blob_oid |
222 sort >observed &&
224 test_cmp expected observed
227 test_expect_success 'verify explicitly specifying oversized blob in input' '
228 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
229 test_parse_ls_files_stage_oids <ls_files_result |
230 sort >expected &&
232 echo HEAD >objects &&
233 git -C r2 rev-parse HEAD:large.10000 >>objects &&
234 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
235 git -C r2 index-pack ../filter.pack &&
237 git -C r2 verify-pack -v ../filter.pack >verify_result &&
238 grep blob verify_result |
239 parse_verify_pack_blob_oid |
240 sort >observed &&
242 test_cmp expected observed
245 test_expect_success 'verify blob:limit=1m' '
246 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
247 test_parse_ls_files_stage_oids <ls_files_result |
248 sort >expected &&
250 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
251 HEAD
253 git -C r2 index-pack ../filter.pack &&
255 git -C r2 verify-pack -v ../filter.pack >verify_result &&
256 grep blob verify_result |
257 parse_verify_pack_blob_oid |
258 sort >observed &&
260 test_cmp expected observed
263 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
264 git -C r2 verify-pack -v ../all.pack >verify_result &&
265 grep -E "commit|tree" verify_result |
266 parse_verify_pack_blob_oid |
267 sort >expected &&
269 git -C r2 verify-pack -v ../filter.pack >verify_result &&
270 grep -E "commit|tree" verify_result |
271 parse_verify_pack_blob_oid |
272 sort >observed &&
274 test_cmp expected observed
277 test_expect_success 'verify small limit and big limit results in small limit' '
278 git -C r2 ls-files -s large.1000 >ls_files_result &&
279 test_parse_ls_files_stage_oids <ls_files_result |
280 sort >expected &&
282 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 \
283 --filter=blob:limit=10001 >filter.pack <<-EOF &&
284 HEAD
286 git -C r2 index-pack ../filter.pack &&
288 git -C r2 verify-pack -v ../filter.pack >verify_result &&
289 grep blob verify_result |
290 parse_verify_pack_blob_oid |
291 sort >observed &&
293 test_cmp expected observed
296 test_expect_success 'verify big limit and small limit results in small limit' '
297 git -C r2 ls-files -s large.1000 >ls_files_result &&
298 test_parse_ls_files_stage_oids <ls_files_result |
299 sort >expected &&
301 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 \
302 --filter=blob:limit=1001 >filter.pack <<-EOF &&
303 HEAD
305 git -C r2 index-pack ../filter.pack &&
307 git -C r2 verify-pack -v ../filter.pack >verify_result &&
308 grep blob verify_result |
309 parse_verify_pack_blob_oid |
310 sort >observed &&
312 test_cmp expected observed
315 # Test sparse:path=<path> filter.
316 # !!!!
317 # NOTE: sparse:path filter support has been dropped for security reasons,
318 # so the tests have been changed to make sure that using it fails.
319 # !!!!
320 # Use a local file containing a sparse-checkout specification to filter
321 # out blobs not required for the corresponding sparse-checkout. We do not
322 # require sparse-checkout to actually be enabled.
324 test_expect_success 'setup r3' '
325 git init r3 &&
326 mkdir r3/dir1 &&
327 for n in sparse1 sparse2
329 echo "This is file: $n" > r3/$n &&
330 git -C r3 add $n &&
331 echo "This is file: dir1/$n" > r3/dir1/$n &&
332 git -C r3 add dir1/$n || return 1
333 done &&
334 git -C r3 commit -m "sparse" &&
335 echo dir1/ >pattern1 &&
336 echo sparse1 >pattern2
339 test_expect_success 'verify blob count in normal packfile' '
340 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
341 >ls_files_result &&
342 test_parse_ls_files_stage_oids <ls_files_result |
343 sort >expected &&
345 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
346 HEAD
348 git -C r3 index-pack ../all.pack &&
350 git -C r3 verify-pack -v ../all.pack >verify_result &&
351 grep blob verify_result |
352 parse_verify_pack_blob_oid |
353 sort >observed &&
355 test_cmp expected observed
358 test_expect_success 'verify sparse:path=pattern1 fails' '
359 test_must_fail git -C r3 pack-objects --revs --stdout \
360 --filter=sparse:path=../pattern1 <<-EOF
361 HEAD
365 test_expect_success 'verify sparse:path=pattern2 fails' '
366 test_must_fail git -C r3 pack-objects --revs --stdout \
367 --filter=sparse:path=../pattern2 <<-EOF
368 HEAD
372 # Test sparse:oid=<oid-ish> filter.
373 # Use a blob containing a sparse-checkout specification to filter
374 # out blobs not required for the corresponding sparse-checkout. We do not
375 # require sparse-checkout to actually be enabled.
377 test_expect_success 'setup r4' '
378 git init r4 &&
379 mkdir r4/dir1 &&
380 for n in sparse1 sparse2
382 echo "This is file: $n" > r4/$n &&
383 git -C r4 add $n &&
384 echo "This is file: dir1/$n" > r4/dir1/$n &&
385 git -C r4 add dir1/$n || return 1
386 done &&
387 echo dir1/ >r4/pattern &&
388 git -C r4 add pattern &&
389 git -C r4 commit -m "pattern"
392 test_expect_success 'verify blob count in normal packfile' '
393 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
394 >ls_files_result &&
395 test_parse_ls_files_stage_oids <ls_files_result |
396 sort >expected &&
398 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
399 HEAD
401 git -C r4 index-pack ../all.pack &&
403 git -C r4 verify-pack -v ../all.pack >verify_result &&
404 grep blob verify_result |
405 parse_verify_pack_blob_oid |
406 sort >observed &&
408 test_cmp expected observed
411 test_expect_success 'verify sparse:oid=OID' '
412 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
413 test_parse_ls_files_stage_oids <ls_files_result |
414 sort >expected &&
416 git -C r4 ls-files -s pattern >staged &&
417 oid=$(test_parse_ls_files_stage_oids <staged) &&
418 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
419 HEAD
421 git -C r4 index-pack ../filter.pack &&
423 git -C r4 verify-pack -v ../filter.pack >verify_result &&
424 grep blob verify_result |
425 parse_verify_pack_blob_oid |
426 sort >observed &&
428 test_cmp expected observed
431 test_expect_success 'verify sparse:oid=oid-ish' '
432 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
433 test_parse_ls_files_stage_oids <ls_files_result |
434 sort >expected &&
436 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=main:pattern >filter.pack <<-EOF &&
437 HEAD
439 git -C r4 index-pack ../filter.pack &&
441 git -C r4 verify-pack -v ../filter.pack >verify_result &&
442 grep blob verify_result |
443 parse_verify_pack_blob_oid |
444 sort >observed &&
446 test_cmp expected observed
449 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
450 # This models previously omitted objects that we did not receive.
452 test_expect_success 'setup r1 - delete loose blobs' '
453 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
454 >ls_files_result &&
455 test_parse_ls_files_stage_oids <ls_files_result |
456 sort >expected &&
458 for id in `sed "s|..|&/|" expected`
460 rm r1/.git/objects/$id || return 1
461 done
464 test_expect_success 'verify pack-objects fails w/ missing objects' '
465 test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
466 HEAD
470 test_expect_success 'verify pack-objects fails w/ --missing=error' '
471 test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
472 HEAD
476 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
477 git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF
478 HEAD
482 test_done