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
'verify emitted+omitted == all' '
34 git -C r1 rev-list HEAD --objects \
35 | awk -f print_1.awk \
37 git -C r1 rev-list HEAD --objects --filter-print-omitted --filter=blob:none \
38 | awk -f print_1.awk \
41 test_cmp observed expected
45 # Test blob:limit=<n>[kmg] filter.
46 # We boundary test around the size parameter. The filter is strictly less than
47 # the value, so size 500 and 1000 should have the same results, but 1001 should
50 test_expect_success
'setup r2' '
54 printf "%"$n"s" X > r2/large.$n
55 git -C r2 add large.$n
56 git -C r2 commit -m "$n"
60 test_expect_success
'verify blob:limit=500 omits all blobs' '
61 git -C r2 ls-files -s large.1000 large.10000 \
62 | awk -f print_2.awk \
64 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=500 \
65 | awk -f print_1.awk \
68 test_cmp observed expected
71 test_expect_success
'verify emitted+omitted == all' '
72 git -C r2 rev-list HEAD --objects \
73 | awk -f print_1.awk \
75 git -C r2 rev-list HEAD --objects --filter-print-omitted --filter=blob:limit=500 \
76 | awk -f print_1.awk \
79 test_cmp observed expected
82 test_expect_success
'verify blob:limit=1000' '
83 git -C r2 ls-files -s large.1000 large.10000 \
84 | awk -f print_2.awk \
86 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1000 \
87 | awk -f print_1.awk \
90 test_cmp observed expected
93 test_expect_success
'verify blob:limit=1001' '
94 git -C r2 ls-files -s large.10000 \
95 | awk -f print_2.awk \
97 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1001 \
98 | awk -f print_1.awk \
101 test_cmp observed expected
104 test_expect_success
'verify blob:limit=1k' '
105 git -C r2 ls-files -s large.10000 \
106 | awk -f print_2.awk \
108 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1k \
109 | awk -f print_1.awk \
112 test_cmp observed expected
115 test_expect_success
'verify blob:limit=1m' '
116 cat </dev/null >expected &&
117 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
118 | awk -f print_1.awk \
121 test_cmp observed expected
124 # Test sparse:path=<path> filter.
125 # Use a local file containing a sparse-checkout specification to filter
126 # out blobs not required for the corresponding sparse-checkout. We do not
127 # require sparse-checkout to actually be enabled.
129 test_expect_success
'setup r3' '
132 for n in sparse1 sparse2
134 echo "This is file: $n" > r3/$n
136 echo "This is file: dir1/$n" > r3/dir1/$n
137 git -C r3 add dir1/$n
139 git -C r3 commit -m "sparse" &&
140 echo dir1/ >pattern1 &&
141 echo sparse1 >pattern2
144 test_expect_success
'verify sparse:path=pattern1 omits top-level files' '
145 git -C r3 ls-files -s sparse1 sparse2 \
146 | awk -f print_2.awk \
148 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
149 | awk -f print_1.awk \
152 test_cmp observed expected
155 test_expect_success
'verify sparse:path=pattern2 omits both sparse2 files' '
156 git -C r3 ls-files -s sparse2 dir1/sparse2 \
157 | awk -f print_2.awk \
159 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
160 | awk -f print_1.awk \
163 test_cmp observed expected
166 # Test sparse:oid=<oid-ish> filter.
167 # Like sparse:path, but we get the sparse-checkout specification from
168 # a blob rather than a file on disk.
170 test_expect_success
'setup r3 part 2' '
171 echo dir1/ >r3/pattern &&
172 git -C r3 add pattern &&
173 git -C r3 commit -m "pattern"
176 test_expect_success
'verify sparse:oid=OID omits top-level files' '
177 git -C r3 ls-files -s pattern sparse1 sparse2 \
178 | awk -f print_2.awk \
180 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
181 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
182 | awk -f print_1.awk \
185 test_cmp observed expected
188 test_expect_success
'verify sparse:oid=oid-ish omits top-level files' '
189 git -C r3 ls-files -s pattern sparse1 sparse2 \
190 | awk -f print_2.awk \
192 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
193 | awk -f print_1.awk \
196 test_cmp observed expected
199 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
200 # This models previously omitted objects that we did not receive.
202 test_expect_success
'rev-list W/ --missing=print' '
203 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
204 | awk -f print_2.awk \
206 for id in `cat expected | sed "s|..|&/|"`
208 rm r1/.git/objects/$id
210 git -C r1 rev-list --quiet HEAD --missing=print --objects \
211 | awk -f print_1.awk \
214 test_cmp observed expected
217 test_expect_success
'rev-list W/O --missing fails' '
218 test_must_fail git -C r1 rev-list --quiet --objects HEAD
221 test_expect_success
'rev-list W/ missing=allow-any' '
222 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD