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 blob:limit=<n>[kmg] filter.
63 # We boundary test around the size parameter. The filter is strictly less than
64 # the value, so size 500 and 1000 should have the same results, but 1001 should
67 test_expect_success
'setup r2' '
71 printf "%"$n"s" X > r2/large.$n
72 git -C r2 add large.$n
73 git -C r2 commit -m "$n"
77 test_expect_success
'verify blob count in normal packfile' '
78 git -C r2 ls-files -s large.1000 large.10000 \
79 | awk -f print_2.awk \
81 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
84 git -C r2 index-pack ../all.pack &&
85 git -C r2 verify-pack -v ../all.pack \
87 | awk -f print_1.awk \
89 test_cmp observed expected
92 test_expect_success
'verify blob:limit=500 omits all blobs' '
93 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
96 git -C r2 index-pack ../filter.pack &&
97 git -C r2 verify-pack -v ../filter.pack \
99 | awk -f print_1.awk \
101 nr=$(wc -l <observed) &&
105 test_expect_success
'verify blob:limit=1000' '
106 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
109 git -C r2 index-pack ../filter.pack &&
110 git -C r2 verify-pack -v ../filter.pack \
112 | awk -f print_1.awk \
114 nr=$(wc -l <observed) &&
118 test_expect_success
'verify blob:limit=1001' '
119 git -C r2 ls-files -s large.1000 \
120 | awk -f print_2.awk \
122 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
125 git -C r2 index-pack ../filter.pack &&
126 git -C r2 verify-pack -v ../filter.pack \
128 | awk -f print_1.awk \
130 test_cmp observed expected
133 test_expect_success
'verify blob:limit=10001' '
134 git -C r2 ls-files -s large.1000 large.10000 \
135 | awk -f print_2.awk \
137 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
140 git -C r2 index-pack ../filter.pack &&
141 git -C r2 verify-pack -v ../filter.pack \
143 | awk -f print_1.awk \
145 test_cmp observed expected
148 test_expect_success
'verify blob:limit=1k' '
149 git -C r2 ls-files -s large.1000 \
150 | awk -f print_2.awk \
152 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
155 git -C r2 index-pack ../filter.pack &&
156 git -C r2 verify-pack -v ../filter.pack \
158 | awk -f print_1.awk \
160 test_cmp observed expected
163 test_expect_success
'verify explicitly specifying oversized blob in input' '
164 git -C r2 ls-files -s large.1000 large.10000 \
165 | awk -f print_2.awk \
167 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
169 $(git -C r2 rev-parse HEAD:large.10000)
171 git -C r2 index-pack ../filter.pack &&
172 git -C r2 verify-pack -v ../filter.pack \
174 | awk -f print_1.awk \
176 test_cmp observed expected
179 test_expect_success
'verify blob:limit=1m' '
180 git -C r2 ls-files -s large.1000 large.10000 \
181 | awk -f print_2.awk \
183 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
186 git -C r2 index-pack ../filter.pack &&
187 git -C r2 verify-pack -v ../filter.pack \
189 | awk -f print_1.awk \
191 test_cmp observed expected
194 test_expect_success
'verify normal and blob:limit packfiles have same commits/trees' '
195 git -C r2 verify-pack -v ../all.pack \
196 | grep -E "commit|tree" \
197 | awk -f print_1.awk \
199 git -C r2 verify-pack -v ../filter.pack \
200 | grep -E "commit|tree" \
201 | awk -f print_1.awk \
203 test_cmp observed expected
206 # Test sparse:path=<path> filter.
207 # Use a local file containing a sparse-checkout specification to filter
208 # out blobs not required for the corresponding sparse-checkout. We do not
209 # require sparse-checkout to actually be enabled.
211 test_expect_success
'setup r3' '
214 for n in sparse1 sparse2
216 echo "This is file: $n" > r3/$n
218 echo "This is file: dir1/$n" > r3/dir1/$n
219 git -C r3 add dir1/$n
221 git -C r3 commit -m "sparse" &&
222 echo dir1/ >pattern1 &&
223 echo sparse1 >pattern2
226 test_expect_success
'verify blob count in normal packfile' '
227 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
228 | awk -f print_2.awk \
230 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
233 git -C r3 index-pack ../all.pack &&
234 git -C r3 verify-pack -v ../all.pack \
236 | awk -f print_1.awk \
238 test_cmp observed expected
241 test_expect_success
'verify sparse:path=pattern1' '
242 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 \
243 | awk -f print_2.awk \
245 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
248 git -C r3 index-pack ../filter.pack &&
249 git -C r3 verify-pack -v ../filter.pack \
251 | awk -f print_1.awk \
253 test_cmp observed expected
256 test_expect_success
'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
257 git -C r3 verify-pack -v ../all.pack \
258 | grep -E "commit|tree" \
259 | awk -f print_1.awk \
261 git -C r3 verify-pack -v ../filter.pack \
262 | grep -E "commit|tree" \
263 | awk -f print_1.awk \
265 test_cmp observed expected
268 test_expect_success
'verify sparse:path=pattern2' '
269 git -C r3 ls-files -s sparse1 dir1/sparse1 \
270 | awk -f print_2.awk \
272 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
275 git -C r3 index-pack ../filter.pack &&
276 git -C r3 verify-pack -v ../filter.pack \
278 | awk -f print_1.awk \
280 test_cmp observed expected
283 test_expect_success
'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
284 git -C r3 verify-pack -v ../all.pack \
285 | grep -E "commit|tree" \
286 | awk -f print_1.awk \
288 git -C r3 verify-pack -v ../filter.pack \
289 | grep -E "commit|tree" \
290 | awk -f print_1.awk \
292 test_cmp observed expected
295 # Test sparse:oid=<oid-ish> filter.
296 # Like sparse:path, but we get the sparse-checkout specification from
297 # a blob rather than a file on disk.
299 test_expect_success
'setup r4' '
302 for n in sparse1 sparse2
304 echo "This is file: $n" > r4/$n
306 echo "This is file: dir1/$n" > r4/dir1/$n
307 git -C r4 add dir1/$n
309 echo dir1/ >r4/pattern &&
310 git -C r4 add pattern &&
311 git -C r4 commit -m "pattern"
314 test_expect_success
'verify blob count in normal packfile' '
315 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
316 | awk -f print_2.awk \
318 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
321 git -C r4 index-pack ../all.pack &&
322 git -C r4 verify-pack -v ../all.pack \
324 | awk -f print_1.awk \
326 test_cmp observed expected
329 test_expect_success
'verify sparse:oid=OID' '
330 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
331 | awk -f print_2.awk \
333 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
334 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
337 git -C r4 index-pack ../filter.pack &&
338 git -C r4 verify-pack -v ../filter.pack \
340 | awk -f print_1.awk \
342 test_cmp observed expected
345 test_expect_success
'verify sparse:oid=oid-ish' '
346 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
347 | awk -f print_2.awk \
349 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
352 git -C r4 index-pack ../filter.pack &&
353 git -C r4 verify-pack -v ../filter.pack \
355 | awk -f print_1.awk \
357 test_cmp observed expected
360 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
361 # This models previously omitted objects that we did not receive.
363 test_expect_success
'setup r1 - delete loose blobs' '
364 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
365 | awk -f print_2.awk \
367 for id in `cat expected | sed "s|..|&/|"`
369 rm r1/.git/objects/$id
373 test_expect_success
'verify pack-objects fails w/ missing objects' '
374 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
379 test_expect_success
'verify pack-objects fails w/ --missing=error' '
380 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
385 test_expect_success
'verify pack-objects w/ --missing=allow-any' '
386 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF