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
10 # Test blob:none filter.
12 test_expect_success
'setup r1' '
13 echo "{print \$1}" >print_1.awk &&
14 echo "{print \$2}" >print_2.awk &&
19 echo "This is file: $n" > r1/file.$n
21 git -C r1 commit -m "$n"
25 test_expect_success
'verify blob count in normal packfile' '
26 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
28 awk -f print_2.awk ls_files_result |
31 git -C r1 pack-objects --revs --stdout >all.pack <<-EOF &&
34 git -C r1 index-pack ../all.pack &&
36 git -C r1 verify-pack -v ../all.pack >verify_result &&
37 grep blob verify_result |
41 test_cmp expected observed
44 test_expect_success
'verify blob:none packfile has no blobs' '
45 git -C r1 pack-objects --revs --stdout --filter=blob:none >filter.pack <<-EOF &&
48 git -C r1 index-pack ../filter.pack &&
50 git -C r1 verify-pack -v ../filter.pack >verify_result &&
51 ! grep blob verify_result
54 test_expect_success
'verify normal and blob:none packfiles have same commits/trees' '
55 git -C r1 verify-pack -v ../all.pack >verify_result &&
56 grep -E "commit|tree" verify_result |
60 git -C r1 verify-pack -v ../filter.pack >verify_result &&
61 grep -E "commit|tree" verify_result |
65 test_cmp expected observed
68 test_expect_success
'get an error for missing tree object' '
72 git -C r5 commit -m "foo" &&
73 git -C r5 rev-parse HEAD^{tree} >tree &&
74 del=$(sed "s|..|&/|" tree) &&
75 rm r5/.git/objects/$del &&
76 test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
79 grep "bad tree object" bad_tree
82 test_expect_success
'setup for tests of tree:0' '
84 echo "This is a file in a subtree" >r1/subtree/file &&
85 git -C r1 add subtree/file &&
86 git -C r1 commit -m subtree
89 test_expect_success
'verify tree:0 packfile has no blobs or trees' '
90 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
93 git -C r1 index-pack ../commitsonly.pack &&
94 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
95 ! grep -E "tree|blob" objs
98 test_expect_success
'grab tree directly when using tree:0' '
99 # We should get the tree specified directly but not its blobs or subtrees.
100 git -C r1 pack-objects --revs --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
103 git -C r1 index-pack ../commitsonly.pack &&
104 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
105 awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
106 git -C r1 rev-parse HEAD: >expected &&
107 test_cmp expected trees_and_blobs
110 # Test blob:limit=<n>[kmg] filter.
111 # We boundary test around the size parameter. The filter is strictly less than
112 # the value, so size 500 and 1000 should have the same results, but 1001 should
115 test_expect_success
'setup r2' '
119 printf "%"$n"s" X > r2/large.$n
120 git -C r2 add large.$n
121 git -C r2 commit -m "$n"
125 test_expect_success
'verify blob count in normal packfile' '
126 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
127 awk -f print_2.awk ls_files_result |
130 git -C r2 pack-objects --revs --stdout >all.pack <<-EOF &&
133 git -C r2 index-pack ../all.pack &&
135 git -C r2 verify-pack -v ../all.pack >verify_result &&
136 grep blob verify_result |
140 test_cmp expected observed
143 test_expect_success
'verify blob:limit=500 omits all blobs' '
144 git -C r2 pack-objects --revs --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
147 git -C r2 index-pack ../filter.pack &&
149 git -C r2 verify-pack -v ../filter.pack >verify_result &&
150 ! grep blob verify_result
153 test_expect_success
'verify blob:limit=1000' '
154 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
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=1001' '
164 git -C r2 ls-files -s large.1000 >ls_files_result &&
165 awk -f print_2.awk ls_files_result |
168 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
171 git -C r2 index-pack ../filter.pack &&
173 git -C r2 verify-pack -v ../filter.pack >verify_result &&
174 grep blob verify_result |
178 test_cmp expected observed
181 test_expect_success
'verify blob:limit=10001' '
182 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
183 awk -f print_2.awk ls_files_result |
186 git -C r2 pack-objects --revs --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
189 git -C r2 index-pack ../filter.pack &&
191 git -C r2 verify-pack -v ../filter.pack >verify_result &&
192 grep blob verify_result |
196 test_cmp expected observed
199 test_expect_success
'verify blob:limit=1k' '
200 git -C r2 ls-files -s large.1000 >ls_files_result &&
201 awk -f print_2.awk ls_files_result |
204 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
207 git -C r2 index-pack ../filter.pack &&
209 git -C r2 verify-pack -v ../filter.pack >verify_result &&
210 grep blob verify_result |
214 test_cmp expected observed
217 test_expect_success
'verify explicitly specifying oversized blob in input' '
218 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
219 awk -f print_2.awk ls_files_result |
222 echo HEAD >objects &&
223 git -C r2 rev-parse HEAD:large.10000 >>objects &&
224 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
225 git -C r2 index-pack ../filter.pack &&
227 git -C r2 verify-pack -v ../filter.pack >verify_result &&
228 grep blob verify_result |
232 test_cmp expected observed
235 test_expect_success
'verify blob:limit=1m' '
236 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
237 awk -f print_2.awk ls_files_result |
240 git -C r2 pack-objects --revs --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
243 git -C r2 index-pack ../filter.pack &&
245 git -C r2 verify-pack -v ../filter.pack >verify_result &&
246 grep blob verify_result |
250 test_cmp expected observed
253 test_expect_success
'verify normal and blob:limit packfiles have same commits/trees' '
254 git -C r2 verify-pack -v ../all.pack >verify_result &&
255 grep -E "commit|tree" verify_result |
259 git -C r2 verify-pack -v ../filter.pack >verify_result &&
260 grep -E "commit|tree" verify_result |
264 test_cmp expected observed
267 # Test sparse:path=<path> filter.
269 # NOTE: sparse:path filter support has been dropped for security reasons,
270 # so the tests have been changed to make sure that using it fails.
272 # Use a local file containing a sparse-checkout specification to filter
273 # out blobs not required for the corresponding sparse-checkout. We do not
274 # require sparse-checkout to actually be enabled.
276 test_expect_success
'setup r3' '
279 for n in sparse1 sparse2
281 echo "This is file: $n" > r3/$n
283 echo "This is file: dir1/$n" > r3/dir1/$n
284 git -C r3 add dir1/$n
286 git -C r3 commit -m "sparse" &&
287 echo dir1/ >pattern1 &&
288 echo sparse1 >pattern2
291 test_expect_success
'verify blob count in normal packfile' '
292 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
294 awk -f print_2.awk ls_files_result |
297 git -C r3 pack-objects --revs --stdout >all.pack <<-EOF &&
300 git -C r3 index-pack ../all.pack &&
302 git -C r3 verify-pack -v ../all.pack >verify_result &&
303 grep blob verify_result |
307 test_cmp expected observed
310 test_expect_success
'verify sparse:path=pattern1 fails' '
311 test_must_fail git -C r3 pack-objects --revs --stdout \
312 --filter=sparse:path=../pattern1 <<-EOF
317 test_expect_success
'verify sparse:path=pattern2 fails' '
318 test_must_fail git -C r3 pack-objects --revs --stdout \
319 --filter=sparse:path=../pattern2 <<-EOF
324 # Test sparse:oid=<oid-ish> filter.
325 # Use a blob containing a sparse-checkout specification to filter
326 # out blobs not required for the corresponding sparse-checkout. We do not
327 # require sparse-checkout to actually be enabled.
329 test_expect_success
'setup r4' '
332 for n in sparse1 sparse2
334 echo "This is file: $n" > r4/$n
336 echo "This is file: dir1/$n" > r4/dir1/$n
337 git -C r4 add dir1/$n
339 echo dir1/ >r4/pattern &&
340 git -C r4 add pattern &&
341 git -C r4 commit -m "pattern"
344 test_expect_success
'verify blob count in normal packfile' '
345 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
347 awk -f print_2.awk ls_files_result |
350 git -C r4 pack-objects --revs --stdout >all.pack <<-EOF &&
353 git -C r4 index-pack ../all.pack &&
355 git -C r4 verify-pack -v ../all.pack >verify_result &&
356 grep blob verify_result |
360 test_cmp expected observed
363 test_expect_success
'verify sparse:oid=OID' '
364 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
365 awk -f print_2.awk ls_files_result |
368 git -C r4 ls-files -s pattern >staged &&
369 oid=$(awk -f print_2.awk staged) &&
370 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
373 git -C r4 index-pack ../filter.pack &&
375 git -C r4 verify-pack -v ../filter.pack >verify_result &&
376 grep blob verify_result |
380 test_cmp expected observed
383 test_expect_success
'verify sparse:oid=oid-ish' '
384 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
385 awk -f print_2.awk ls_files_result |
388 git -C r4 pack-objects --revs --stdout --filter=sparse:oid=main:pattern >filter.pack <<-EOF &&
391 git -C r4 index-pack ../filter.pack &&
393 git -C r4 verify-pack -v ../filter.pack >verify_result &&
394 grep blob verify_result |
398 test_cmp expected observed
401 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
402 # This models previously omitted objects that we did not receive.
404 test_expect_success
'setup r1 - delete loose blobs' '
405 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
407 awk -f print_2.awk ls_files_result |
410 for id in `cat expected | sed "s|..|&/|"`
412 rm r1/.git/objects/$id
416 test_expect_success
'verify pack-objects fails w/ missing objects' '
417 test_must_fail git -C r1 pack-objects --revs --stdout >miss.pack <<-EOF
422 test_expect_success
'verify pack-objects fails w/ --missing=error' '
423 test_must_fail git -C r1 pack-objects --revs --stdout --missing=error >miss.pack <<-EOF
428 test_expect_success
'verify pack-objects w/ --missing=allow-any' '
429 git -C r1 pack-objects --revs --stdout --missing=allow-any >miss.pack <<-EOF