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 \
24 | awk -f print_2.awk \
26 git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
29 git -C r1 index-pack ../all.pack &&
30 git -C r1 verify-pack -v ../all.pack \
32 | awk -f print_1.awk \
34 test_cmp observed expected
37 test_expect_success 'verify blob:none packfile has no blobs' '
38 git -C r1 pack-objects --rev --stdout --filter=blob:none >filter.pack <<-EOF &&
41 git -C r1 index-pack ../filter.pack &&
42 git -C r1 verify-pack -v ../filter.pack \
44 | awk -f print_1.awk \
46 nr=$(wc -l <observed) &&
50 test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
51 git -C r1 verify-pack -v ../all.pack \
52 | grep -E "commit|tree" \
53 | awk -f print_1.awk \
55 git -C r1 verify-pack -v ../filter.pack \
56 | grep -E "commit|tree" \
57 | awk -f print_1.awk \
59 test_cmp observed expected
62 test_expect_success 'get an error for missing tree object' '
66 git -C r5 commit -m "foo" &&
67 del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") &&
68 rm r5/.git/objects/$del &&
69 test_must_fail git -C r5 pack-objects --rev --stdout 2>bad_tree <<-EOF &&
72 grep -q "bad tree object" bad_tree
75 test_expect_success 'setup for tests of tree:0' '
77 echo "This is a file in a subtree" >r1/subtree/file &&
78 git -C r1 add subtree/file &&
79 git -C r1 commit -m subtree
82 test_expect_success 'verify tree:0 packfile has no blobs or trees' '
83 git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
86 git -C r1 index-pack ../commitsonly.pack &&
87 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
88 ! grep -E "tree|blob" objs
91 test_expect_success 'grab tree directly when using tree:0' '
92 # We should get the tree specified directly but not its blobs or subtrees.
93 git -C r1 pack-objects --rev --stdout --filter=tree:0 >commitsonly.pack <<-EOF &&
96 git -C r1 index-pack ../commitsonly.pack &&
97 git -C r1 verify-pack -v ../commitsonly.pack >objs &&
98 awk "/tree|blob/{print \$1}" objs >trees_and_blobs &&
99 git -C r1 rev-parse HEAD: >expected &&
100 test_cmp expected trees_and_blobs
103 # Test blob:limit=<n>[kmg] filter.
104 # We boundary test around the size parameter. The filter is strictly less than
105 # the value, so size 500 and 1000 should have the same results, but 1001 should
108 test_expect_success 'setup r2' '
112 printf "%"$n"s" X > r2/large.$n
113 git -C r2 add large.$n
114 git -C r2 commit -m "$n"
118 test_expect_success 'verify blob count in normal packfile' '
119 git -C r2 ls-files -s large.1000 large.10000 \
120 | awk -f print_2.awk \
122 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
125 git -C r2 index-pack ../all.pack &&
126 git -C r2 verify-pack -v ../all.pack \
128 | awk -f print_1.awk \
130 test_cmp observed expected
133 test_expect_success 'verify blob:limit=500 omits all blobs' '
134 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
137 git -C r2 index-pack ../filter.pack &&
138 git -C r2 verify-pack -v ../filter.pack \
140 | awk -f print_1.awk \
142 nr=$(wc -l <observed) &&
146 test_expect_success 'verify blob:limit=1000' '
147 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
150 git -C r2 index-pack ../filter.pack &&
151 git -C r2 verify-pack -v ../filter.pack \
153 | awk -f print_1.awk \
155 nr=$(wc -l <observed) &&
159 test_expect_success 'verify blob:limit=1001' '
160 git -C r2 ls-files -s large.1000 \
161 | awk -f print_2.awk \
163 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
166 git -C r2 index-pack ../filter.pack &&
167 git -C r2 verify-pack -v ../filter.pack \
169 | awk -f print_1.awk \
171 test_cmp observed expected
174 test_expect_success 'verify blob:limit=10001' '
175 git -C r2 ls-files -s large.1000 large.10000 \
176 | awk -f print_2.awk \
178 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
181 git -C r2 index-pack ../filter.pack &&
182 git -C r2 verify-pack -v ../filter.pack \
184 | awk -f print_1.awk \
186 test_cmp observed expected
189 test_expect_success 'verify blob:limit=1k' '
190 git -C r2 ls-files -s large.1000 \
191 | awk -f print_2.awk \
193 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
196 git -C r2 index-pack ../filter.pack &&
197 git -C r2 verify-pack -v ../filter.pack \
199 | awk -f print_1.awk \
201 test_cmp observed expected
204 test_expect_success 'verify explicitly specifying oversized blob in input' '
205 git -C r2 ls-files -s large.1000 large.10000 \
206 | awk -f print_2.awk \
208 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
210 $(git -C r2 rev-parse HEAD:large.10000)
212 git -C r2 index-pack ../filter.pack &&
213 git -C r2 verify-pack -v ../filter.pack \
215 | awk -f print_1.awk \
217 test_cmp observed expected
220 test_expect_success 'verify blob:limit=1m' '
221 git -C r2 ls-files -s large.1000 large.10000 \
222 | awk -f print_2.awk \
224 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
227 git -C r2 index-pack ../filter.pack &&
228 git -C r2 verify-pack -v ../filter.pack \
230 | awk -f print_1.awk \
232 test_cmp observed expected
235 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
236 git -C r2 verify-pack -v ../all.pack \
237 | grep -E "commit|tree" \
238 | awk -f print_1.awk \
240 git -C r2 verify-pack -v ../filter.pack \
241 | grep -E "commit|tree" \
242 | awk -f print_1.awk \
244 test_cmp observed expected
247 # Test sparse:path=<path> filter.
248 # Use a local file containing a sparse-checkout specification to filter
249 # out blobs not required for the corresponding sparse-checkout. We do not
250 # require sparse-checkout to actually be enabled.
252 test_expect_success 'setup r3' '
255 for n in sparse1 sparse2
257 echo "This is file: $n" > r3/$n
259 echo "This is file: dir1/$n" > r3/dir1/$n
260 git -C r3 add dir1/$n
262 git -C r3 commit -m "sparse" &&
263 echo dir1/ >pattern1 &&
264 echo sparse1 >pattern2
267 test_expect_success 'verify blob count in normal packfile' '
268 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
269 | awk -f print_2.awk \
271 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
274 git -C r3 index-pack ../all.pack &&
275 git -C r3 verify-pack -v ../all.pack \
277 | awk -f print_1.awk \
279 test_cmp observed expected
282 test_expect_success 'verify sparse:path=pattern1' '
283 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 \
284 | awk -f print_2.awk \
286 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
289 git -C r3 index-pack ../filter.pack &&
290 git -C r3 verify-pack -v ../filter.pack \
292 | awk -f print_1.awk \
294 test_cmp observed expected
297 test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
298 git -C r3 verify-pack -v ../all.pack \
299 | grep -E "commit|tree" \
300 | awk -f print_1.awk \
302 git -C r3 verify-pack -v ../filter.pack \
303 | grep -E "commit|tree" \
304 | awk -f print_1.awk \
306 test_cmp observed expected
309 test_expect_success 'verify sparse:path=pattern2' '
310 git -C r3 ls-files -s sparse1 dir1/sparse1 \
311 | awk -f print_2.awk \
313 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
316 git -C r3 index-pack ../filter.pack &&
317 git -C r3 verify-pack -v ../filter.pack \
319 | awk -f print_1.awk \
321 test_cmp observed expected
324 test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
325 git -C r3 verify-pack -v ../all.pack \
326 | grep -E "commit|tree" \
327 | awk -f print_1.awk \
329 git -C r3 verify-pack -v ../filter.pack \
330 | grep -E "commit|tree" \
331 | awk -f print_1.awk \
333 test_cmp observed expected
336 # Test sparse:oid=<oid-ish> filter.
337 # Like sparse:path, but we get the sparse-checkout specification from
338 # a blob rather than a file on disk.
340 test_expect_success 'setup r4' '
343 for n in sparse1 sparse2
345 echo "This is file: $n" > r4/$n
347 echo "This is file: dir1/$n" > r4/dir1/$n
348 git -C r4 add dir1/$n
350 echo dir1/ >r4/pattern &&
351 git -C r4 add pattern &&
352 git -C r4 commit -m "pattern"
355 test_expect_success 'verify blob count in normal packfile' '
356 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
357 | awk -f print_2.awk \
359 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
362 git -C r4 index-pack ../all.pack &&
363 git -C r4 verify-pack -v ../all.pack \
365 | awk -f print_1.awk \
367 test_cmp observed expected
370 test_expect_success 'verify sparse:oid=OID' '
371 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
372 | awk -f print_2.awk \
374 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
375 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
378 git -C r4 index-pack ../filter.pack &&
379 git -C r4 verify-pack -v ../filter.pack \
381 | awk -f print_1.awk \
383 test_cmp observed expected
386 test_expect_success 'verify sparse:oid=oid-ish' '
387 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
388 | awk -f print_2.awk \
390 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
393 git -C r4 index-pack ../filter.pack &&
394 git -C r4 verify-pack -v ../filter.pack \
396 | awk -f print_1.awk \
398 test_cmp observed expected
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 \
406 | awk -f print_2.awk \
408 for id in `cat expected | sed "s|..|&/|"`
410 rm r1/.git/objects/$id
414 test_expect_success 'verify pack-objects fails w/ missing objects' '
415 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
420 test_expect_success 'verify pack-objects fails w/ --missing=error' '
421 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
426 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
427 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF