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.
281 # NOTE: sparse:path filter support has been dropped for security reasons,
282 # so the tests have been changed to make sure that using it fails.
284 # Use a local file containing a sparse-checkout specification to filter
285 # out blobs not required for the corresponding sparse-checkout. We do not
286 # require sparse-checkout to actually be enabled.
288 test_expect_success 'setup r3' '
291 for n in sparse1 sparse2
293 echo "This is file: $n" > r3/$n
295 echo "This is file: dir1/$n" > r3/dir1/$n
296 git -C r3 add dir1/$n
298 git -C r3 commit -m "sparse" &&
299 echo dir1/ >pattern1 &&
300 echo sparse1 >pattern2
303 test_expect_success 'verify blob count in normal packfile' '
304 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
306 awk -f print_2.awk ls_files_result |
309 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
312 git -C r3 index-pack ../all.pack &&
314 git -C r3 verify-pack -v ../all.pack >verify_result &&
315 grep blob verify_result |
319 test_cmp expected observed
322 test_expect_success 'verify sparse:path=pattern1 fails' '
323 test_must_fail git -C r3 pack-objects --revs --stdout \
324 --filter=sparse:path=../pattern1 <<-EOF
329 test_expect_success 'verify sparse:path=pattern2 fails' '
330 test_must_fail git -C r3 pack-objects --revs --stdout \
331 --filter=sparse:path=../pattern2 <<-EOF
336 # Test sparse:oid=<oid-ish> filter.
337 # Use a blob containing a sparse-checkout specification to filter
338 # out blobs not required for the corresponding sparse-checkout. We do not
339 # require sparse-checkout to actually be enabled.
341 test_expect_success 'setup r4' '
344 for n in sparse1 sparse2
346 echo "This is file: $n" > r4/$n
348 echo "This is file: dir1/$n" > r4/dir1/$n
349 git -C r4 add dir1/$n
351 echo dir1/ >r4/pattern &&
352 git -C r4 add pattern &&
353 git -C r4 commit -m "pattern"
356 test_expect_success 'verify blob count in normal packfile' '
357 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
359 awk -f print_2.awk ls_files_result |
362 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
365 git -C r4 index-pack ../all.pack &&
367 git -C r4 verify-pack -v ../all.pack >verify_result &&
368 grep blob verify_result |
372 test_cmp expected observed
375 test_expect_success 'verify sparse:oid=OID' '
376 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
377 awk -f print_2.awk ls_files_result |
380 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
381 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
384 git -C r4 index-pack ../filter.pack &&
386 git -C r4 verify-pack -v ../filter.pack >verify_result &&
387 grep blob verify_result |
391 test_cmp expected observed
394 test_expect_success 'verify sparse:oid=oid-ish' '
395 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
396 awk -f print_2.awk ls_files_result |
399 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
402 git -C r4 index-pack ../filter.pack &&
404 git -C r4 verify-pack -v ../filter.pack >verify_result &&
405 grep blob verify_result |
409 test_cmp expected observed
412 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
413 # This models previously omitted objects that we did not receive.
415 test_expect_success 'setup r1 - delete loose blobs' '
416 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
418 awk -f print_2.awk ls_files_result |
421 for id in `cat expected | sed "s|..|&/|"`
423 rm r1/.git/objects/$id
427 test_expect_success 'verify pack-objects fails w/ missing objects' '
428 test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
433 test_expect_success 'verify pack-objects fails w/ --missing=error' '
434 test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
439 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
440 git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF