repack -ad: prune the list of shallow commits
[git/raj.git] / t / t5317-pack-objects-filter-objects.sh
blob6710c8bc8c4699035bec418258fcaec8a634855c
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 | awk -f print_2.awk \
25 | sort >expected &&
26 git -C r1 pack-objects --rev --stdout >all.pack <<-EOF &&
27 HEAD
28 EOF
29 git -C r1 index-pack ../all.pack &&
30 git -C r1 verify-pack -v ../all.pack \
31 | grep blob \
32 | awk -f print_1.awk \
33 | sort >observed &&
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 &&
39 HEAD
40 EOF
41 git -C r1 index-pack ../filter.pack &&
42 git -C r1 verify-pack -v ../filter.pack \
43 | grep blob \
44 | awk -f print_1.awk \
45 | sort >observed &&
46 nr=$(wc -l <observed) &&
47 test 0 -eq $nr
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 \
54 | sort >expected &&
55 git -C r1 verify-pack -v ../filter.pack \
56 | grep -E "commit|tree" \
57 | awk -f print_1.awk \
58 | sort >observed &&
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
65 # filter more.
67 test_expect_success 'setup r2' '
68 git init r2 &&
69 for n in 1000 10000
71 printf "%"$n"s" X > r2/large.$n
72 git -C r2 add large.$n
73 git -C r2 commit -m "$n"
74 done
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 \
80 | sort >expected &&
81 git -C r2 pack-objects --rev --stdout >all.pack <<-EOF &&
82 HEAD
83 EOF
84 git -C r2 index-pack ../all.pack &&
85 git -C r2 verify-pack -v ../all.pack \
86 | grep blob \
87 | awk -f print_1.awk \
88 | sort >observed &&
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 &&
94 HEAD
95 EOF
96 git -C r2 index-pack ../filter.pack &&
97 git -C r2 verify-pack -v ../filter.pack \
98 | grep blob \
99 | awk -f print_1.awk \
100 | sort >observed &&
101 nr=$(wc -l <observed) &&
102 test 0 -eq $nr
105 test_expect_success 'verify blob:limit=1000' '
106 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1000 >filter.pack <<-EOF &&
107 HEAD
109 git -C r2 index-pack ../filter.pack &&
110 git -C r2 verify-pack -v ../filter.pack \
111 | grep blob \
112 | awk -f print_1.awk \
113 | sort >observed &&
114 nr=$(wc -l <observed) &&
115 test 0 -eq $nr
118 test_expect_success 'verify blob:limit=1001' '
119 git -C r2 ls-files -s large.1000 \
120 | awk -f print_2.awk \
121 | sort >expected &&
122 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1001 >filter.pack <<-EOF &&
123 HEAD
125 git -C r2 index-pack ../filter.pack &&
126 git -C r2 verify-pack -v ../filter.pack \
127 | grep blob \
128 | awk -f print_1.awk \
129 | sort >observed &&
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 \
136 | sort >expected &&
137 git -C r2 pack-objects --rev --stdout --filter=blob:limit=10001 >filter.pack <<-EOF &&
138 HEAD
140 git -C r2 index-pack ../filter.pack &&
141 git -C r2 verify-pack -v ../filter.pack \
142 | grep blob \
143 | awk -f print_1.awk \
144 | sort >observed &&
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 \
151 | sort >expected &&
152 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
153 HEAD
155 git -C r2 index-pack ../filter.pack &&
156 git -C r2 verify-pack -v ../filter.pack \
157 | grep blob \
158 | awk -f print_1.awk \
159 | sort >observed &&
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 \
166 | sort >expected &&
167 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1k >filter.pack <<-EOF &&
168 HEAD
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 \
173 | grep blob \
174 | awk -f print_1.awk \
175 | sort >observed &&
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 \
182 | sort >expected &&
183 git -C r2 pack-objects --rev --stdout --filter=blob:limit=1m >filter.pack <<-EOF &&
184 HEAD
186 git -C r2 index-pack ../filter.pack &&
187 git -C r2 verify-pack -v ../filter.pack \
188 | grep blob \
189 | awk -f print_1.awk \
190 | sort >observed &&
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 \
198 | sort >expected &&
199 git -C r2 verify-pack -v ../filter.pack \
200 | grep -E "commit|tree" \
201 | awk -f print_1.awk \
202 | sort >observed &&
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' '
212 git init r3 &&
213 mkdir r3/dir1 &&
214 for n in sparse1 sparse2
216 echo "This is file: $n" > r3/$n
217 git -C r3 add $n
218 echo "This is file: dir1/$n" > r3/dir1/$n
219 git -C r3 add dir1/$n
220 done &&
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 \
229 | sort >expected &&
230 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
231 HEAD
233 git -C r3 index-pack ../all.pack &&
234 git -C r3 verify-pack -v ../all.pack \
235 | grep blob \
236 | awk -f print_1.awk \
237 | sort >observed &&
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 \
244 | sort >expected &&
245 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
246 HEAD
248 git -C r3 index-pack ../filter.pack &&
249 git -C r3 verify-pack -v ../filter.pack \
250 | grep blob \
251 | awk -f print_1.awk \
252 | sort >observed &&
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 \
260 | sort >expected &&
261 git -C r3 verify-pack -v ../filter.pack \
262 | grep -E "commit|tree" \
263 | awk -f print_1.awk \
264 | sort >observed &&
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 \
271 | sort >expected &&
272 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
273 HEAD
275 git -C r3 index-pack ../filter.pack &&
276 git -C r3 verify-pack -v ../filter.pack \
277 | grep blob \
278 | awk -f print_1.awk \
279 | sort >observed &&
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 \
287 | sort >expected &&
288 git -C r3 verify-pack -v ../filter.pack \
289 | grep -E "commit|tree" \
290 | awk -f print_1.awk \
291 | sort >observed &&
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' '
300 git init r4 &&
301 mkdir r4/dir1 &&
302 for n in sparse1 sparse2
304 echo "This is file: $n" > r4/$n
305 git -C r4 add $n
306 echo "This is file: dir1/$n" > r4/dir1/$n
307 git -C r4 add dir1/$n
308 done &&
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 \
317 | sort >expected &&
318 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
319 HEAD
321 git -C r4 index-pack ../all.pack &&
322 git -C r4 verify-pack -v ../all.pack \
323 | grep blob \
324 | awk -f print_1.awk \
325 | sort >observed &&
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 \
332 | sort >expected &&
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 &&
335 HEAD
337 git -C r4 index-pack ../filter.pack &&
338 git -C r4 verify-pack -v ../filter.pack \
339 | grep blob \
340 | awk -f print_1.awk \
341 | sort >observed &&
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 \
348 | sort >expected &&
349 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
350 HEAD
352 git -C r4 index-pack ../filter.pack &&
353 git -C r4 verify-pack -v ../filter.pack \
354 | grep blob \
355 | awk -f print_1.awk \
356 | sort >observed &&
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 \
366 | sort >expected &&
367 for id in `cat expected | sed "s|..|&/|"`
369 rm r1/.git/objects/$id
370 done
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
375 HEAD
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
381 HEAD
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
387 HEAD
391 test_done