296
test_i18ngrep "unable to parse sparse filter data in" err
297
'
298
299
+setup_triangle () {
300
+ rm -rf big-blob.txt server client promisor-remote &&
301
+
302
+ printf "line %d\n" $(test_seq 1 100) >big-blob.txt &&
303
+
304
+ # Create a server with 2 commits: a commit with a big blob and a child
305
+ # commit with an incremental change. Also, create a partial clone
306
+ # client that only contains the first commit.
307
+ git init server &&
308
+ git -C server config --local uploadpack.allowfilter 1 &&
309
+ cp big-blob.txt server &&
310
+ git -C server add big-blob.txt &&
311
+ git -C server commit -m "initial" &&
312
+ git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
313
+ echo another line >>server/big-blob.txt &&
314
+ git -C server commit -am "append line to big blob" &&
315
+
316
+ # Create a promisor remote that only contains the blob from the first
317
+ # commit, and set it as the promisor remote of client. Thus, whenever
318
+ # the client lazy fetches, the lazy fetch will succeed only if it is
319
+ # for this blob.
320
+ git init promisor-remote &&
321
+ test_commit -C promisor-remote one && # so that ref advertisement is not empty
322
+ git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 &&
323
+ git -C promisor-remote hash-object -w --stdin <big-blob.txt &&
324
+ git -C client remote set-url origin "file://$(pwd)/promisor-remote"
325
+}
326
+
327
+# NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
328
+# test that "fetch" avoid fetching trees and blobs, but not commits or
329
+# tags. Revisit this if Git is ever taught to support partial clones
330
+# with commits and/or tags filtered out.
331
+
332
+test_expect_success 'fetch lazy-fetches only to resolve deltas' '
333
+ setup_triangle &&
334
+
335
+ # Exercise to make sure it works. Git will not fetch anything from the
336
+ # promisor remote other than for the big blob (because it needs to
337
+ # resolve the delta).
338
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
339
+ fetch "file://$(pwd)/server" master &&
340
+
341
+ # Verify the assumption that the client needed to fetch the delta base
342
+ # to resolve the delta.
343
+ git hash-object big-blob.txt >hash &&
344
+ grep "want $(cat hash)" trace
345
+'
346
+
347
+test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
348
+ setup_triangle &&
349
+
350
+ git -C server config --local protocol.version 2 &&
351
+ git -C client config --local protocol.version 2 &&
352
+ git -C promisor-remote config --local protocol.version 2 &&
353
+
354
+ # Exercise to make sure it works. Git will not fetch anything from the
355
+ # promisor remote other than for the big blob (because it needs to
356
+ # resolve the delta).
357
+ GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
358
+ fetch "file://$(pwd)/server" master &&
359
+
360
+ # Verify that protocol version 2 was used.
361
+ grep "fetch< version 2" trace &&
362
+
363
+ # Verify the assumption that the client needed to fetch the delta base
364
+ # to resolve the delta.
365
+ git hash-object big-blob.txt >hash &&
366
+ grep "want $(cat hash)" trace
367
+'
368
+
369
. "$TEST_DIRECTORY"/lib-httpd.sh
370
start_httpd
371