t1510-repo-setup: mark as untraceable with '-x'
[alt-git.git] / t / t5317-pack-objects-filter-objects.sh
blob1b0acc383bb216a3f420cd19ff066275a5b4706e
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 blob:limit=1m' '
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=1m >filter.pack <<-EOF &&
168 HEAD
170 git -C r2 index-pack ../filter.pack &&
171 git -C r2 verify-pack -v ../filter.pack \
172 | grep blob \
173 | awk -f print_1.awk \
174 | sort >observed &&
175 test_cmp observed expected
178 test_expect_success 'verify normal and blob:limit packfiles have same commits/trees' '
179 git -C r2 verify-pack -v ../all.pack \
180 | grep -E "commit|tree" \
181 | awk -f print_1.awk \
182 | sort >expected &&
183 git -C r2 verify-pack -v ../filter.pack \
184 | grep -E "commit|tree" \
185 | awk -f print_1.awk \
186 | sort >observed &&
187 test_cmp observed expected
190 # Test sparse:path=<path> filter.
191 # Use a local file containing a sparse-checkout specification to filter
192 # out blobs not required for the corresponding sparse-checkout. We do not
193 # require sparse-checkout to actually be enabled.
195 test_expect_success 'setup r3' '
196 git init r3 &&
197 mkdir r3/dir1 &&
198 for n in sparse1 sparse2
200 echo "This is file: $n" > r3/$n
201 git -C r3 add $n
202 echo "This is file: dir1/$n" > r3/dir1/$n
203 git -C r3 add dir1/$n
204 done &&
205 git -C r3 commit -m "sparse" &&
206 echo dir1/ >pattern1 &&
207 echo sparse1 >pattern2
210 test_expect_success 'verify blob count in normal packfile' '
211 git -C r3 ls-files -s sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
212 | awk -f print_2.awk \
213 | sort >expected &&
214 git -C r3 pack-objects --rev --stdout >all.pack <<-EOF &&
215 HEAD
217 git -C r3 index-pack ../all.pack &&
218 git -C r3 verify-pack -v ../all.pack \
219 | grep blob \
220 | awk -f print_1.awk \
221 | sort >observed &&
222 test_cmp observed expected
225 test_expect_success 'verify sparse:path=pattern1' '
226 git -C r3 ls-files -s dir1/sparse1 dir1/sparse2 \
227 | awk -f print_2.awk \
228 | sort >expected &&
229 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern1 >filter.pack <<-EOF &&
230 HEAD
232 git -C r3 index-pack ../filter.pack &&
233 git -C r3 verify-pack -v ../filter.pack \
234 | grep blob \
235 | awk -f print_1.awk \
236 | sort >observed &&
237 test_cmp observed expected
240 test_expect_success 'verify normal and sparse:path=pattern1 packfiles have same commits/trees' '
241 git -C r3 verify-pack -v ../all.pack \
242 | grep -E "commit|tree" \
243 | awk -f print_1.awk \
244 | sort >expected &&
245 git -C r3 verify-pack -v ../filter.pack \
246 | grep -E "commit|tree" \
247 | awk -f print_1.awk \
248 | sort >observed &&
249 test_cmp observed expected
252 test_expect_success 'verify sparse:path=pattern2' '
253 git -C r3 ls-files -s sparse1 dir1/sparse1 \
254 | awk -f print_2.awk \
255 | sort >expected &&
256 git -C r3 pack-objects --rev --stdout --filter=sparse:path=../pattern2 >filter.pack <<-EOF &&
257 HEAD
259 git -C r3 index-pack ../filter.pack &&
260 git -C r3 verify-pack -v ../filter.pack \
261 | grep blob \
262 | awk -f print_1.awk \
263 | sort >observed &&
264 test_cmp observed expected
267 test_expect_success 'verify normal and sparse:path=pattern2 packfiles have same commits/trees' '
268 git -C r3 verify-pack -v ../all.pack \
269 | grep -E "commit|tree" \
270 | awk -f print_1.awk \
271 | sort >expected &&
272 git -C r3 verify-pack -v ../filter.pack \
273 | grep -E "commit|tree" \
274 | awk -f print_1.awk \
275 | sort >observed &&
276 test_cmp observed expected
279 # Test sparse:oid=<oid-ish> filter.
280 # Like sparse:path, but we get the sparse-checkout specification from
281 # a blob rather than a file on disk.
283 test_expect_success 'setup r4' '
284 git init r4 &&
285 mkdir r4/dir1 &&
286 for n in sparse1 sparse2
288 echo "This is file: $n" > r4/$n
289 git -C r4 add $n
290 echo "This is file: dir1/$n" > r4/dir1/$n
291 git -C r4 add dir1/$n
292 done &&
293 echo dir1/ >r4/pattern &&
294 git -C r4 add pattern &&
295 git -C r4 commit -m "pattern"
298 test_expect_success 'verify blob count in normal packfile' '
299 git -C r4 ls-files -s pattern sparse1 sparse2 dir1/sparse1 dir1/sparse2 \
300 | awk -f print_2.awk \
301 | sort >expected &&
302 git -C r4 pack-objects --rev --stdout >all.pack <<-EOF &&
303 HEAD
305 git -C r4 index-pack ../all.pack &&
306 git -C r4 verify-pack -v ../all.pack \
307 | grep blob \
308 | awk -f print_1.awk \
309 | sort >observed &&
310 test_cmp observed expected
313 test_expect_success 'verify sparse:oid=OID' '
314 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
315 | awk -f print_2.awk \
316 | sort >expected &&
317 oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) &&
318 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
319 HEAD
321 git -C r4 index-pack ../filter.pack &&
322 git -C r4 verify-pack -v ../filter.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-ish' '
330 git -C r4 ls-files -s dir1/sparse1 dir1/sparse2 \
331 | awk -f print_2.awk \
332 | sort >expected &&
333 git -C r4 pack-objects --rev --stdout --filter=sparse:oid=master:pattern >filter.pack <<-EOF &&
334 HEAD
336 git -C r4 index-pack ../filter.pack &&
337 git -C r4 verify-pack -v ../filter.pack \
338 | grep blob \
339 | awk -f print_1.awk \
340 | sort >observed &&
341 test_cmp observed expected
344 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
345 # This models previously omitted objects that we did not receive.
347 test_expect_success 'setup r1 - delete loose blobs' '
348 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
349 | awk -f print_2.awk \
350 | sort >expected &&
351 for id in `cat expected | sed "s|..|&/|"`
353 rm r1/.git/objects/$id
354 done
357 test_expect_success 'verify pack-objects fails w/ missing objects' '
358 test_must_fail git -C r1 pack-objects --rev --stdout >miss.pack <<-EOF
359 HEAD
363 test_expect_success 'verify pack-objects fails w/ --missing=error' '
364 test_must_fail git -C r1 pack-objects --rev --stdout --missing=error >miss.pack <<-EOF
365 HEAD
369 test_expect_success 'verify pack-objects w/ --missing=allow-any' '
370 git -C r1 pack-objects --rev --stdout --missing=allow-any >miss.pack <<-EOF
371 HEAD
375 test_done