3 test_description='git rev-list using object filtering'
7 # Test the blob:none filter.
9 test_expect_success 'setup r1' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
16 echo "This is file: $n" > r1/file.$n
18 git -C r1 commit -m "$n"
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 \
25 awk -f print_2.awk ls_files_result |
28 git -C r1 rev-list --quiet --objects --filter-print-omitted \
29 --filter=blob:none HEAD >revs &&
30 awk -f print_1.awk revs |
34 test_cmp expected observed
37 test_expect_success 'specify blob explicitly prevents filtering' '
38 file_3=$(git -C r1 ls-files -s file.3 |
39 awk -f print_2.awk) &&
41 file_4=$(git -C r1 ls-files -s file.4 |
42 awk -f print_2.awk) &&
44 git -C r1 rev-list --objects --filter=blob:none HEAD $file_3 >observed &&
45 grep "$file_3" observed &&
46 ! grep "$file_4" observed
49 test_expect_success 'verify emitted+omitted == all' '
50 git -C r1 rev-list --objects HEAD >revs &&
51 awk -f print_1.awk revs |
54 git -C r1 rev-list --objects --filter-print-omitted --filter=blob:none \
56 awk -f print_1.awk revs |
60 test_cmp expected observed
64 # Test blob:limit=<n>[kmg] filter.
65 # We boundary test around the size parameter. The filter is strictly less than
66 # the value, so size 500 and 1000 should have the same results, but 1001 should
69 test_expect_success 'setup r2' '
73 printf "%"$n"s" X > r2/large.$n
74 git -C r2 add large.$n
75 git -C r2 commit -m "$n"
79 test_expect_success 'verify blob:limit=500 omits all blobs' '
80 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
81 awk -f print_2.awk ls_files_result |
84 git -C r2 rev-list --quiet --objects --filter-print-omitted \
85 --filter=blob:limit=500 HEAD >revs &&
86 awk -f print_1.awk revs |
90 test_cmp expected observed
93 test_expect_success 'verify emitted+omitted == all' '
94 git -C r2 rev-list --objects HEAD >revs &&
95 awk -f print_1.awk revs |
98 git -C r2 rev-list --objects --filter-print-omitted \
99 --filter=blob:limit=500 HEAD >revs &&
100 awk -f print_1.awk revs |
104 test_cmp expected observed
107 test_expect_success 'verify blob:limit=1000' '
108 git -C r2 ls-files -s large.1000 large.10000 >ls_files_result &&
109 awk -f print_2.awk ls_files_result |
112 git -C r2 rev-list --quiet --objects --filter-print-omitted \
113 --filter=blob:limit=1000 HEAD >revs &&
114 awk -f print_1.awk revs |
118 test_cmp expected observed
121 test_expect_success 'verify blob:limit=1001' '
122 git -C r2 ls-files -s large.10000 >ls_files_result &&
123 awk -f print_2.awk ls_files_result |
126 git -C r2 rev-list --quiet --objects --filter-print-omitted \
127 --filter=blob:limit=1001 HEAD >revs &&
128 awk -f print_1.awk revs |
132 test_cmp expected observed
135 test_expect_success 'verify blob:limit=1k' '
136 git -C r2 ls-files -s large.10000 >ls_files_result &&
137 awk -f print_2.awk ls_files_result |
140 git -C r2 rev-list --quiet --objects --filter-print-omitted \
141 --filter=blob:limit=1k HEAD >revs &&
142 awk -f print_1.awk revs |
146 test_cmp expected observed
149 test_expect_success 'verify blob:limit=1m' '
150 git -C r2 rev-list --quiet --objects --filter-print-omitted \
151 --filter=blob:limit=1m HEAD >revs &&
152 awk -f print_1.awk revs |
156 test_must_be_empty observed
159 # Test sparse:path=<path> filter.
160 # Use a local file containing a sparse-checkout specification to filter
161 # out blobs not required for the corresponding sparse-checkout. We do not
162 # require sparse-checkout to actually be enabled.
164 test_expect_success 'setup r3' '
167 for n in sparse1 sparse2
169 echo "This is file: $n" > r3/$n
171 echo "This is file: dir1/$n" > r3/dir1/$n
172 git -C r3 add dir1/$n
174 git -C r3 commit -m "sparse" &&
175 echo dir1/ >pattern1 &&
176 echo sparse1 >pattern2
179 test_expect_success 'verify sparse:path=pattern1 omits top-level files' '
180 git -C r3 ls-files -s sparse1 sparse2 >ls_files_result &&
181 awk -f print_2.awk ls_files_result |
184 git -C r3 rev-list --quiet --objects --filter-print-omitted \
185 --filter=sparse:path=../pattern1 HEAD >revs &&
186 awk -f print_1.awk revs |
190 test_cmp expected observed
193 test_expect_success 'verify sparse:path=pattern2 omits both sparse2 files' '
194 git -C r3 ls-files -s sparse2 dir1/sparse2 >ls_files_result &&
195 awk -f print_2.awk ls_files_result |
198 git -C r3 rev-list --quiet --objects --filter-print-omitted \
199 --filter=sparse:path=../pattern2 HEAD >revs &&
200 awk -f print_1.awk revs |
204 test_cmp expected observed
207 # Test sparse:oid=<oid-ish> filter.
208 # Like sparse:path, but we get the sparse-checkout specification from
209 # a blob rather than a file on disk.
211 test_expect_success 'setup r3 part 2' '
212 echo dir1/ >r3/pattern &&
213 git -C r3 add pattern &&
214 git -C r3 commit -m "pattern"
217 test_expect_success 'verify sparse:oid=OID omits top-level files' '
218 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
219 awk -f print_2.awk ls_files_result |
222 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
224 git -C r3 rev-list --quiet --objects --filter-print-omitted \
225 --filter=sparse:oid=$oid HEAD >revs &&
226 awk -f print_1.awk revs |
230 test_cmp expected observed
233 test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
234 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
235 awk -f print_2.awk ls_files_result |
238 git -C r3 rev-list --quiet --objects --filter-print-omitted \
239 --filter=sparse:oid=master:pattern HEAD >revs &&
240 awk -f print_1.awk revs |
244 test_cmp expected observed
247 test_expect_success 'rev-list W/ --missing=print and --missing=allow-any for trees' '
248 TREE=$(git -C r3 rev-parse HEAD:dir1) &&
250 # Create a spare repo because we will be deleting objects from this one.
253 rm r3.b/.git/objects/$(echo $TREE | sed "s|^..|&/|") &&
255 git -C r3.b rev-list --quiet --missing=print --objects HEAD \
256 >missing_objs 2>rev_list_err &&
257 echo "?$TREE" >expected &&
258 test_cmp expected missing_objs &&
260 # do not complain when a missing tree cannot be parsed
261 test_must_be_empty rev_list_err &&
263 git -C r3.b rev-list --missing=allow-any --objects HEAD \
264 >objs 2>rev_list_err &&
266 test_must_be_empty rev_list_err
269 # Test tree:0 filter.
271 test_expect_success 'verify tree:0 includes trees in "filtered" output' '
272 git -C r3 rev-list --quiet --objects --filter-print-omitted \
273 --filter=tree:0 HEAD >revs &&
275 awk -f print_1.awk revs |
277 xargs -n1 git -C r3 cat-file -t >unsorted_filtered_types &&
279 sort -u unsorted_filtered_types >filtered_types &&
280 test_write_lines blob tree >expected &&
281 test_cmp expected filtered_types
284 # Make sure tree:0 does not iterate through any trees.
286 test_expect_success 'filter a GIANT tree through tree:0' '
287 GIT_TRACE=1 git -C r3 rev-list \
288 --objects --filter=tree:0 HEAD 2>filter_trace &&
289 grep "Skipping contents of tree [.][.][.]" filter_trace >actual &&
290 # One line for each commit traversed.
291 test_line_count = 2 actual &&
293 # Make sure no other trees were considered besides the root.
294 ! grep "Skipping contents of tree [^.]" filter_trace
297 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
298 # This models previously omitted objects that we did not receive.
300 test_expect_success 'rev-list W/ --missing=print' '
301 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
303 awk -f print_2.awk ls_files_result |
306 for id in `cat expected | sed "s|..|&/|"`
308 rm r1/.git/objects/$id
311 git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&
312 awk -f print_1.awk revs |
316 test_cmp expected observed
319 test_expect_success 'rev-list W/O --missing fails' '
320 test_must_fail git -C r1 rev-list --quiet --objects HEAD
323 test_expect_success 'rev-list W/ missing=allow-any' '
324 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD