tests: don't swallow Git errors upstream of pipes
[git/git.git] / t / t6112-rev-list-filters-objects.sh
1 #!/bin/sh
2
3 test_description='git rev-list using object filtering'
4
5 . ./test-lib.sh
6
7 # Test the 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:none omits all 5 blobs' '
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 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:none >revs &&
29 awk -f print_1.awk revs |
30 sed "s/~//" |
31 sort >observed &&
32
33 test_cmp expected observed
34 '
35
36 test_expect_success 'verify emitted+omitted == all' '
37 git -C r1 rev-list HEAD --objects >revs &&
38 awk -f print_1.awk revs |
39 sort >expected &&
40
41 git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
42 >revs &&
43 awk -f print_1.awk revs |
44 sed "s/~//" |
45 sort >observed &&
46
47 test_cmp expected observed
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
56 test_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
66 test_expect_success 'verify blob:limit=500 omits all blobs' '
67 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
68 awk -f print_2.awk ls_files_result |
69 sort >expected &&
70
71 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 >revs &&
72 awk -f print_1.awk revs |
73 sed "s/~//" |
74 sort >observed &&
75
76 test_cmp expected observed
77 '
78
79 test_expect_success 'verify emitted+omitted == all' '
80 git -C r2 rev-list HEAD --objects >revs &&
81 awk -f print_1.awk revs |
82 sort >expected &&
83
84 git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 >revs &&
85 awk -f print_1.awk revs |
86 sed "s/~//" |
87 sort >observed &&
88
89 test_cmp expected observed
90 '
91
92 test_expect_success 'verify blob:limit=1000' '
93 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
94 awk -f print_2.awk ls_files_result |
95 sort >expected &&
96
97 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 >revs &&
98 awk -f print_1.awk revs |
99 sed "s/~//" |
100 sort >observed &&
101
102 test_cmp expected observed
103 '
104
105 test_expect_success 'verify blob:limit=1001' '
106 git -C r2 ls-files -s large.10000 >ls_files_result &&
107 awk -f print_2.awk ls_files_result |
108 sort >expected &&
109
110 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 >revs &&
111 awk -f print_1.awk revs |
112 sed "s/~//" |
113 sort >observed &&
114
115 test_cmp expected observed
116 '
117
118 test_expect_success 'verify blob:limit=1k' '
119 git -C r2 ls-files -s large.10000 >ls_files_result &&
120 awk -f print_2.awk ls_files_result |
121 sort >expected &&
122
123 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k >revs &&
124 awk -f print_1.awk revs |
125 sed "s/~//" |
126 sort >observed &&
127
128 test_cmp expected observed
129 '
130
131 test_expect_success 'verify blob:limit=1m' '
132 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m >revs &&
133 awk -f print_1.awk revs |
134 sed "s/~//" |
135 sort >observed &&
136
137 test_must_be_empty observed
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
145 test_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
160 test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
161 git -C r3 ls-files -s sparse1 sparse2 >ls_files_result &&
162 awk -f print_2.awk ls_files_result |
163 sort >expected &&
164
165 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 >revs &&
166 awk -f print_1.awk revs |
167 sed "s/~//" |
168 sort >observed &&
169
170 test_cmp expected observed
171 '
172
173 test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
174 git -C r3 ls-files -s sparse2 dir1/sparse2 >ls_files_result &&
175 awk -f print_2.awk ls_files_result |
176 sort >expected &&
177
178 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 >revs &&
179 awk -f print_1.awk revs |
180 sed "s/~//" |
181 sort >observed &&
182
183 test_cmp expected observed
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
190 test_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
196 test_expect_success 'verify sparse:oid=OID omits top-level files' '
197 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
198 awk -f print_2.awk ls_files_result |
199 sort >expected &&
200
201 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
202
203 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid >revs &&
204 awk -f print_1.awk revs |
205 sed "s/~//" |
206 sort >observed &&
207
208 test_cmp expected observed
209 '
210
211 test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
212 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
213 awk -f print_2.awk ls_files_result |
214 sort >expected &&
215
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 |
218 sed "s/~//" |
219 sort >observed &&
220
221 test_cmp expected observed
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
227 test_expect_success 'rev-list W/ --missing=print' '
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 |
231 sort >expected &&
232
233 for id in `cat expected | sed "s|..|&/|"`
234 do
235 rm r1/.git/objects/$id
236 done &&
237
238 git -C r1 rev-list --quiet HEAD --missing=print --objects >revs &&
239 awk -f print_1.awk revs |
240 sed "s/?//" |
241 sort >observed &&
242
243 test_cmp expected observed
244 '
245
246 test_expect_success 'rev-list W/O --missing fails' '
247 test_must_fail git -C r1 rev-list --quiet --objects HEAD
248 '
249
250 test_expect_success 'rev-list W/ missing=allow-any' '
251 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
252 '
253
254 test_done