3 test_description
='test fetching bundles with --bundle-uri'
7 test_expect_success
'fail to clone from non-existent file' '
8 test_when_finished rm -rf test &&
9 git clone --bundle-uri="$(pwd)/does-not-exist" . test 2>err &&
10 grep "failed to download bundle from URI" err
13 test_expect_success
'fail to clone from non-bundle file' '
14 test_when_finished rm -rf test &&
16 git clone --bundle-uri="$(pwd)/bogus" . test 2>err &&
17 grep "is not a bundle" err
20 test_expect_success
'create bundle' '
21 git init clone-from &&
22 git -C clone-from checkout -b topic &&
23 test_commit -C clone-from A &&
24 test_commit -C clone-from B &&
25 git -C clone-from bundle create B.bundle topic
28 test_expect_success
'clone with path bundle' '
29 git clone --bundle-uri="clone-from/B.bundle" \
30 clone-from clone-path &&
31 git -C clone-path rev-parse refs/bundles/topic >actual &&
32 git -C clone-from rev-parse topic >expect &&
33 test_cmp expect actual
36 test_expect_success
'clone with path bundle and non-default hash' '
37 test_when_finished "rm -rf clone-path-non-default-hash" &&
38 GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="clone-from/B.bundle" \
39 clone-from clone-path-non-default-hash &&
40 git -C clone-path-non-default-hash rev-parse refs/bundles/topic >actual &&
41 git -C clone-from rev-parse topic >expect &&
42 test_cmp expect actual
45 test_expect_success
'clone with file:// bundle' '
46 git clone --bundle-uri="file://$(pwd)/clone-from/B.bundle" \
47 clone-from clone-file &&
48 git -C clone-file rev-parse refs/bundles/topic >actual &&
49 git -C clone-from rev-parse topic >expect &&
50 test_cmp expect actual
53 # To get interesting tests for bundle lists, we need to construct a
54 # somewhat-interesting commit history.
56 # ---------------- bundle-4
60 # ----|---|------- bundle-3
64 # ----|---|------- bundle-2
68 # ----|---|------- bundle-1
73 test_expect_success
'construct incremental bundle list' '
76 git checkout -b base &&
78 git checkout -b left &&
80 git checkout -b right base &&
82 git checkout -b merge left &&
83 git merge right -m "4" &&
85 git bundle create bundle-1.bundle base &&
86 git bundle create bundle-2.bundle base..left &&
87 git bundle create bundle-3.bundle base..right &&
88 git bundle create bundle-4.bundle merge --not left right
92 test_expect_success
'clone bundle list (file, no heuristic)' '
93 cat >bundle-list <<-EOF &&
99 uri = file://$(pwd)/clone-from/bundle-1.bundle
102 uri = file://$(pwd)/clone-from/bundle-2.bundle
105 uri = file://$(pwd)/clone-from/bundle-3.bundle
108 uri = file://$(pwd)/clone-from/bundle-4.bundle
111 git clone --bundle-uri="file://$(pwd)/bundle-list" \
112 clone-from clone-list-file 2>err &&
113 ! grep "Repository lacks these prerequisite commits" err &&
115 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
116 git -C clone-list-file cat-file --batch-check <oids &&
118 git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
119 grep "refs/bundles/" refs >actual &&
120 cat >expect <<-\EOF &&
126 test_cmp expect actual
129 test_expect_success
'clone bundle list (file, all mode, some failures)' '
130 cat >bundle-list <<-EOF &&
135 # Does not exist. Should be skipped.
137 uri = file://$(pwd)/clone-from/bundle-0.bundle
140 uri = file://$(pwd)/clone-from/bundle-1.bundle
143 uri = file://$(pwd)/clone-from/bundle-2.bundle
145 # No bundle-3 means bundle-4 will not apply.
148 uri = file://$(pwd)/clone-from/bundle-4.bundle
150 # Does not exist. Should be skipped.
152 uri = file://$(pwd)/clone-from/bundle-5.bundle
156 git clone --bundle-uri="file://$(pwd)/bundle-list" \
157 clone-from clone-all-some 2>err &&
158 ! grep "Repository lacks these prerequisite commits" err &&
159 ! grep "fatal" err &&
160 grep "warning: failed to download bundle from URI" err &&
162 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
163 git -C clone-all-some cat-file --batch-check <oids &&
165 git -C clone-all-some for-each-ref --format="%(refname)" >refs &&
166 grep "refs/bundles/" refs >actual &&
167 cat >expect <<-\EOF &&
171 test_cmp expect actual
174 test_expect_success
'clone bundle list (file, all mode, all failures)' '
175 cat >bundle-list <<-EOF &&
180 # Does not exist. Should be skipped.
182 uri = file://$(pwd)/clone-from/bundle-0.bundle
184 # Does not exist. Should be skipped.
186 uri = file://$(pwd)/clone-from/bundle-5.bundle
189 git clone --bundle-uri="file://$(pwd)/bundle-list" \
190 clone-from clone-all-fail 2>err &&
191 ! grep "Repository lacks these prerequisite commits" err &&
192 ! grep "fatal" err &&
193 grep "warning: failed to download bundle from URI" err &&
195 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
196 git -C clone-all-fail cat-file --batch-check <oids &&
198 git -C clone-all-fail for-each-ref --format="%(refname)" >refs &&
199 ! grep "refs/bundles/" refs
202 test_expect_success
'clone bundle list (file, any mode)' '
203 cat >bundle-list <<-EOF &&
208 # Does not exist. Should be skipped.
210 uri = file://$(pwd)/clone-from/bundle-0.bundle
213 uri = file://$(pwd)/clone-from/bundle-1.bundle
215 # Does not exist. Should be skipped.
217 uri = file://$(pwd)/clone-from/bundle-5.bundle
220 git clone --bundle-uri="file://$(pwd)/bundle-list" \
221 clone-from clone-any-file 2>err &&
222 ! grep "Repository lacks these prerequisite commits" err &&
224 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
225 git -C clone-any-file cat-file --batch-check <oids &&
227 git -C clone-any-file for-each-ref --format="%(refname)" >refs &&
228 grep "refs/bundles/" refs >actual &&
229 cat >expect <<-\EOF &&
232 test_cmp expect actual
235 test_expect_success
'clone bundle list (file, any mode, all failures)' '
236 cat >bundle-list <<-EOF &&
241 # Does not exist. Should be skipped.
243 uri = $HTTPD_URL/bundle-0.bundle
245 # Does not exist. Should be skipped.
247 uri = $HTTPD_URL/bundle-5.bundle
250 git clone --bundle-uri="file://$(pwd)/bundle-list" \
251 clone-from clone-any-fail 2>err &&
252 ! grep "fatal" err &&
253 grep "warning: failed to download bundle from URI" err &&
255 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
256 git -C clone-any-fail cat-file --batch-check <oids &&
258 git -C clone-any-fail for-each-ref --format="%(refname)" >refs &&
259 ! grep "refs/bundles/" refs
262 #########################################################################
263 # HTTP tests begin here
265 .
"$TEST_DIRECTORY"/lib-httpd.sh
268 test_expect_success
'fail to fetch from non-existent HTTP URL' '
269 test_when_finished rm -rf test &&
270 git clone --bundle-uri="$HTTPD_URL/does-not-exist" . test 2>err &&
271 grep "failed to download bundle from URI" err
274 test_expect_success
'fail to fetch from non-bundle HTTP URL' '
275 test_when_finished rm -rf test &&
276 echo bogus >"$HTTPD_DOCUMENT_ROOT_PATH/bogus" &&
277 git clone --bundle-uri="$HTTPD_URL/bogus" . test 2>err &&
278 grep "is not a bundle" err
281 test_expect_success
'clone HTTP bundle' '
282 cp clone-from/B.bundle "$HTTPD_DOCUMENT_ROOT_PATH/B.bundle" &&
284 git clone --no-local --mirror clone-from \
285 "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" &&
287 git clone --bundle-uri="$HTTPD_URL/B.bundle" \
288 "$HTTPD_URL/smart/fetch.git" clone-http &&
289 git -C clone-http rev-parse refs/bundles/topic >actual &&
290 git -C clone-from rev-parse topic >expect &&
291 test_cmp expect actual &&
293 test_config -C clone-http log.excludedecoration refs/bundle/
296 test_expect_success
'clone HTTP bundle with non-default hash' '
297 test_when_finished "rm -rf clone-http-non-default-hash" &&
298 GIT_DEFAULT_HASH=sha256 git clone --bundle-uri="$HTTPD_URL/B.bundle" \
299 "$HTTPD_URL/smart/fetch.git" clone-http-non-default-hash &&
300 git -C clone-http-non-default-hash rev-parse refs/bundles/topic >actual &&
301 git -C clone-from rev-parse topic >expect &&
302 test_cmp expect actual
305 test_expect_success
'clone bundle list (HTTP, no heuristic)' '
306 test_when_finished rm -f trace*.txt &&
308 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
309 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
315 uri = $HTTPD_URL/bundle-1.bundle
318 uri = $HTTPD_URL/bundle-2.bundle
321 uri = $HTTPD_URL/bundle-3.bundle
324 uri = $HTTPD_URL/bundle-4.bundle
327 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
328 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
329 clone-from clone-list-http 2>err &&
330 ! grep "Repository lacks these prerequisite commits" err &&
332 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
333 git -C clone-list-http cat-file --batch-check <oids &&
335 cat >expect <<-EOF &&
336 $HTTPD_URL/bundle-1.bundle
337 $HTTPD_URL/bundle-2.bundle
338 $HTTPD_URL/bundle-3.bundle
339 $HTTPD_URL/bundle-4.bundle
340 $HTTPD_URL/bundle-list
343 # Sort the list, since the order is not well-defined
344 # without a heuristic.
345 test_remote_https_urls <trace-clone.txt | sort >actual &&
346 test_cmp expect actual
349 test_expect_success
'clone bundle list (HTTP, any mode)' '
350 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
351 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
356 # Does not exist. Should be skipped.
358 uri = $HTTPD_URL/bundle-0.bundle
361 uri = $HTTPD_URL/bundle-1.bundle
363 # Does not exist. Should be skipped.
365 uri = $HTTPD_URL/bundle-5.bundle
368 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
369 clone-from clone-any-http 2>err &&
370 ! grep "fatal" err &&
371 grep "warning: failed to download bundle from URI" err &&
373 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
374 git -C clone-any-http cat-file --batch-check <oids &&
376 git -C clone-list-file for-each-ref --format="%(refname)" >refs &&
377 grep "refs/bundles/" refs >actual &&
378 cat >expect <<-\EOF &&
384 test_cmp expect actual
387 test_expect_success
'clone bundle list (http, creationToken)' '
388 test_when_finished rm -f trace*.txt &&
390 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
391 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
395 heuristic = creationToken
398 uri = bundle-1.bundle
402 uri = bundle-2.bundle
406 uri = bundle-3.bundle
410 uri = bundle-4.bundle
414 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" git \
415 clone --bundle-uri="$HTTPD_URL/bundle-list" \
416 "$HTTPD_URL/smart/fetch.git" clone-list-http-2 &&
418 git -C clone-from for-each-ref --format="%(objectname)" >oids &&
419 git -C clone-list-http-2 cat-file --batch-check <oids &&
421 cat >expect <<-EOF &&
422 $HTTPD_URL/bundle-list
423 $HTTPD_URL/bundle-4.bundle
424 $HTTPD_URL/bundle-3.bundle
425 $HTTPD_URL/bundle-2.bundle
426 $HTTPD_URL/bundle-1.bundle
429 test_remote_https_urls <trace-clone.txt >actual &&
430 test_cmp expect actual
433 test_expect_success
'clone incomplete bundle list (http, creationToken)' '
434 test_when_finished rm -f trace*.txt &&
436 cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
437 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
441 heuristic = creationToken
444 uri = bundle-1.bundle
448 GIT_TRACE2_EVENT=$(pwd)/trace-clone.txt \
449 git clone --bundle-uri="$HTTPD_URL/bundle-list" \
450 --single-branch --branch=base --no-tags \
451 "$HTTPD_URL/smart/fetch.git" clone-token-http &&
453 test_cmp_config -C clone-token-http "$HTTPD_URL/bundle-list" fetch.bundleuri &&
454 test_cmp_config -C clone-token-http 1 fetch.bundlecreationtoken &&
456 cat >expect <<-EOF &&
457 $HTTPD_URL/bundle-list
458 $HTTPD_URL/bundle-1.bundle
461 test_remote_https_urls <trace-clone.txt >actual &&
462 test_cmp expect actual &&
464 # We now have only one bundle ref.
465 git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
466 cat >expect <<-\EOF &&
469 test_cmp expect refs &&
471 # Add remaining bundles, exercising the "deepening" strategy
472 # for downloading via the creationToken heurisitc.
473 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
475 uri = bundle-2.bundle
479 uri = bundle-3.bundle
483 uri = bundle-4.bundle
487 GIT_TRACE2_EVENT="$(pwd)/trace1.txt" \
488 git -C clone-token-http fetch origin --no-tags \
489 refs/heads/merge:refs/heads/merge &&
490 test_cmp_config -C clone-token-http 4 fetch.bundlecreationtoken &&
492 cat >expect <<-EOF &&
493 $HTTPD_URL/bundle-list
494 $HTTPD_URL/bundle-4.bundle
495 $HTTPD_URL/bundle-3.bundle
496 $HTTPD_URL/bundle-2.bundle
499 test_remote_https_urls <trace1.txt >actual &&
500 test_cmp expect actual &&
502 # We now have all bundle refs.
503 git -C clone-token-http for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
505 cat >expect <<-\EOF &&
514 test_expect_success
'http clone with bundle.heuristic creates fetch.bundleURI' '
515 test_when_finished rm -rf fetch-http-4 trace*.txt &&
517 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
521 heuristic = creationToken
524 uri = bundle-1.bundle
528 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
529 git clone --single-branch --branch=base \
530 --bundle-uri="$HTTPD_URL/bundle-list" \
531 "$HTTPD_URL/smart/fetch.git" fetch-http-4 &&
533 test_cmp_config -C fetch-http-4 "$HTTPD_URL/bundle-list" fetch.bundleuri &&
534 test_cmp_config -C fetch-http-4 1 fetch.bundlecreationtoken &&
536 cat >expect <<-EOF &&
537 $HTTPD_URL/bundle-list
538 $HTTPD_URL/bundle-1.bundle
541 test_remote_https_urls <trace-clone.txt >actual &&
542 test_cmp expect actual &&
544 # only received base ref from bundle-1
545 git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
546 cat >expect <<-\EOF &&
549 test_cmp expect refs &&
551 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
553 uri = bundle-2.bundle
557 # Fetch the objects for bundle-2 _and_ bundle-3.
558 GIT_TRACE2_EVENT="$(pwd)/trace1.txt" \
559 git -C fetch-http-4 fetch origin --no-tags \
560 refs/heads/left:refs/heads/left \
561 refs/heads/right:refs/heads/right &&
562 test_cmp_config -C fetch-http-4 2 fetch.bundlecreationtoken &&
564 cat >expect <<-EOF &&
565 $HTTPD_URL/bundle-list
566 $HTTPD_URL/bundle-2.bundle
569 test_remote_https_urls <trace1.txt >actual &&
570 test_cmp expect actual &&
572 # received left from bundle-2
573 git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
574 cat >expect <<-\EOF &&
578 test_cmp expect refs &&
581 GIT_TRACE2_EVENT="$(pwd)/trace1b.txt" \
582 git -C fetch-http-4 fetch origin --no-tags \
583 refs/heads/left:refs/heads/left \
584 refs/heads/right:refs/heads/right &&
586 cat >expect <<-EOF &&
587 $HTTPD_URL/bundle-list
589 test_remote_https_urls <trace1b.txt >actual &&
590 test_cmp expect actual &&
592 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
594 uri = bundle-3.bundle
598 uri = bundle-4.bundle
602 # This fetch should skip bundle-3.bundle, since its objects are
603 # already local (we have the requisite commits for bundle-4.bundle).
604 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
605 git -C fetch-http-4 fetch origin --no-tags \
606 refs/heads/merge:refs/heads/merge &&
607 test_cmp_config -C fetch-http-4 4 fetch.bundlecreationtoken &&
609 cat >expect <<-EOF &&
610 $HTTPD_URL/bundle-list
611 $HTTPD_URL/bundle-4.bundle
614 test_remote_https_urls <trace2.txt >actual &&
615 test_cmp expect actual &&
617 # received merge ref from bundle-4, but right is missing
618 # because we did not download bundle-3.
619 git -C fetch-http-4 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
621 cat >expect <<-\EOF &&
626 test_cmp expect refs &&
629 GIT_TRACE2_EVENT="$(pwd)/trace2b.txt" \
630 git -C fetch-http-4 fetch origin &&
632 cat >expect <<-EOF &&
633 $HTTPD_URL/bundle-list
635 test_remote_https_urls <trace2b.txt >actual &&
636 test_cmp expect actual
639 test_expect_success
'creationToken heuristic with failed downloads (clone)' '
640 test_when_finished rm -rf download-* trace*.txt &&
642 # Case 1: base bundle does not exist, nothing can unbundle
643 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
647 heuristic = creationToken
654 uri = bundle-2.bundle
658 uri = bundle-3.bundle
662 uri = bundle-4.bundle
666 GIT_TRACE2_EVENT="$(pwd)/trace-clone-1.txt" \
667 git clone --single-branch --branch=base \
668 --bundle-uri="$HTTPD_URL/bundle-list" \
669 "$HTTPD_URL/smart/fetch.git" download-1 &&
671 # Bundle failure does not set these configs.
672 test_must_fail git -C download-1 config fetch.bundleuri &&
673 test_must_fail git -C download-1 config fetch.bundlecreationtoken &&
675 cat >expect <<-EOF &&
676 $HTTPD_URL/bundle-list
677 $HTTPD_URL/bundle-4.bundle
678 $HTTPD_URL/bundle-3.bundle
679 $HTTPD_URL/bundle-2.bundle
680 $HTTPD_URL/fake.bundle
682 test_remote_https_urls <trace-clone-1.txt >actual &&
683 test_cmp expect actual &&
685 # All bundles failed to unbundle
686 git -C download-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
687 test_must_be_empty refs &&
689 # Case 2: middle bundle does not exist, only two bundles can unbundle
690 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
694 heuristic = creationToken
697 uri = bundle-1.bundle
705 uri = bundle-3.bundle
709 uri = bundle-4.bundle
713 GIT_TRACE2_EVENT="$(pwd)/trace-clone-2.txt" \
714 git clone --single-branch --branch=base \
715 --bundle-uri="$HTTPD_URL/bundle-list" \
716 "$HTTPD_URL/smart/fetch.git" download-2 &&
718 # Bundle failure does not set these configs.
719 test_must_fail git -C download-2 config fetch.bundleuri &&
720 test_must_fail git -C download-2 config fetch.bundlecreationtoken &&
722 cat >expect <<-EOF &&
723 $HTTPD_URL/bundle-list
724 $HTTPD_URL/bundle-4.bundle
725 $HTTPD_URL/bundle-3.bundle
726 $HTTPD_URL/fake.bundle
727 $HTTPD_URL/bundle-1.bundle
729 test_remote_https_urls <trace-clone-2.txt >actual &&
730 test_cmp expect actual &&
732 # bundle-1 and bundle-3 could unbundle, but bundle-4 could not
733 git -C download-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
734 cat >expect <<-EOF &&
738 test_cmp expect refs &&
740 # Case 3: top bundle does not exist, rest unbundle fine.
741 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
745 heuristic = creationToken
748 uri = bundle-1.bundle
752 uri = bundle-2.bundle
756 uri = bundle-3.bundle
764 GIT_TRACE2_EVENT="$(pwd)/trace-clone-3.txt" \
765 git clone --single-branch --branch=base \
766 --bundle-uri="$HTTPD_URL/bundle-list" \
767 "$HTTPD_URL/smart/fetch.git" download-3 &&
769 # As long as we have continguous successful downloads,
770 # we _do_ set these configs.
771 test_cmp_config -C download-3 "$HTTPD_URL/bundle-list" fetch.bundleuri &&
772 test_cmp_config -C download-3 3 fetch.bundlecreationtoken &&
774 cat >expect <<-EOF &&
775 $HTTPD_URL/bundle-list
776 $HTTPD_URL/fake.bundle
777 $HTTPD_URL/bundle-3.bundle
778 $HTTPD_URL/bundle-2.bundle
779 $HTTPD_URL/bundle-1.bundle
781 test_remote_https_urls <trace-clone-3.txt >actual &&
782 test_cmp expect actual &&
784 # fake.bundle did not unbundle, but the others did.
785 git -C download-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
786 cat >expect <<-EOF &&
794 # Expand the bundle list to include other interesting shapes, specifically
795 # interesting for use when fetching from a previous state.
797 # ---------------- bundle-7
800 # ---/--|--\------ bundle-6
802 # --|---|---|----- bundle-4
805 # --|-|---|/------ bundle-3 (the client will be caught up to this point.)
807 # ---\|---|------- bundle-2
809 # ----|---|------- bundle-1
814 test_expect_success
'expand incremental bundle list' '
817 git checkout -b lefter left &&
819 git checkout -b righter right &&
821 git checkout -b top lefter &&
822 git merge -m "7" merge righter &&
824 git bundle create bundle-6.bundle lefter righter --not left right &&
825 git bundle create bundle-7.bundle top --not lefter merge righter &&
827 cp bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/"
829 git -C "$HTTPD_DOCUMENT_ROOT_PATH/fetch.git" fetch origin +refs/heads/*:refs/heads/*
832 test_expect_success
'creationToken heuristic with failed downloads (fetch)' '
833 test_when_finished rm -rf download-* trace*.txt &&
835 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
839 heuristic = creationToken
842 uri = bundle-1.bundle
846 uri = bundle-2.bundle
850 uri = bundle-3.bundle
854 git clone --single-branch --branch=left \
855 --bundle-uri="$HTTPD_URL/bundle-list" \
856 "$HTTPD_URL/smart/fetch.git" fetch-base &&
857 test_cmp_config -C fetch-base "$HTTPD_URL/bundle-list" fetch.bundleURI &&
858 test_cmp_config -C fetch-base 3 fetch.bundleCreationToken &&
860 # Case 1: all bundles exist: successful unbundling of all bundles
861 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
865 heuristic = creationToken
868 uri = bundle-1.bundle
872 uri = bundle-2.bundle
876 uri = bundle-3.bundle
880 uri = bundle-4.bundle
884 uri = bundle-6.bundle
888 uri = bundle-7.bundle
892 cp -r fetch-base fetch-1 &&
893 GIT_TRACE2_EVENT="$(pwd)/trace-fetch-1.txt" \
894 git -C fetch-1 fetch origin &&
895 test_cmp_config -C fetch-1 7 fetch.bundlecreationtoken &&
897 cat >expect <<-EOF &&
898 $HTTPD_URL/bundle-list
899 $HTTPD_URL/bundle-7.bundle
900 $HTTPD_URL/bundle-6.bundle
901 $HTTPD_URL/bundle-4.bundle
903 test_remote_https_urls <trace-fetch-1.txt >actual &&
904 test_cmp expect actual &&
906 # Check which bundles have unbundled by refs
907 git -C fetch-1 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
908 cat >expect <<-EOF &&
917 test_cmp expect refs &&
919 # Case 2: middle bundle does not exist, only bundle-4 can unbundle
920 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
924 heuristic = creationToken
927 uri = bundle-1.bundle
931 uri = bundle-2.bundle
935 uri = bundle-3.bundle
939 uri = bundle-4.bundle
947 uri = bundle-7.bundle
951 cp -r fetch-base fetch-2 &&
952 GIT_TRACE2_EVENT="$(pwd)/trace-fetch-2.txt" \
953 git -C fetch-2 fetch origin &&
955 # Since bundle-7 fails to unbundle, do not update creation token.
956 test_cmp_config -C fetch-2 3 fetch.bundlecreationtoken &&
958 cat >expect <<-EOF &&
959 $HTTPD_URL/bundle-list
960 $HTTPD_URL/bundle-7.bundle
961 $HTTPD_URL/fake.bundle
962 $HTTPD_URL/bundle-4.bundle
964 test_remote_https_urls <trace-fetch-2.txt >actual &&
965 test_cmp expect actual &&
967 # Check which bundles have unbundled by refs
968 git -C fetch-2 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
969 cat >expect <<-EOF &&
975 test_cmp expect refs &&
977 # Case 3: top bundle does not exist, rest unbundle fine.
978 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
982 heuristic = creationToken
985 uri = bundle-1.bundle
989 uri = bundle-2.bundle
993 uri = bundle-3.bundle
997 uri = bundle-4.bundle
1001 uri = bundle-6.bundle
1009 cp -r fetch-base fetch-3 &&
1010 GIT_TRACE2_EVENT="$(pwd)/trace-fetch-3.txt" \
1011 git -C fetch-3 fetch origin &&
1013 # As long as we have continguous successful downloads,
1014 # we _do_ set the maximum creation token.
1015 test_cmp_config -C fetch-3 6 fetch.bundlecreationtoken &&
1017 # NOTE: the fetch skips bundle-4 since bundle-6 successfully
1018 # unbundles itself and bundle-7 failed to download.
1019 cat >expect <<-EOF &&
1020 $HTTPD_URL/bundle-list
1021 $HTTPD_URL/fake.bundle
1022 $HTTPD_URL/bundle-6.bundle
1024 test_remote_https_urls <trace-fetch-3.txt >actual &&
1025 test_cmp expect actual &&
1027 # Check which bundles have unbundled by refs
1028 git -C fetch-3 for-each-ref --format="%(refname)" "refs/bundles/*" >refs &&
1029 cat >expect <<-EOF &&
1034 refs/bundles/righter
1036 test_cmp expect refs
1039 test_expect_success
'bundles are downloaded once during fetch --all' '
1040 test_when_finished rm -rf download-* trace*.txt fetch-mult &&
1042 cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
1046 heuristic = creationToken
1049 uri = bundle-1.bundle
1053 uri = bundle-2.bundle
1057 uri = bundle-3.bundle
1061 git clone --single-branch --branch=left \
1062 --bundle-uri="$HTTPD_URL/bundle-list" \
1063 "$HTTPD_URL/smart/fetch.git" fetch-mult &&
1064 git -C fetch-mult remote add dup1 "$HTTPD_URL/smart/fetch.git" &&
1065 git -C fetch-mult remote add dup2 "$HTTPD_URL/smart/fetch.git" &&
1067 GIT_TRACE2_EVENT="$(pwd)/trace-mult.txt" \
1068 git -C fetch-mult fetch --all &&
1069 grep "\"child_start\".*\"git-remote-https\",\"$HTTPD_URL/bundle-list\"" \
1070 trace-mult.txt >bundle-fetches &&
1071 test_line_count = 1 bundle-fetches
1073 # Do not add tests here unless they use the HTTP server, as they will
1074 # not run unless the HTTP dependencies exist.