tests: don't swallow Git errors upstream of pipes
[git/git.git] / t / t6112-rev-list-filters-objects.sh
CommitLineData
caf3827e
JH
1#!/bin/sh
2
3test_description='git rev-list using object filtering'
4
5. ./test-lib.sh
6
7# Test the 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:none omits all 5 blobs' '
61de0ff6
MD
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 |
bdbc17e8
MD
26 sort >expected &&
27
61de0ff6
MD
28 git -C r1 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:none >revs &&
29 awk -f print_1.awk revs |
bdbc17e8
MD
30 sed "s/~//" |
31 sort >observed &&
32
dcbaa0b3 33 test_cmp expected observed
caf3827e
JH
34'
35
36test_expect_success 'verify emitted+omitted == all' '
61de0ff6
MD
37 git -C r1 rev-list HEAD --objects >revs &&
38 awk -f print_1.awk revs |
bdbc17e8
MD
39 sort >expected &&
40
61de0ff6
MD
41 git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
42 >revs &&
43 awk -f print_1.awk revs |
bdbc17e8
MD
44 sed "s/~//" |
45 sort >observed &&
46
dcbaa0b3 47 test_cmp expected observed
caf3827e
JH
48'
49
50
51# Test blob:limit=<n>[kmg] filter.
52# We boundary test around the size parameter. The filter is strictly less than
53# the value, so size 500 and 1000 should have the same results, but 1001 should
54# filter more.
55
56test_expect_success 'setup r2' '
57 git init r2 &&
58 for n in 1000 10000
59 do
60 printf "%"$n"s" X > r2/large.$n
61 git -C r2 add large.$n
62 git -C r2 commit -m "$n"
63 done
64'
65
66test_expect_success 'verify blob:limit=500 omits all blobs' '
61de0ff6
MD
67 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
68 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
69 sort >expected &&
70
61de0ff6
MD
71 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 >revs &&
72 awk -f print_1.awk revs |
bdbc17e8
MD
73 sed "s/~//" |
74 sort >observed &&
75
dcbaa0b3 76 test_cmp expected observed
caf3827e
JH
77'
78
79test_expect_success 'verify emitted+omitted == all' '
61de0ff6
MD
80 git -C r2 rev-list HEAD --objects >revs &&
81 awk -f print_1.awk revs |
bdbc17e8
MD
82 sort >expected &&
83
61de0ff6
MD
84 git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 >revs &&
85 awk -f print_1.awk revs |
bdbc17e8
MD
86 sed "s/~//" |
87 sort >observed &&
88
dcbaa0b3 89 test_cmp expected observed
caf3827e
JH
90'
91
92test_expect_success 'verify blob:limit=1000' '
61de0ff6
MD
93 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
94 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
95 sort >expected &&
96
61de0ff6
MD
97 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 >revs &&
98 awk -f print_1.awk revs |
bdbc17e8
MD
99 sed "s/~//" |
100 sort >observed &&
101
dcbaa0b3 102 test_cmp expected observed
caf3827e
JH
103'
104
105test_expect_success 'verify blob:limit=1001' '
61de0ff6
MD
106 git -C r2 ls-files -s large.10000 >ls_files_result &&
107 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
108 sort >expected &&
109
61de0ff6
MD
110 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 >revs &&
111 awk -f print_1.awk revs |
bdbc17e8
MD
112 sed "s/~//" |
113 sort >observed &&
114
dcbaa0b3 115 test_cmp expected observed
caf3827e
JH
116'
117
118test_expect_success 'verify blob:limit=1k' '
61de0ff6
MD
119 git -C r2 ls-files -s large.10000 >ls_files_result &&
120 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
121 sort >expected &&
122
61de0ff6
MD
123 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k >revs &&
124 awk -f print_1.awk revs |
bdbc17e8
MD
125 sed "s/~//" |
126 sort >observed &&
127
dcbaa0b3 128 test_cmp expected observed
caf3827e
JH
129'
130
131test_expect_success 'verify blob:limit=1m' '
61de0ff6
MD
132 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m >revs &&
133 awk -f print_1.awk revs |
bdbc17e8
MD
134 sed "s/~//" |
135 sort >observed &&
136
1c5e94f4 137 test_must_be_empty observed
caf3827e
JH
138'
139
140# Test sparse:path=<path> filter.
141# Use a local file containing a sparse-checkout specification to filter
142# out blobs not required for the corresponding sparse-checkout. We do not
143# require sparse-checkout to actually be enabled.
144
145test_expect_success 'setup r3' '
146 git init r3 &&
147 mkdir r3/dir1 &&
148 for n in sparse1 sparse2
149 do
150 echo "This is file: $n" > r3/$n
151 git -C r3 add $n
152 echo "This is file: dir1/$n" > r3/dir1/$n
153 git -C r3 add dir1/$n
154 done &&
155 git -C r3 commit -m "sparse" &&
156 echo dir1/ >pattern1 &&
157 echo sparse1 >pattern2
158'
159
160test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
61de0ff6
MD
161 git -C r3 ls-files -s sparse1 sparse2 >ls_files_result &&
162 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
163 sort >expected &&
164
61de0ff6
MD
165 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 >revs &&
166 awk -f print_1.awk revs |
bdbc17e8
MD
167 sed "s/~//" |
168 sort >observed &&
169
dcbaa0b3 170 test_cmp expected observed
caf3827e
JH
171'
172
173test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
61de0ff6
MD
174 git -C r3 ls-files -s sparse2 dir1/sparse2 >ls_files_result &&
175 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
176 sort >expected &&
177
61de0ff6
MD
178 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 >revs &&
179 awk -f print_1.awk revs |
bdbc17e8
MD
180 sed "s/~//" |
181 sort >observed &&
182
dcbaa0b3 183 test_cmp expected observed
caf3827e
JH
184'
185
186# Test sparse:oid=<oid-ish> filter.
187# Like sparse:path, but we get the sparse-checkout specification from
188# a blob rather than a file on disk.
189
190test_expect_success 'setup r3 part 2' '
191 echo dir1/ >r3/pattern &&
192 git -C r3 add pattern &&
193 git -C r3 commit -m "pattern"
194'
195
196test_expect_success 'verify sparse:oid=OID omits top-level files' '
61de0ff6
MD
197 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
198 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
199 sort >expected &&
200
caf3827e 201 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
bdbc17e8 202
61de0ff6
MD
203 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid >revs &&
204 awk -f print_1.awk revs |
bdbc17e8
MD
205 sed "s/~//" |
206 sort >observed &&
207
dcbaa0b3 208 test_cmp expected observed
caf3827e
JH
209'
210
211test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
61de0ff6
MD
212 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
213 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
214 sort >expected &&
215
61de0ff6
MD
216 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern >revs &&
217 awk -f print_1.awk revs |
bdbc17e8
MD
218 sed "s/~//" |
219 sort >observed &&
220
dcbaa0b3 221 test_cmp expected observed
caf3827e
JH
222'
223
224# Delete some loose objects and use rev-list, but WITHOUT any filtering.
225# This models previously omitted objects that we did not receive.
226
227test_expect_success 'rev-list W/ --missing=print' '
61de0ff6
MD
228 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
229 >ls_files_result &&
230 awk -f print_2.awk ls_files_result |
bdbc17e8
MD
231 sort >expected &&
232
caf3827e
JH
233 for id in `cat expected | sed "s|..|&/|"`
234 do
235 rm r1/.git/objects/$id
236 done &&
bdbc17e8 237
61de0ff6
MD
238 git -C r1 rev-list --quiet HEAD --missing=print --objects >revs &&
239 awk -f print_1.awk revs |
bdbc17e8
MD
240 sed "s/?//" |
241 sort >observed &&
242
dcbaa0b3 243 test_cmp expected observed
caf3827e
JH
244'
245
246test_expect_success 'rev-list W/O --missing fails' '
247 test_must_fail git -C r1 rev-list --quiet --objects HEAD
248'
249
250test_expect_success 'rev-list W/ missing=allow-any' '
251 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
252'
253
254test_done