@@ -215,6 +215,104 @@ test_expect_success 'upload-pack respects config using protocol v2' '
215
215
test_path_is_file server/.git/hookout
216
216
'
217
217
218
+ test_expect_success ' setup filter tests' '
219
+ rm -rf server client &&
220
+ git init server &&
221
+
222
+ # 1 commit to create a file, and 1 commit to modify it
223
+ test_commit -C server message1 a.txt &&
224
+ test_commit -C server message2 a.txt &&
225
+ git -C server config protocol.version 2 &&
226
+ git -C server config uploadpack.allowfilter 1 &&
227
+ git -C server config uploadpack.allowanysha1inwant 1 &&
228
+ git -C server config protocol.version 2
229
+ '
230
+
231
+ test_expect_success ' partial clone' '
232
+ GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
233
+ clone --filter=blob:none "file://$(pwd)/server" client &&
234
+ grep "version 2" trace &&
235
+
236
+ # Ensure that the old version of the file is missing
237
+ git -C client rev-list master --quiet --objects --missing=print \
238
+ >observed.oids &&
239
+ grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
240
+
241
+ # Ensure that client passes fsck
242
+ git -C client fsck
243
+ '
244
+
245
+ test_expect_success ' dynamically fetch missing object' '
246
+ rm "$(pwd)/trace" &&
247
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
248
+ cat-file -p $(git -C server rev-parse message1:a.txt) &&
249
+ grep "version 2" trace
250
+ '
251
+
252
+ test_expect_success ' partial fetch' '
253
+ rm -rf client "$(pwd)/trace" &&
254
+ git init client &&
255
+ SERVER="file://$(pwd)/server" &&
256
+ test_config -C client extensions.partialClone "$SERVER" &&
257
+
258
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
259
+ fetch --filter=blob:none "$SERVER" master:refs/heads/other &&
260
+ grep "version 2" trace &&
261
+
262
+ # Ensure that the old version of the file is missing
263
+ git -C client rev-list other --quiet --objects --missing=print \
264
+ >observed.oids &&
265
+ grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
266
+
267
+ # Ensure that client passes fsck
268
+ git -C client fsck
269
+ '
270
+
271
+ test_expect_success ' do not advertise filter if not configured to do so' '
272
+ SERVER="file://$(pwd)/server" &&
273
+
274
+ rm "$(pwd)/trace" &&
275
+ git -C server config uploadpack.allowfilter 1 &&
276
+ GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
277
+ ls-remote "$SERVER" &&
278
+ grep "fetch=.*filter" trace &&
279
+
280
+ rm "$(pwd)/trace" &&
281
+ git -C server config uploadpack.allowfilter 0 &&
282
+ GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 \
283
+ ls-remote "$SERVER" &&
284
+ grep "fetch=" trace >fetch_capabilities &&
285
+ ! grep filter fetch_capabilities
286
+ '
287
+
288
+ test_expect_success ' partial clone warns if filter is not advertised' '
289
+ rm -rf client &&
290
+ git -C server config uploadpack.allowfilter 0 &&
291
+ git -c protocol.version=2 \
292
+ clone --filter=blob:none "file://$(pwd)/server" client 2>err &&
293
+ test_i18ngrep "filtering not recognized by server, ignoring" err
294
+ '
295
+
296
+ test_expect_success ' even with handcrafted request, filter does not work if not advertised' '
297
+ git -C server config uploadpack.allowfilter 0 &&
298
+
299
+ # Custom request that tries to filter even though it is not advertised.
300
+ test-pkt-line pack >in <<-EOF &&
301
+ command=fetch
302
+ 0001
303
+ want $(git -C server rev-parse master)
304
+ filter blob:none
305
+ 0000
306
+ EOF
307
+
308
+ test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
309
+ grep "unexpected line: .filter blob:none." err &&
310
+
311
+ # Exercise to ensure that if advertised, filter works
312
+ git -C server config uploadpack.allowfilter 1 &&
313
+ git -C server serve --stateless-rpc <in >/dev/null
314
+ '
315
+
218
316
# Test protocol v2 with 'http://' transport
219
317
#
220
318
. " $TEST_DIRECTORY " /lib-httpd.sh
0 commit comments