3 test_description='git pack-objects using object filtering'
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 &&
16 echo "This is file: $n" > r1/file.$n
18 git -C r1 commit -m "$n"
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 \
25 awk -f print_2.awk ls_files_result |
28 git -C r1 pack-objects --revs --stdout >all.pack <<-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 |
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 &&
45 git -C r1 index-pack ../filter.pack &&
47 git -C r1 verify-pack -v ../filter.pack >verify_result &&
48 grep blob verify_result |
52 nr=$(wc -l <observed) &&
56 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
57 git -C r1 verify-pack -v ../all.pack >verify_result &&
58 grep -E "commit|tree" verify_result |
62 git -C r1 verify-pack -v ../filter.pack >verify_result &&
63 grep -E "commit|tree" verify_result |
67 test_cmp expected observed
70 test_expect_success 'get an error for missing tree object' '
74 git -C r5 commit -m "foo" &&
75 del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
76 rm r5/.git/objects/$del &&
77 test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
80 grep "bad tree object" bad_tree
83 test_expect_success 'setup for tests of tree:0' '
85 echo "This is a file in a subtree" >r1/subtree/file &&
86 git -C r1 add subtree/file &&
87 git -C r1 commit -m subtree
90 test_expect_success 'verify tree:0 packfile has no blobs or trees' '
91 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
94 git -C r1 index-pack ../commitsonly.pack &&
95 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
96 ! grep -E "tree|blob" objs
99 test_expect_success 'grab tree directly when using tree:0' '
100 # We should get the tree specified directly but not its blobs or subtrees.
101 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
104 git -C r1 index-pack ../commitsonly.pack &&
105 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
106 awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
107 git -C r1 rev-parse HEAD: >expected &&
108 test_cmp expected trees_and_blobs
111 # Test blob:limit=<n>[kmg] filter.
112 # We boundary test around the size parameter. The filter is strictly less than
113 # the value, so size 500 and 1000 should have the same results, but 1001 should
116 test_expect_success 'setup r2' '
120 printf "%"$n"s" X > r2/large.$n
121 git -C r2 add large.$n
122 git -C r2 commit -m "$n"
126 test_expect_success 'verify blob count in normal packfile' '
127 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
128 awk -f print_2.awk ls_files_result |
131 git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
134 git -C r2 index-pack ../all.pack &&
136 git -C r2 verify-pack -v ../all.pack >verify_result &&
137 grep blob verify_result |
141 test_cmp expected observed
144 test_expect_success 'verify blob:limit=500 omits all blobs' '
145 git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
148 git -C r2 index-pack ../filter.pack &&
150 git -C r2 verify-pack -v ../filter.pack >verify_result &&
151 grep blob verify_result |
155 nr=$(wc -l <observed) &&
159 test_expect_success 'verify blob:limit=1000' '
160 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
163 git -C r2 index-pack ../filter.pack &&
165 git -C r2 verify-pack -v ../filter.pack >verify_result &&
166 grep blob verify_result |
170 nr=$(wc -l <observed) &&
174 test_expect_success 'verify blob:limit=1001' '
175 git -C r2 ls-files -s large.1000 >ls_files_result &&
176 awk -f print_2.awk ls_files_result |
179 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
182 git -C r2 index-pack ../filter.pack &&
184 git -C r2 verify-pack -v ../filter.pack >verify_result &&
185 grep blob verify_result |
189 test_cmp expected observed
192 test_expect_success 'verify blob:limit=10001' '
193 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
194 awk -f print_2.awk ls_files_result |
197 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
200 git -C r2 index-pack ../filter.pack &&
202 git -C r2 verify-pack -v ../filter.pack >verify_result &&
203 grep blob verify_result |
207 test_cmp expected observed
210 test_expect_success 'verify blob:limit=1k' '
211 git -C r2 ls-files -s large.1000 >ls_files_result &&
212 awk -f print_2.awk ls_files_result |
215 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
218 git -C r2 index-pack ../filter.pack &&
220 git -C r2 verify-pack -v ../filter.pack >verify_result &&
221 grep blob verify_result |
225 test_cmp expected observed
228 test_expect_success 'verify explicitly specifying oversized blob in input' '
229 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
230 awk -f print_2.awk ls_files_result |
233 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
235 $(git -C r2 rev-parse HEAD:large.10000)
237 git -C r2 index-pack ../filter.pack &&
239 git -C r2 verify-pack -v ../filter.pack >verify_result &&
240 grep blob verify_result |
244 test_cmp expected observed
247 test_expect_success 'verify blob:limit=1m' '
248 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
249 awk -f print_2.awk ls_files_result |
252 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
255 git -C r2 index-pack ../filter.pack &&
257 git -C r2 verify-pack -v ../filter.pack >verify_result &&
258 grep blob verify_result |
262 test_cmp expected observed
265 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
266 git -C r2 verify-pack -v ../all.pack >verify_result &&
267 grep -E "commit|tree" verify_result |
271 git -C r2 verify-pack -v ../filter.pack >verify_result &&
272 grep -E "commit|tree" verify_result |
276 test_cmp expected observed
279 # Test sparse:path=<path> filter.
280 # Use a local file containing a sparse-checkout specification to filter
281 # out blobs not required for the corresponding sparse-checkout. We do not
282 # require sparse-checkout to actually be enabled.
284 test_expect_success 'setup r3' '
287 for n in sparse1 sparse2
289 echo "This is file: $n" > r3/$n
291 echo "This is file: dir1/$n" > r3/dir1/$n
292 git -C r3 add dir1/$n
294 git -C r3 commit -m "sparse" &&
295 echo dir1/ >pattern1 &&
296 echo sparse1 >pattern2
299 test_expect_success 'verify blob count in normal packfile' '
300 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
302 awk -f print_2.awk ls_files_result |
305 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
308 git -C r3 index-pack ../all.pack &&
310 git -C r3 verify-pack -v ../all.pack >verify_result &&
311 grep blob verify_result |
315 test_cmp expected observed
318 test_expect_success 'verify sparse:path=pattern1' '
319 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
320 awk -f print_2.awk ls_files_result |
323 git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
326 git -C r3 index-pack ../filter.pack &&
328 git -C r3 verify-pack -v ../filter.pack >verify_result &&
329 grep blob verify_result |
333 test_cmp expected observed
336 test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
337 git -C r3 verify-pack -v ../all.pack >verify_result &&
338 grep -E "commit|tree" verify_result |
342 git -C r3 verify-pack -v ../filter.pack >verify_result &&
343 grep -E "commit|tree" verify_result |
347 test_cmp expected observed
350 test_expect_success 'verify sparse:path=pattern2' '
351 git -C r3 ls-files -s sparse1 dir1/sparse1 >ls_files_result &&
352 awk -f print_2.awk ls_files_result |
355 git -C r3 pack-objects --revs --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
358 git -C r3 index-pack ../filter.pack &&
360 git -C r3 verify-pack -v ../filter.pack >verify_result &&
361 grep blob verify_result |
365 test_cmp expected observed
368 test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
369 git -C r3 verify-pack -v ../all.pack >verify_result &&
370 grep -E "commit|tree" verify_result |
374 git -C r3 verify-pack -v ../filter.pack >verify_result &&
375 grep -E "commit|tree" verify_result |
379 test_cmp expected observed
382 # Test sparse:oid=<oid-ish> filter.
383 # Like sparse:path, but we get the sparse-checkout specification from
384 # a blob rather than a file on disk.
386 test_expect_success 'setup r4' '
389 for n in sparse1 sparse2
391 echo "This is file: $n" > r4/$n
393 echo "This is file: dir1/$n" > r4/dir1/$n
394 git -C r4 add dir1/$n
396 echo dir1/ >r4/pattern &&
397 git -C r4 add pattern &&
398 git -C r4 commit -m "pattern"
401 test_expect_success 'verify blob count in normal packfile' '
402 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
404 awk -f print_2.awk ls_files_result |
407 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
410 git -C r4 index-pack ../all.pack &&
412 git -C r4 verify-pack -v ../all.pack >verify_result &&
413 grep blob verify_result |
417 test_cmp expected observed
420 test_expect_success 'verify sparse:oid=OID' '
421 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
422 awk -f print_2.awk ls_files_result |
425 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
426 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
429 git -C r4 index-pack ../filter.pack &&
431 git -C r4 verify-pack -v ../filter.pack >verify_result &&
432 grep blob verify_result |
436 test_cmp expected observed
439 test_expect_success 'verify sparse:oid=oid-ish' '
440 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
441 awk -f print_2.awk ls_files_result |
444 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
447 git -C r4 index-pack ../filter.pack &&
449 git -C r4 verify-pack -v ../filter.pack >verify_result &&
450 grep blob verify_result |
454 test_cmp expected observed
457 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
458 # This models previously omitted objects that we did not receive.
460 test_expect_success 'setup r1 - delete loose blobs' '
461 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
463 awk -f print_2.awk ls_files_result |
466 for id in `cat expected | sed "s|..|&/|"`
468 rm r1/.git/objects/$id
472 test_expect_success 'verify pack-objects fails w/ missing objects' '
473 test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
478 test_expect_success 'verify pack-objects fails w/ --missing=error' '
479 test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
484 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
485 git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF