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.
161 # NOTE: sparse:path filter support has been dropped for security reasons,
162 # so the tests have been changed to make sure that using it fails.
164 # Use a local file containing a sparse-checkout specification to filter
165 # out blobs not required for the corresponding sparse-checkout. We do not
166 # require sparse-checkout to actually be enabled.
168 test_expect_success 'setup r3' '
171 for n in sparse1 sparse2
173 echo "This is file: $n" > r3/$n
175 echo "This is file: dir1/$n" > r3/dir1/$n
176 git -C r3 add dir1/$n
178 git -C r3 commit -m "sparse" &&
179 echo dir1/ >pattern1 &&
180 echo sparse1 >pattern2
183 test_expect_success 'verify sparse:path=pattern1 fails' '
184 test_must_fail git -C r3 rev-list --quiet --objects \
185 --filter-print-omitted --filter=sparse:path=../pattern1 HEAD
188 test_expect_success 'verify sparse:path=pattern2 fails' '
189 test_must_fail git -C r3 rev-list --quiet --objects \
190 --filter-print-omitted --filter=sparse:path=../pattern2 HEAD
193 # Test sparse:oid=<oid-ish> filter.
194 # Use a blob containing a sparse-checkout specification to filter
195 # out blobs not required for the corresponding sparse-checkout. We do not
196 # require sparse-checkout to actually be enabled.
198 test_expect_success 'setup r3 part 2' '
199 echo dir1/ >r3/pattern &&
200 git -C r3 add pattern &&
201 git -C r3 commit -m "pattern"
204 test_expect_success 'verify sparse:oid=OID omits top-level files' '
205 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
206 awk -f print_2.awk ls_files_result |
209 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
211 git -C r3 rev-list --quiet --objects --filter-print-omitted \
212 --filter=sparse:oid=$oid HEAD >revs &&
213 awk -f print_1.awk revs |
217 test_cmp expected observed
220 test_expect_success 'verify sparse:oid=oid-ish omits top-level files' '
221 git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result &&
222 awk -f print_2.awk ls_files_result |
225 git -C r3 rev-list --quiet --objects --filter-print-omitted \
226 --filter=sparse:oid=master:pattern HEAD >revs &&
227 awk -f print_1.awk revs |
231 test_cmp expected observed
234 test_expect_success 'rev-list W/ --missing=print and --missing=allow-any for trees' '
235 TREE=$(git -C r3 rev-parse HEAD:dir1) &&
237 # Create a spare repo because we will be deleting objects from this one.
240 rm r3.b/.git/objects/$(echo $TREE | sed "s|^..|&/|") &&
242 git -C r3.b rev-list --quiet --missing=print --objects HEAD \
243 >missing_objs 2>rev_list_err &&
244 echo "?$TREE" >expected &&
245 test_cmp expected missing_objs &&
247 # do not complain when a missing tree cannot be parsed
248 test_must_be_empty rev_list_err &&
250 git -C r3.b rev-list --missing=allow-any --objects HEAD \
251 >objs 2>rev_list_err &&
253 test_must_be_empty rev_list_err
256 # Test tree:0 filter.
258 test_expect_success 'verify tree:0 includes trees in "filtered" output' '
259 git -C r3 rev-list --quiet --objects --filter-print-omitted \
260 --filter=tree:0 HEAD >revs &&
262 awk -f print_1.awk revs |
264 xargs -n1 git -C r3 cat-file -t >unsorted_filtered_types &&
266 sort -u unsorted_filtered_types >filtered_types &&
267 test_write_lines blob tree >expected &&
268 test_cmp expected filtered_types
271 # Make sure tree:0 does not iterate through any trees.
273 test_expect_success 'verify skipping tree iteration when not collecting omits' '
274 GIT_TRACE=1 git -C r3 rev-list \
275 --objects --filter=tree:0 HEAD 2>filter_trace &&
276 grep "Skipping contents of tree [.][.][.]" filter_trace >actual &&
277 # One line for each commit traversed.
278 test_line_count = 2 actual &&
280 # Make sure no other trees were considered besides the root.
281 ! grep "Skipping contents of tree [^.]" filter_trace
284 # Test tree:# filters.
290 hash=$(git -C r3 rev-parse $commit:$name) &&
291 grep "^$hash $name$" actual
294 test_expect_success 'verify tree:1 includes root trees' '
295 git -C r3 rev-list --objects --filter=tree:1 HEAD >actual &&
297 # We should get two root directories and two commits.
298 expect_has HEAD "" &&
299 expect_has HEAD~1 "" &&
300 test_line_count = 4 actual
303 test_expect_success 'verify tree:2 includes root trees and immediate children' '
304 git -C r3 rev-list --objects --filter=tree:2 HEAD >actual &&
306 expect_has HEAD "" &&
307 expect_has HEAD~1 "" &&
308 expect_has HEAD dir1 &&
309 expect_has HEAD pattern &&
310 expect_has HEAD sparse1 &&
311 expect_has HEAD sparse2 &&
313 # There are also 2 commit objects
314 test_line_count = 8 actual
317 test_expect_success 'verify tree:3 includes everything expected' '
318 git -C r3 rev-list --objects --filter=tree:3 HEAD >actual &&
320 expect_has HEAD "" &&
321 expect_has HEAD~1 "" &&
322 expect_has HEAD dir1 &&
323 expect_has HEAD dir1/sparse1 &&
324 expect_has HEAD dir1/sparse2 &&
325 expect_has HEAD pattern &&
326 expect_has HEAD sparse1 &&
327 expect_has HEAD sparse2 &&
329 # There are also 2 commit objects
330 test_line_count = 10 actual
333 # Test provisional omit collection logic with a repo that has objects appearing
334 # at multiple depths - first deeper than the filter's threshold, then shallow.
336 test_expect_success 'setup r4' '
341 echo bar > r4/subdir/bar &&
344 cp -r r4/foo r4/subdir r4/filt &&
346 git -C r4 add foo subdir filt &&
347 git -C r4 commit -m "commit msg"
350 expect_has_with_different_name () {
354 hash=$(git -C $repo rev-parse HEAD:$name) &&
355 ! grep "^$hash $name$" actual &&
356 grep "^$hash " actual &&
357 ! grep "~$hash" actual
360 test_expect_success 'test tree:# filter provisional omit for blob and tree' '
361 git -C r4 rev-list --objects --filter-print-omitted --filter=tree:2 \
363 expect_has_with_different_name r4 filt/foo &&
364 expect_has_with_different_name r4 filt/subdir
367 test_expect_success 'verify skipping tree iteration when collecting omits' '
368 GIT_TRACE=1 git -C r4 rev-list --filter-print-omitted \
369 --objects --filter=tree:0 HEAD 2>filter_trace &&
370 grep "^Skipping contents of tree " filter_trace >actual &&
372 echo "Skipping contents of tree subdir/..." >expect &&
373 test_cmp expect actual
376 # Test tree:<depth> where a tree is iterated to twice - once where a subentry is
377 # too deep to be included, and again where the blob inside it is shallow enough
378 # to be included. This makes sure we don't use LOFR_MARK_SEEN incorrectly (we
379 # can't use it because a tree can be iterated over again at a lower depth).
381 test_expect_success 'tree:<depth> where we iterate over tree at two levels' '
384 mkdir -p r5/a/subdir/b &&
385 echo foo > r5/a/subdir/b/foo &&
387 mkdir -p r5/subdir/b &&
388 echo foo > r5/subdir/b/foo &&
390 git -C r5 add a subdir &&
391 git -C r5 commit -m "commit msg" &&
393 git -C r5 rev-list --objects --filter=tree:4 HEAD >actual &&
394 expect_has_with_different_name r5 a/subdir/b/foo
397 test_expect_success 'tree:<depth> which filters out blob but given as arg' '
398 blob_hash=$(git -C r4 rev-parse HEAD:subdir/bar) &&
400 git -C r4 rev-list --objects --filter=tree:1 HEAD $blob_hash >actual &&
401 grep ^$blob_hash actual
404 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
405 # This models previously omitted objects that we did not receive.
407 test_expect_success 'rev-list W/ --missing=print' '
408 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
410 awk -f print_2.awk ls_files_result |
413 for id in `cat expected | sed "s|..|&/|"`
415 rm r1/.git/objects/$id
418 git -C r1 rev-list --quiet --missing=print --objects HEAD >revs &&
419 awk -f print_1.awk revs |
423 test_cmp expected observed
426 test_expect_success 'rev-list W/O --missing fails' '
427 test_must_fail git -C r1 rev-list --quiet --objects HEAD
430 test_expect_success 'rev-list W/ missing=allow-any' '
431 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD
434 # Test expansion of filter specs.
436 test_expect_success 'expand blob limit in protocol' '
437 git -C r2 config --local uploadpack.allowfilter 1 &&
438 GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 clone \
439 --filter=blob:limit=1k "file://$(pwd)/r2" limit &&
440 ! grep "blob:limit=1k" trace &&
441 grep "blob:limit=1024" trace
444 test_expect_success 'expand tree depth limit in protocol' '
445 GIT_TRACE_PACKET="$(pwd)/tree_trace" git -c protocol.version=2 clone \
446 --filter=tree:0k "file://$(pwd)/r2" tree &&
447 ! grep "tree:0k" tree_trace &&
448 grep "tree:0" tree_trace