Merge branch 'sg/travis-build-during-script-phase'
[git] / t / t5317-pack-objects-filter-objects.sh
1 #!/bin/sh
2
3 test_description='git pack-objects using object filtering'
4
5 . ./test-lib.sh
6
7 # Test blob:none filter.
8
9 test_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
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
35 '
36
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
48 '
49
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
60 '
61
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.
66
67 test_expect_success 'setup r2' '
68         git init r2 &&
69         for n in 1000 10000
70         do
71                 printf "%"$n"s" X > r2/large.$n
72                 git -C r2 add large.$n
73                 git -C r2 commit -m "$n"
74         done
75 '
76
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
90 '
91
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
103 '
104
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
108         EOF
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
116 '
117
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
124         EOF
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
131 '
132
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
139         EOF
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
146 '
147
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
154         EOF
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
161 '
162
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
169         EOF
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
176 '
177
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
188 '
189
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.
194
195 test_expect_success 'setup r3' '
196         git init r3 &&
197         mkdir r3/dir1 &&
198         for n in sparse1 sparse2
199         do
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
208 '
209
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
216         EOF
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
223 '
224
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
231         EOF
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
238 '
239
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
250 '
251
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
258         EOF
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
265 '
266
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
277 '
278
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.
282
283 test_expect_success 'setup r4' '
284         git init r4 &&
285         mkdir r4/dir1 &&
286         for n in sparse1 sparse2
287         do
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"
296 '
297
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
304         EOF
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
311 '
312
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
320         EOF
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
327 '
328
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
335         EOF
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
342 '
343
344 # Delete some loose objects and use pack-objects, but WITHOUT any filtering.
345 # This models previously omitted objects that we did not receive.
346
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|..|&/|"`
352         do
353                 rm r1/.git/objects/$id
354         done
355 '
356
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
360         EOF
361 '
362
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
366         EOF
367 '
368
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
372         EOF
373 '
374
375 test_done