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 --rev --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 --rev --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 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
75 test_expect_success 'setup r2' '
79 printf "%"$n"s" X > r2/large.$n
80 git -C r2 add large.$n
81 git -C r2 commit -m "$n"
85 test_expect_success 'verify blob count in normal packfile' '
86 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
87 awk -f print_2.awk ls_files_result |
90 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
93 git -C r2 index-pack ../all.pack &&
95 git -C r2 verify-pack -v ../all.pack >verify_result &&
96 grep blob verify_result |
100 test_cmp expected observed
103 test_expect_success 'verify blob:limit=500 omits all blobs' '
104 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
107 git -C r2 index-pack ../filter.pack &&
109 git -C r2 verify-pack -v ../filter.pack >verify_result &&
110 grep blob verify_result |
114 nr=$(wc -l <observed) &&
118 test_expect_success 'verify blob:limit=1000' '
119 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
122 git -C r2 index-pack ../filter.pack &&
124 git -C r2 verify-pack -v ../filter.pack >verify_result &&
125 grep blob verify_result |
129 nr=$(wc -l <observed) &&
133 test_expect_success 'verify blob:limit=1001' '
134 git -C r2 ls-files -s large.1000 >ls_files_result &&
135 awk -f print_2.awk ls_files_result |
138 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
141 git -C r2 index-pack ../filter.pack &&
143 git -C r2 verify-pack -v ../filter.pack >verify_result &&
144 grep blob verify_result |
148 test_cmp expected observed
151 test_expect_success 'verify blob:limit=10001' '
152 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
153 awk -f print_2.awk ls_files_result |
156 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
159 git -C r2 index-pack ../filter.pack &&
161 git -C r2 verify-pack -v ../filter.pack >verify_result &&
162 grep blob verify_result |
166 test_cmp expected observed
169 test_expect_success 'verify blob:limit=1k' '
170 git -C r2 ls-files -s large.1000 >ls_files_result &&
171 awk -f print_2.awk ls_files_result |
174 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
177 git -C r2 index-pack ../filter.pack &&
179 git -C r2 verify-pack -v ../filter.pack >verify_result &&
180 grep blob verify_result |
184 test_cmp expected observed
187 test_expect_success 'verify explicitly specifying oversized blob in input' '
188 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
189 awk -f print_2.awk ls_files_result |
192 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
194 $(git -C r2 rev-parse HEAD:large.10000)
196 git -C r2 index-pack ../filter.pack &&
198 git -C r2 verify-pack -v ../filter.pack >verify_result &&
199 grep blob verify_result |
203 test_cmp expected observed
206 test_expect_success 'verify blob:limit=1m' '
207 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
208 awk -f print_2.awk ls_files_result |
211 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
214 git -C r2 index-pack ../filter.pack &&
216 git -C r2 verify-pack -v ../filter.pack >verify_result &&
217 grep blob verify_result |
221 test_cmp expected observed
224 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
225 git -C r2 verify-pack -v ../all.pack >verify_result &&
226 grep -E "commit|tree" verify_result |
230 git -C r2 verify-pack -v ../filter.pack >verify_result &&
231 grep -E "commit|tree" verify_result |
235 test_cmp expected observed
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.
243 test_expect_success 'setup r3' '
246 for n in sparse1 sparse2
248 echo "This is file: $n" > r3/$n
250 echo "This is file: dir1/$n" > r3/dir1/$n
251 git -C r3 add dir1/$n
253 git -C r3 commit -m "sparse" &&
254 echo dir1/ >pattern1 &&
255 echo sparse1 >pattern2
258 test_expect_success 'verify blob count in normal packfile' '
259 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
261 awk -f print_2.awk ls_files_result |
264 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
267 git -C r3 index-pack ../all.pack &&
269 git -C r3 verify-pack -v ../all.pack >verify_result &&
270 grep blob verify_result |
274 test_cmp expected observed
277 test_expect_success 'verify sparse:path=pattern1' '
278 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
279 awk -f print_2.awk ls_files_result |
282 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
285 git -C r3 index-pack ../filter.pack &&
287 git -C r3 verify-pack -v ../filter.pack >verify_result &&
288 grep blob verify_result |
292 test_cmp expected observed
295 test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
296 git -C r3 verify-pack -v ../all.pack >verify_result &&
297 grep -E "commit|tree" verify_result |
301 git -C r3 verify-pack -v ../filter.pack >verify_result &&
302 grep -E "commit|tree" verify_result |
306 test_cmp expected observed
309 test_expect_success 'verify sparse:path=pattern2' '
310 git -C r3 ls-files -s sparse1 dir1/sparse1 >ls_files_result &&
311 awk -f print_2.awk ls_files_result |
314 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
317 git -C r3 index-pack ../filter.pack &&
319 git -C r3 verify-pack -v ../filter.pack >verify_result &&
320 grep blob verify_result |
324 test_cmp expected observed
327 test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
328 git -C r3 verify-pack -v ../all.pack >verify_result &&
329 grep -E "commit|tree" verify_result |
333 git -C r3 verify-pack -v ../filter.pack >verify_result &&
334 grep -E "commit|tree" verify_result |
338 test_cmp expected observed
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.
345 test_expect_success 'setup r4' '
348 for n in sparse1 sparse2
350 echo "This is file: $n" > r4/$n
352 echo "This is file: dir1/$n" > r4/dir1/$n
353 git -C r4 add dir1/$n
355 echo dir1/ >r4/pattern &&
356 git -C r4 add pattern &&
357 git -C r4 commit -m "pattern"
360 test_expect_success 'verify blob count in normal packfile' '
361 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
363 awk -f print_2.awk ls_files_result |
366 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
369 git -C r4 index-pack ../all.pack &&
371 git -C r4 verify-pack -v ../all.pack >verify_result &&
372 grep blob verify_result |
376 test_cmp expected observed
379 test_expect_success 'verify sparse:oid=OID' '
380 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
381 awk -f print_2.awk ls_files_result |
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 &&
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 test_expect_success 'verify sparse:oid=oid-ish' '
399 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
400 awk -f print_2.awk ls_files_result |
403 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
406 git -C r4 index-pack ../filter.pack &&
408 git -C r4 verify-pack -v ../filter.pack >verify_result &&
409 grep blob verify_result |
413 test_cmp expected observed
416 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
417 # This models previously omitted objects that we did not receive.
419 test_expect_success 'setup r1 - delete loose blobs' '
420 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
422 awk -f print_2.awk ls_files_result |
425 for id in `cat expected | sed "s|..|&/|"`
427 rm r1/.git/objects/$id
431 test_expect_success 'verify pack-objects fails w/ missing objects' '
432 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
437 test_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
443 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
444 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF