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
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 |
57 git -C r1 verify-pack -v ../filter.pack >verify_result &&
58 grep -E "commit|tree" verify_result |
62 test_cmp expected observed
65 test_expect_success
'get an error for missing tree object' '
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 &&
76 grep "bad tree object" bad_tree
79 test_expect_success
'setup for tests of tree:0' '
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 &&
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 &&
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
112 test_expect_success
'setup r2' '
116 printf "%"$n"s" X > r2/large.$n
117 git -C r2 add large.$n
118 git -C r2 commit -m "$n"
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 |
127 git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
130 git -C r2 index-pack ../all.pack &&
132 git -C r2 verify-pack -v ../all.pack >verify_result &&
133 grep blob verify_result |
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 &&
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 &&
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 |
165 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
168 git -C r2 index-pack ../filter.pack &&
170 git -C r2 verify-pack -v ../filter.pack >verify_result &&
171 grep blob verify_result |
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 |
183 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
186 git -C r2 index-pack ../filter.pack &&
188 git -C r2 verify-pack -v ../filter.pack >verify_result &&
189 grep blob verify_result |
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 |
201 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
204 git -C r2 index-pack ../filter.pack &&
206 git -C r2 verify-pack -v ../filter.pack >verify_result &&
207 grep blob verify_result |
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 |
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 |
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 |
237 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
240 git -C r2 index-pack ../filter.pack &&
242 git -C r2 verify-pack -v ../filter.pack >verify_result &&
243 grep blob verify_result |
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 |
256 git -C r2 verify-pack -v ../filter.pack >verify_result &&
257 grep -E "commit|tree" verify_result |
261 test_cmp expected observed
264 # Test sparse:path=<path> filter.
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.
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' '
276 for n in sparse1 sparse2
278 echo "This is file: $n" > r3/$n
280 echo "This is file: dir1/$n" > r3/dir1/$n
281 git -C r3 add dir1/$n
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 \
291 awk -f print_2.awk ls_files_result |
294 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
297 git -C r3 index-pack ../all.pack &&
299 git -C r3 verify-pack -v ../all.pack >verify_result &&
300 grep blob verify_result |
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
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
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' '
329 for n in sparse1 sparse2
331 echo "This is file: $n" > r4/$n
333 echo "This is file: dir1/$n" > r4/dir1/$n
334 git -C r4 add dir1/$n
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 \
344 awk -f print_2.awk ls_files_result |
347 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
350 git -C r4 index-pack ../all.pack &&
352 git -C r4 verify-pack -v ../all.pack >verify_result &&
353 grep blob verify_result |
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 |
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 &&
370 git -C r4 index-pack ../filter.pack &&
372 git -C r4 verify-pack -v ../filter.pack >verify_result &&
373 grep blob verify_result |
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 |
385 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
388 git -C r4 index-pack ../filter.pack &&
390 git -C r4 verify-pack -v ../filter.pack >verify_result &&
391 grep blob verify_result |
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 \
404 awk -f print_2.awk ls_files_result |
407 for id in `cat expected | sed "s|..|&/|"`
409 rm r1/.git/objects/$id
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
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
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