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 \
24 | awk -f print_2.awk \
26 git -C r1 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:none \
27 | awk -f print_1.awk \
30 test_cmp observed expected
33 test_expect_success
'specify blob explicitly prevents filtering' '
34 file_3=$(git -C r1 ls-files -s file.3 |
35 awk -f print_2.awk) &&
37 file_4=$(git -C r1 ls-files -s file.4 |
38 awk -f print_2.awk) &&
40 git -C r1 rev-list --objects --filter=blob:none HEAD $file_3 >observed &&
41 grep -q "$file_3" observed &&
42 test_must_fail grep -q "$file_4" observed
45 test_expect_success
'verify emitted+omitted == all' '
46 git -C r1 rev-list HEAD --objects \
47 | awk -f print_1.awk \
49 git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
50 | awk -f print_1.awk \
53 test_cmp observed expected
57 # Test blob:limit=<n>[kmg] filter.
58 # We boundary test around the size parameter. The filter is strictly less than
59 # the value, so size 500 and 1000 should have the same results, but 1001 should
62 test_expect_success
'setup r2' '
66 printf "%"$n"s" X > r2/large.$n
67 git -C r2 add large.$n
68 git -C r2 commit -m "$n"
72 test_expect_success
'verify blob:limit=500 omits all blobs' '
73 git -C r2 ls-files -s large.1000 large.10000 \
74 | awk -f print_2.awk \
76 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 \
77 | awk -f print_1.awk \
80 test_cmp observed expected
83 test_expect_success
'verify emitted+omitted == all' '
84 git -C r2 rev-list HEAD --objects \
85 | awk -f print_1.awk \
87 git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 \
88 | awk -f print_1.awk \
91 test_cmp observed expected
94 test_expect_success
'verify blob:limit=1000' '
95 git -C r2 ls-files -s large.1000 large.10000 \
96 | awk -f print_2.awk \
98 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 \
99 | awk -f print_1.awk \
102 test_cmp observed expected
105 test_expect_success
'verify blob:limit=1001' '
106 git -C r2 ls-files -s large.10000 \
107 | awk -f print_2.awk \
109 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 \
110 | awk -f print_1.awk \
113 test_cmp observed expected
116 test_expect_success
'verify blob:limit=1k' '
117 git -C r2 ls-files -s large.10000 \
118 | awk -f print_2.awk \
120 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k \
121 | awk -f print_1.awk \
124 test_cmp observed expected
127 test_expect_success
'verify blob:limit=1m' '
128 cat </dev/null >expected &&
129 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
130 | awk -f print_1.awk \
133 test_cmp observed expected
136 # Test sparse:path=<path> filter.
137 # Use a local file containing a sparse-checkout specification to filter
138 # out blobs not required for the corresponding sparse-checkout. We do not
139 # require sparse-checkout to actually be enabled.
141 test_expect_success
'setup r3' '
144 for n in sparse1 sparse2
146 echo "This is file: $n" > r3/$n
148 echo "This is file: dir1/$n" > r3/dir1/$n
149 git -C r3 add dir1/$n
151 git -C r3 commit -m "sparse" &&
152 echo dir1/ >pattern1 &&
153 echo sparse1 >pattern2
156 test_expect_success
'verify sparse:path=pattern1 omits top-level files' '
157 git -C r3 ls-files -s sparse1 sparse2 \
158 | awk -f print_2.awk \
160 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
161 | awk -f print_1.awk \
164 test_cmp observed expected
167 test_expect_success
'verify sparse:path=pattern2 omits both sparse2 files' '
168 git -C r3 ls-files -s sparse2 dir1/sparse2 \
169 | awk -f print_2.awk \
171 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
172 | awk -f print_1.awk \
175 test_cmp observed expected
178 # Test sparse:oid=<oid-ish> filter.
179 # Like sparse:path, but we get the sparse-checkout specification from
180 # a blob rather than a file on disk.
182 test_expect_success
'setup r3 part 2' '
183 echo dir1/ >r3/pattern &&
184 git -C r3 add pattern &&
185 git -C r3 commit -m "pattern"
188 test_expect_success
'verify sparse:oid=OID omits top-level files' '
189 git -C r3 ls-files -s pattern sparse1 sparse2 \
190 | awk -f print_2.awk \
192 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
193 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
194 | awk -f print_1.awk \
197 test_cmp observed expected
200 test_expect_success
'verify sparse:oid=oid-ish omits top-level files' '
201 git -C r3 ls-files -s pattern sparse1 sparse2 \
202 | awk -f print_2.awk \
204 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
205 | awk -f print_1.awk \
208 test_cmp observed expected
211 test_expect_success
'rev-list W/ --missing=print and --missing=allow-any for trees' '
212 TREE=$(git -C r3 rev-parse HEAD:dir1) &&
214 # Create a spare repo because we will be deleting objects from this one.
217 rm r3.b/.git/objects/$(echo $TREE | sed "s|^..|&/|") &&
219 git -C r3.b rev-list --quiet --missing=print --objects HEAD \
220 >missing_objs 2>rev_list_err &&
221 echo "?$TREE" >expected &&
222 test_cmp expected missing_objs &&
224 # do not complain when a missing tree cannot be parsed
225 test_must_be_empty rev_list_err &&
227 git -C r3.b rev-list --missing=allow-any --objects HEAD \
228 >objs 2>rev_list_err &&
230 test_must_be_empty rev_list_err
233 # Test tree:0 filter.
235 test_expect_success
'verify tree:0 includes trees in "filtered" output' '
236 git -C r3 rev-list --quiet --objects --filter-print-omitted \
237 --filter=tree:0 HEAD >revs &&
239 awk -f print_1.awk revs |
241 xargs -n1 git -C r3 cat-file -t >unsorted_filtered_types &&
243 sort -u unsorted_filtered_types >filtered_types &&
244 printf "blob\ntree\n" >expected &&
245 test_cmp expected filtered_types
248 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
249 # This models previously omitted objects that we did not receive.
251 test_expect_success
'rev-list W/ --missing=print' '
252 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
253 | awk -f print_2.awk \
255 for id in `cat expected | sed "s|..|&/|"`
257 rm r1/.git/objects/$id
259 git -C r1 rev-list --quiet HEAD --missing=print --objects \
260 | awk -f print_1.awk \
263 test_cmp observed expected
266 test_expect_success
'rev-list W/O --missing fails' '
267 test_must_fail git -C r1 rev-list --quiet --objects HEAD
270 test_expect_success
'rev-list W/ missing=allow-any' '
271 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD