1#!/bin/sh
2
3test_description='git pack-objects using object filtering'
4
5. ./test-lib.sh
6
7# Test blob:none filter.
8
9test_expect_success 'setup r1' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
12
13 git init r1 &&
14 for n in 1 2 3 4 5
15 do
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
20'
21
22test_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 &&
27
28 git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
29 HEAD
30 EOF
31 git -C r1 index-pack ../all.pack &&
32
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 &&
37
38 test_cmp expected observed
39'
40
41test_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 &&
46
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 &&
51
52 nr=$(wc -l <observed) &&
53 test 0 -eq $nr
54'
55
56test_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 &&
61
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 &&
66
67 test_cmp expected observed
68'
69
70# Test blob:limit=<n>[kmg] filter.
71# We boundary test around the size parameter. The filter is strictly less than
72# the value, so size 500 and 1000 should have the same results, but 1001 should
73# filter more.
74
75test_expect_success 'setup r2' '
76 git init r2 &&
77 for n in 1000 10000
78 do
79 printf "%"$n"s" X > r2/large.$n
80 git -C r2 add large.$n
81 git -C r2 commit -m "$n"
82 done
83'
84
85test_expect_success 'verify blob count in normal packfile' '
86 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
87 awk -f print_2.awk ls_files_result |
88 sort >expected &&
89
90 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
91 HEAD
92 EOF
93 git -C r2 index-pack ../all.pack &&
94
95 git -C r2 verify-pack -v ../all.pack >verify_result &&
96 grep blob verify_result |
97 awk -f print_1.awk |
98 sort >observed &&
99
100 test_cmp expected observed
101'
102
103test_expect_success 'verify blob:limit=500 omits all blobs' '
104 git -C r2 pack-objects --rev --stdout --filter=blob:limit=500 >filter.pack <<-EOF &&
105 HEAD
106 EOF
107 git -C r2 index-pack ../filter.pack &&
108
109 git -C r2 verify-pack -v ../filter.pack >verify_result &&
110 grep blob verify_result |
111 awk -f print_1.awk |
112 sort >observed &&
113
114 nr=$(wc -l <observed) &&
115 test 0 -eq $nr
116'
117
118test_expect_success 'verify blob:limit=1000' '
119 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
120 HEAD
121 EOF
122 git -C r2 index-pack ../filter.pack &&
123
124 git -C r2 verify-pack -v ../filter.pack >verify_result &&
125 grep blob verify_result |
126 awk -f print_1.awk |
127 sort >observed &&
128
129 nr=$(wc -l <observed) &&
130 test 0 -eq $nr
131'
132
133test_expect_success 'verify blob:limit=1001' '
134 git -C r2 ls-files -s large.1000 >ls_files_result &&
135 awk -f print_2.awk ls_files_result |
136 sort >expected &&
137
138 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
139 HEAD
140 EOF
141 git -C r2 index-pack ../filter.pack &&
142
143 git -C r2 verify-pack -v ../filter.pack >verify_result &&
144 grep blob verify_result |
145 awk -f print_1.awk |
146 sort >observed &&
147
148 test_cmp expected observed
149'
150
151test_expect_success 'verify blob:limit=10001' '
152 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
153 awk -f print_2.awk ls_files_result |
154 sort >expected &&
155
156 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
157 HEAD
158 EOF
159 git -C r2 index-pack ../filter.pack &&
160
161 git -C r2 verify-pack -v ../filter.pack >verify_result &&
162 grep blob verify_result |
163 awk -f print_1.awk |
164 sort >observed &&
165
166 test_cmp expected observed
167'
168
169test_expect_success 'verify blob:limit=1k' '
170 git -C r2 ls-files -s large.1000 >ls_files_result &&
171 awk -f print_2.awk ls_files_result |
172 sort >expected &&
173
174 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
175 HEAD
176 EOF
177 git -C r2 index-pack ../filter.pack &&
178
179 git -C r2 verify-pack -v ../filter.pack >verify_result &&
180 grep blob verify_result |
181 awk -f print_1.awk |
182 sort >observed &&
183
184 test_cmp expected observed
185'
186
187test_expect_success 'verify explicitly specifying oversized blob in input' '
188 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
189 awk -f print_2.awk ls_files_result |
190 sort >expected &&
191
192 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
193 HEAD
194 $(git -C r2 rev-parse HEAD:large.10000)
195 EOF
196 git -C r2 index-pack ../filter.pack &&
197
198 git -C r2 verify-pack -v ../filter.pack >verify_result &&
199 grep blob verify_result |
200 awk -f print_1.awk |
201 sort >observed &&
202
203 test_cmp expected observed
204'
205
206test_expect_success 'verify blob:limit=1m' '
207 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
208 awk -f print_2.awk ls_files_result |
209 sort >expected &&
210
211 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
212 HEAD
213 EOF
214 git -C r2 index-pack ../filter.pack &&
215
216 git -C r2 verify-pack -v ../filter.pack >verify_result &&
217 grep blob verify_result |
218 awk -f print_1.awk |
219 sort >observed &&
220
221 test_cmp expected observed
222'
223
224test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
225 git -C r2 verify-pack -v ../all.pack >verify_result &&
226 grep -E "commit|tree" verify_result |
227 awk -f print_1.awk |
228 sort >expected &&
229
230 git -C r2 verify-pack -v ../filter.pack >verify_result &&
231 grep -E "commit|tree" verify_result |
232 awk -f print_1.awk |
233 sort >observed &&
234
235 test_cmp expected observed
236'
237
238# Test sparse:path=<path> filter.
239# Use a local file containing a sparse-checkout specification to filter
240# out blobs not required for the corresponding sparse-checkout. We do not
241# require sparse-checkout to actually be enabled.
242
243test_expect_success 'setup r3' '
244 git init r3 &&
245 mkdir r3/dir1 &&
246 for n in sparse1 sparse2
247 do
248 echo "This is file: $n" > r3/$n
249 git -C r3 add $n
250 echo "This is file: dir1/$n" > r3/dir1/$n
251 git -C r3 add dir1/$n
252 done &&
253 git -C r3 commit -m "sparse" &&
254 echo dir1/ >pattern1 &&
255 echo sparse1 >pattern2
256'
257
258test_expect_success 'verify blob count in normal packfile' '
259 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
260 >ls_files_result &&
261 awk -f print_2.awk ls_files_result |
262 sort >expected &&
263
264 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
265 HEAD
266 EOF
267 git -C r3 index-pack ../all.pack &&
268
269 git -C r3 verify-pack -v ../all.pack >verify_result &&
270 grep blob verify_result |
271 awk -f print_1.awk |
272 sort >observed &&
273
274 test_cmp expected observed
275'
276
277test_expect_success 'verify sparse:path=pattern1' '
278 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
279 awk -f print_2.awk ls_files_result |
280 sort >expected &&
281
282 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
283 HEAD
284 EOF
285 git -C r3 index-pack ../filter.pack &&
286
287 git -C r3 verify-pack -v ../filter.pack >verify_result &&
288 grep blob verify_result |
289 awk -f print_1.awk |
290 sort >observed &&
291
292 test_cmp expected observed
293'
294
295test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
296 git -C r3 verify-pack -v ../all.pack >verify_result &&
297 grep -E "commit|tree" verify_result |
298 awk -f print_1.awk |
299 sort >expected &&
300
301 git -C r3 verify-pack -v ../filter.pack >verify_result &&
302 grep -E "commit|tree" verify_result |
303 awk -f print_1.awk |
304 sort >observed &&
305
306 test_cmp expected observed
307'
308
309test_expect_success 'verify sparse:path=pattern2' '
310 git -C r3 ls-files -s sparse1 dir1/sparse1 >ls_files_result &&
311 awk -f print_2.awk ls_files_result |
312 sort >expected &&
313
314 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
315 HEAD
316 EOF
317 git -C r3 index-pack ../filter.pack &&
318
319 git -C r3 verify-pack -v ../filter.pack >verify_result &&
320 grep blob verify_result |
321 awk -f print_1.awk |
322 sort >observed &&
323
324 test_cmp expected observed
325'
326
327test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
328 git -C r3 verify-pack -v ../all.pack >verify_result &&
329 grep -E "commit|tree" verify_result |
330 awk -f print_1.awk |
331 sort >expected &&
332
333 git -C r3 verify-pack -v ../filter.pack >verify_result &&
334 grep -E "commit|tree" verify_result |
335 awk -f print_1.awk |
336 sort >observed &&
337
338 test_cmp expected observed
339'
340
341# Test sparse:oid=<oid-ish> filter.
342# Like sparse:path, but we get the sparse-checkout specification from
343# a blob rather than a file on disk.
344
345test_expect_success 'setup r4' '
346 git init r4 &&
347 mkdir r4/dir1 &&
348 for n in sparse1 sparse2
349 do
350 echo "This is file: $n" > r4/$n
351 git -C r4 add $n
352 echo "This is file: dir1/$n" > r4/dir1/$n
353 git -C r4 add dir1/$n
354 done &&
355 echo dir1/ >r4/pattern &&
356 git -C r4 add pattern &&
357 git -C r4 commit -m "pattern"
358'
359
360test_expect_success 'verify blob count in normal packfile' '
361 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
362 >ls_files_result &&
363 awk -f print_2.awk ls_files_result |
364 sort >expected &&
365
366 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
367 HEAD
368 EOF
369 git -C r4 index-pack ../all.pack &&
370
371 git -C r4 verify-pack -v ../all.pack >verify_result &&
372 grep blob verify_result |
373 awk -f print_1.awk |
374 sort >observed &&
375
376 test_cmp expected observed
377'
378
379test_expect_success 'verify sparse:oid=OID' '
380 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
381 awk -f print_2.awk ls_files_result |
382 sort >expected &&
383
384 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
385 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
386 HEAD
387 EOF
388 git -C r4 index-pack ../filter.pack &&
389
390 git -C r4 verify-pack -v ../filter.pack >verify_result &&
391 grep blob verify_result |
392 awk -f print_1.awk |
393 sort >observed &&
394
395 test_cmp expected observed
396'
397
398test_expect_success 'verify sparse:oid=oid-ish' '
399 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 >ls_files_result &&
400 awk -f print_2.awk ls_files_result |
401 sort >expected &&
402
403 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
404 HEAD
405 EOF
406 git -C r4 index-pack ../filter.pack &&
407
408 git -C r4 verify-pack -v ../filter.pack >verify_result &&
409 grep blob verify_result |
410 awk -f print_1.awk |
411 sort >observed &&
412
413 test_cmp expected observed
414'
415
416# Delete some loose objects and use pack-objects, but WITHOUT any filtering.
417# This models previously omitted objects that we did not receive.
418
419test_expect_success 'setup r1 - delete loose blobs' '
420 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
421 >ls_files_result &&
422 awk -f print_2.awk ls_files_result |
423 sort >expected &&
424
425 for id in `cat expected | sed "s|..|&/|"`
426 do
427 rm r1/.git/objects/$id
428 done
429'
430
431test_expect_success 'verify pack-objects fails w/ missing objects' '
432 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
433 HEAD
434 EOF
435'
436
437test_expect_success 'verify pack-objects fails w/ --missing=error' '
438 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
439 HEAD
440 EOF
441'
442
443test_expect_success 'verify pack-objects w/ --missing=allow-any' '
444 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
445 HEAD
446 EOF
447'
448
449test_done