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 git -C r2 rev-list HEAD --quiet --objects --filter-print-omitted --filter=blob:limit=1m \
117 | awk -f print_1.awk \
120 test_must_be_empty observed
123 # Test sparse:path=<path> filter.
124 # Use a local file containing a sparse-checkout specification to filter
125 # out blobs not required for the corresponding sparse-checkout. We do not
126 # require sparse-checkout to actually be enabled.
128 test_expect_success
'setup r3' '
131 for n in sparse1 sparse2
133 echo "This is file: $n" > r3/$n
135 echo "This is file: dir1/$n" > r3/dir1/$n
136 git -C r3 add dir1/$n
138 git -C r3 commit -m "sparse" &&
139 echo dir1/ >pattern1 &&
140 echo sparse1 >pattern2
143 test_expect_success
'verify sparse:path=pattern1 omits top-level files' '
144 git -C r3 ls-files -s sparse1 sparse2 \
145 | awk -f print_2.awk \
147 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern1 \
148 | awk -f print_1.awk \
151 test_cmp observed expected
154 test_expect_success
'verify sparse:path=pattern2 omits both sparse2 files' '
155 git -C r3 ls-files -s sparse2 dir1/sparse2 \
156 | awk -f print_2.awk \
158 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:path=../pattern2 \
159 | awk -f print_1.awk \
162 test_cmp observed expected
165 # Test sparse:oid=<oid-ish> filter.
166 # Like sparse:path, but we get the sparse-checkout specification from
167 # a blob rather than a file on disk.
169 test_expect_success
'setup r3 part 2' '
170 echo dir1/ >r3/pattern &&
171 git -C r3 add pattern &&
172 git -C r3 commit -m "pattern"
175 test_expect_success
'verify sparse:oid=OID omits top-level files' '
176 git -C r3 ls-files -s pattern sparse1 sparse2 \
177 | awk -f print_2.awk \
179 oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) &&
180 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=$oid \
181 | awk -f print_1.awk \
184 test_cmp observed expected
187 test_expect_success
'verify sparse:oid=oid-ish omits top-level files' '
188 git -C r3 ls-files -s pattern sparse1 sparse2 \
189 | awk -f print_2.awk \
191 git -C r3 rev-list HEAD --quiet --objects --filter-print-omitted --filter=sparse:oid=master:pattern \
192 | awk -f print_1.awk \
195 test_cmp observed expected
198 # Delete some loose objects and use rev-list, but WITHOUT any filtering.
199 # This models previously omitted objects that we did not receive.
201 test_expect_success
'rev-list W/ --missing=print' '
202 git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \
203 | awk -f print_2.awk \
205 for id in `cat expected | sed "s|..|&/|"`
207 rm r1/.git/objects/$id
209 git -C r1 rev-list --quiet HEAD --missing=print --objects \
210 | awk -f print_1.awk \
213 test_cmp observed expected
216 test_expect_success
'rev-list W/O --missing fails' '
217 test_must_fail git -C r1 rev-list --quiet --objects HEAD
220 test_expect_success
'rev-list W/ missing=allow-any' '
221 git -C r1 rev-list --quiet --missing=allow-any --objects HEAD