help: move git-diff and git-reset to different groups
[git.git] / t / t5317-pack-objects-filter-objects.sh
blob24541ea137517354a8b738bdef34728b49f2850e
1 #!/bin/sh
3 test_description='git pack-objects using object filtering'
5 . ./test-lib.sh
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 &&
13 git init r1 &&
14 for n in 1 2 3 4 5
16 echo "This is file: $n" > r1/file.$n
17 git -C r1 add file.$n
18 git -C r1 commit -m "$n"
19 done
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 \
24 >ls_files_result &&
25 awk -f print_2.awk ls_files_result |
26 sort >expected &&
28 git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
29 HEAD
30 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 |
35 awk -f print_1.awk |
36 sort >observed &&
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 &&
43 HEAD
44 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 |
49 awk -f print_1.awk |
50 sort >observed &&
52 nr=$(wc -l <observed) &&
53 test 0 -eq $nr
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 |
59 awk -f print_1.awk |
60 sort >expected &&
62 git -C r1 verify-pack -v ../filter.pack >verify_result &&
63 grep -E "commit|tree" verify_result |
64 awk -f print_1.awk |
65 sort >observed &&
67 test_cmp expected observed
70 test_expect_success 'get an error for missing tree object' '
71 git init r5 &&
72 echo foo >r5/foo &&
73 git -C r5 add foo &&
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 --rev --stdout 2>bad_tree <<-EOF &&
78 HEAD
79 EOF
80 grep "bad tree object" bad_tree
83 test_expect_success 'setup for tests of tree:0' '
84 mkdir r1/subtree &&
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 --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
92 HEAD
93 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 --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
102 HEAD:
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
114 # filter more.
116 test_expect_success 'setup r2' '
117 git init r2 &&
118 for n in 1000 10000
120 printf "%"$n"s" X > r2/large.$n
121 git -C r2 add large.$n
122 git -C r2 commit -m "$n"
123 done
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 |
129 sort >expected &&
131 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
132 HEAD
134 git -C r2 index-pack ../all.pack &&
136 git -C r2 verify-pack -v ../all.pack >verify_result &&
137 grep blob verify_result |
138 awk -f print_1.awk |
139 sort >observed &&
141 test_cmp expected observed
144 test_expect_success 'verify blob:limit=500 omits all blobs' '
145 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
146 HEAD
148 git -C r2 index-pack ../filter.pack &&
150 git -C r2 verify-pack -v ../filter.pack >verify_result &&
151 grep blob verify_result |
152 awk -f print_1.awk |
153 sort >observed &&
155 nr=$(wc -l <observed) &&
156 test 0 -eq $nr
159 test_expect_success 'verify blob:limit=1000' '
160 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
161 HEAD
163 git -C r2 index-pack ../filter.pack &&
165 git -C r2 verify-pack -v ../filter.pack >verify_result &&
166 grep blob verify_result |
167 awk -f print_1.awk |
168 sort >observed &&
170 nr=$(wc -l <observed) &&
171 test 0 -eq $nr
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 |
177 sort >expected &&
179 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
180 HEAD
182 git -C r2 index-pack ../filter.pack &&
184 git -C r2 verify-pack -v ../filter.pack >verify_result &&
185 grep blob verify_result |
186 awk -f print_1.awk |
187 sort >observed &&
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 |
195 sort >expected &&
197 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
198 HEAD
200 git -C r2 index-pack ../filter.pack &&
202 git -C r2 verify-pack -v ../filter.pack >verify_result &&
203 grep blob verify_result |
204 awk -f print_1.awk |
205 sort >observed &&
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 |
213 sort >expected &&
215 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
216 HEAD
218 git -C r2 index-pack ../filter.pack &&
220 git -C r2 verify-pack -v ../filter.pack >verify_result &&
221 grep blob verify_result |
222 awk -f print_1.awk |
223 sort >observed &&
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 |
231 sort >expected &&
233 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
234 HEAD
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 |
241 awk -f print_1.awk |
242 sort >observed &&
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 |
250 sort >expected &&
252 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
253 HEAD
255 git -C r2 index-pack ../filter.pack &&
257 git -C r2 verify-pack -v ../filter.pack >verify_result &&
258 grep blob verify_result |
259 awk -f print_1.awk |
260 sort >observed &&
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 |
268 awk -f print_1.awk |
269 sort >expected &&
271 git -C r2 verify-pack -v ../filter.pack >verify_result &&
272 grep -E "commit|tree" verify_result |
273 awk -f print_1.awk |
274 sort >observed &&
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' '
285 git init r3 &&
286 mkdir r3/dir1 &&
287 for n in sparse1 sparse2
289 echo "This is file: $n" > r3/$n
290 git -C r3 add $n
291 echo "This is file: dir1/$n" > r3/dir1/$n
292 git -C r3 add dir1/$n
293 done &&
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 \
301 >ls_files_result &&
302 awk -f print_2.awk ls_files_result |
303 sort >expected &&
305 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
306 HEAD
308 git -C r3 index-pack ../all.pack &&
310 git -C r3 verify-pack -v ../all.pack >verify_result &&
311 grep blob verify_result |
312 awk -f print_1.awk |
313 sort >observed &&
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 |
321 sort >expected &&
323 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
324 HEAD
326 git -C r3 index-pack ../filter.pack &&
328 git -C r3 verify-pack -v ../filter.pack >verify_result &&
329 grep blob verify_result |
330 awk -f print_1.awk |
331 sort >observed &&
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 |
339 awk -f print_1.awk |
340 sort >expected &&
342 git -C r3 verify-pack -v ../filter.pack >verify_result &&
343 grep -E "commit|tree" verify_result |
344 awk -f print_1.awk |
345 sort >observed &&
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 |
353 sort >expected &&
355 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
356 HEAD
358 git -C r3 index-pack ../filter.pack &&
360 git -C r3 verify-pack -v ../filter.pack >verify_result &&
361 grep blob verify_result |
362 awk -f print_1.awk |
363 sort >observed &&
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 |
371 awk -f print_1.awk |
372 sort >expected &&
374 git -C r3 verify-pack -v ../filter.pack >verify_result &&
375 grep -E "commit|tree" verify_result |
376 awk -f print_1.awk |
377 sort >observed &&
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' '
387 git init r4 &&
388 mkdir r4/dir1 &&
389 for n in sparse1 sparse2
391 echo "This is file: $n" > r4/$n
392 git -C r4 add $n
393 echo "This is file: dir1/$n" > r4/dir1/$n
394 git -C r4 add dir1/$n
395 done &&
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 \
403 >ls_files_result &&
404 awk -f print_2.awk ls_files_result |
405 sort >expected &&
407 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
408 HEAD
410 git -C r4 index-pack ../all.pack &&
412 git -C r4 verify-pack -v ../all.pack >verify_result &&
413 grep blob verify_result |
414 awk -f print_1.awk |
415 sort >observed &&
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 |
423 sort >expected &&
425 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
426 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
427 HEAD
429 git -C r4 index-pack ../filter.pack &&
431 git -C r4 verify-pack -v ../filter.pack >verify_result &&
432 grep blob verify_result |
433 awk -f print_1.awk |
434 sort >observed &&
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 |
442 sort >expected &&
444 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
445 HEAD
447 git -C r4 index-pack ../filter.pack &&
449 git -C r4 verify-pack -v ../filter.pack >verify_result &&
450 grep blob verify_result |
451 awk -f print_1.awk |
452 sort >observed &&
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 \
462 >ls_files_result &&
463 awk -f print_2.awk ls_files_result |
464 sort >expected &&
466 for id in `cat expected | sed "s|..|&/|"`
468 rm r1/.git/objects/$id
469 done
472 test_expect_success 'verify pack-objects fails w/ missing objects' '
473 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
474 HEAD
478 test_expect_success 'verify pack-objects fails w/ --missing=error' '
479 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
480 HEAD
484 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
485 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
486 HEAD
490 test_done