3 # Copyright (c) 2005 Johannes Schindelin
6 test_description
='Testing multi_ack pack fetching'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 # Test fetch-pack/upload-pack pair.
15 # Some convenience functions
20 branch
=$
(echo $name |
sed -e 's/^\(.\).*$/\1/') &&
25 parents
="$parents -p $1" &&
29 echo "$text" > test.txt
&&
30 git update-index
--add test.txt
&&
31 tree
=$
(git write-tree
) &&
32 # make sure timestamps are in correct order
34 commit
=$
(echo "$text" | git commit-tree
$tree $parents) &&
35 eval "$name=$commit; export $name" &&
36 git update-ref
"refs/heads/$branch" "$commit" &&
37 eval ${branch}TIP
=$commit
44 test_expect_success
"$number pull" '
47 git fetch-pack -k -v .. $heads &&
51 git update-ref refs/heads/A "$ATIP";;
54 git update-ref refs/heads/B "$BTIP";;
57 git symbolic-ref HEAD refs/heads/$(
59 sed -e "s/^\(.\).*$/\1/"
64 mv .git/objects/pack/pack-* . &&
65 p=$(ls -1 pack-*.pack) &&
66 git unpack-objects <$p &&
69 idx=$(echo pack-*.idx) &&
70 pack_count=$(git show-index <$idx | wc -l) &&
71 test $pack_count = $count &&
77 # Here begins the actual testing
79 # A1 - ... - A20 - A21
83 # client pulls A20, B1. Then tracks only B. Then pulls A.
85 test_expect_success
'setup' '
90 git config transfer.unpacklimit 0
95 while [ $cur -le 10 ]; do
96 add A$cur $(eval echo \$A$prev) &&
98 cur=$(($cur+1)) || return 1
101 git update-ref refs/heads/A "$ATIP" &&
102 git update-ref refs/heads/B "$BTIP" &&
103 git symbolic-ref HEAD refs/heads/B
106 pull_to_client
1st
"refs/heads/B refs/heads/A" $
((11*3))
108 test_expect_success
'post 1st pull setup' '
112 while [ $cur -le 65 ]; do
113 add B$cur $(eval echo \$B$prev) &&
115 cur=$(($cur+1)) || return 1
119 pull_to_client
2nd
"refs/heads/B" $
((64*3))
121 pull_to_client
3rd
"refs/heads/A" $
((1*3))
123 test_expect_success
'single branch clone' '
124 git clone --single-branch "file://$(pwd)/." singlebranch
127 test_expect_success
'single branch object count' '
128 GIT_DIR=singlebranch/.git git count-objects -v |
129 grep "^in-pack:" > count.singlebranch &&
130 echo "in-pack: 198" >expected &&
131 test_cmp expected count.singlebranch
134 test_expect_success
'single given branch clone' '
135 GIT_TRACE2_EVENT="$(pwd)/branch-a/trace2_event" \
136 git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
137 test_must_fail git --git-dir=branch-a/.git rev-parse origin/B &&
138 grep \"fetch-info\".*\"haves\":0 branch-a/trace2_event &&
139 grep \"fetch-info\".*\"wants\":1 branch-a/trace2_event
142 test_expect_success
'clone shallow depth 1' '
143 GIT_TRACE2_EVENT="$(pwd)/shallow0/trace2_event" \
144 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
145 test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1 &&
146 grep \"fetch-info\".*\"depth\":1 shallow0/trace2_event
149 test_expect_success
'clone shallow depth 1 with fsck' '
150 git config --global fetch.fsckobjects true &&
151 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0fsck &&
152 test "$(git --git-dir=shallow0fsck/.git rev-list --count HEAD)" = 1 &&
153 git config --global --unset fetch.fsckobjects
156 test_expect_success
'clone shallow' '
157 git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
160 test_expect_success
'clone shallow depth count' '
161 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 2
164 test_expect_success
'clone shallow object count' '
169 grep "^in-pack: 12" count.shallow
172 test_expect_success
'clone shallow object count (part 2)' '
173 sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
174 -e "/: 0$/d" count.shallow > count_output &&
175 test_must_be_empty count_output
178 test_expect_success
'fsck in shallow repo' '
185 test_expect_success
'simple fetch in shallow repo' '
192 test_expect_success
'no changes expected' '
196 ) > count.shallow.2 &&
197 cmp count.shallow count.shallow.2
200 test_expect_success
'fetch same depth in shallow repo' '
207 test_expect_success
'no changes expected' '
211 ) > count.shallow.3 &&
212 cmp count.shallow count.shallow.3
215 test_expect_success
'add two more' '
220 test_expect_success
'pull in shallow repo' '
227 test_expect_success
'clone shallow object count' '
232 grep "^count: 6" count.shallow
235 test_expect_success
'add two more (part 2)' '
240 test_expect_success
'deepening pull in shallow repo' '
243 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
244 git pull --depth 4 .. B &&
245 grep \"fetch-info\".*\"depth\":4 trace2_event &&
246 grep \"fetch-info\".*\"shallows\":2 trace2_event
250 test_expect_success
'clone shallow object count' '
255 grep "^count: 12" count.shallow
258 test_expect_success
'deepening fetch in shallow repo' '
261 git fetch --depth 4 .. A:A
265 test_expect_success
'clone shallow object count' '
270 grep "^count: 18" count.shallow
273 test_expect_success
'pull in shallow repo with missing merge base' '
276 git fetch --depth 4 .. A &&
277 test_must_fail git merge --allow-unrelated-histories FETCH_HEAD
281 test_expect_success
'additional simple shallow deepenings' '
284 git fetch --depth=8 &&
285 git fetch --depth=10 &&
290 test_expect_success
'clone shallow depth count' '
291 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 11
294 test_expect_success
'clone shallow object count' '
300 grep "^count: 54" count.shallow
303 test_expect_success
'fetch --no-shallow on full repo' '
304 test_must_fail git fetch --noshallow
307 test_expect_success
'fetch --depth --no-shallow' '
310 test_must_fail git fetch --depth=1 --noshallow
314 test_expect_success
'turn shallow to complete repository' '
317 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
318 git fetch --unshallow &&
319 ! test -f .git/shallow &&
321 grep \"fetch-info\".*\"shallows\":2 trace2_event &&
322 grep \"fetch-info\".*\"depth\":2147483647 trace2_event
326 test_expect_success
'clone shallow without --no-single-branch' '
327 git clone --depth 1 "file://$(pwd)/." shallow2
330 test_expect_success
'clone shallow object count' '
334 ) > count.shallow2 &&
335 grep "^in-pack: 3" count.shallow2
338 test_expect_success
'clone shallow with --branch' '
339 git clone --depth 1 --branch A "file://$(pwd)/." shallow3
342 test_expect_success
'clone shallow object count' '
343 echo "in-pack: 3" > count3.expected &&
344 GIT_DIR=shallow3/.git git count-objects -v |
345 grep "^in-pack" > count3.actual &&
346 test_cmp count3.expected count3.actual
349 test_expect_success
'clone shallow with detached HEAD' '
350 git checkout HEAD^ &&
351 git clone --depth 1 "file://$(pwd)/." shallow5 &&
353 GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
354 git rev-parse HEAD^ >expected &&
355 test_cmp expected actual
358 test_expect_success
'shallow clone pulling tags' '
359 git tag -a -m A TAGA1 A &&
360 git tag -a -m B TAGB1 B &&
363 git clone --depth 1 "file://$(pwd)/." shallow6 &&
365 cat >taglist.expected <<\EOF &&
369 GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
370 test_cmp taglist.expected taglist.actual &&
372 echo "in-pack: 4" > count6.expected &&
373 GIT_DIR=shallow6/.git git count-objects -v |
374 grep "^in-pack" > count6.actual &&
375 test_cmp count6.expected count6.actual
378 test_expect_success
'shallow cloning single tag' '
379 git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
380 cat >taglist.expected <<\EOF &&
384 GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
385 test_cmp taglist.expected taglist.actual &&
387 echo "in-pack: 4" > count7.expected &&
388 GIT_DIR=shallow7/.git git count-objects -v |
389 grep "^in-pack" > count7.actual &&
390 test_cmp count7.expected count7.actual
393 test_expect_success
'clone shallow with packed refs' '
394 git pack-refs --all &&
395 git clone --depth 1 --branch A "file://$(pwd)/." shallow8 &&
396 echo "in-pack: 4" > count8.expected &&
397 GIT_DIR=shallow8/.git git count-objects -v |
398 grep "^in-pack" > count8.actual &&
399 test_cmp count8.expected count8.actual
402 test_expect_success
'in_vain not triggered before first ACK' '
403 rm -rf myserver myclient &&
405 test_commit -C myserver foo &&
406 git clone "file://$(pwd)/myserver" myclient &&
408 # MAX_IN_VAIN is 256. Because of batching, the client will send 496
409 # (16+32+64+128+256) commits, not 256, before giving up. So create 496
410 # irrelevant commits.
411 test_commit_bulk -C myclient 496 &&
413 # The new commit that the client wants to fetch.
414 test_commit -C myserver bar &&
416 git -C myclient fetch --progress origin 2>log &&
417 test_grep "remote: Total 3 " log
420 test_expect_success
'in_vain resetted upon ACK' '
421 test_when_finished rm -f log trace2 &&
422 rm -rf myserver myclient &&
425 # Linked list of commits on main. The first is common; the rest are
427 test_commit -C myserver first_main_commit &&
428 git clone "file://$(pwd)/myserver" myclient &&
429 test_commit_bulk -C myclient 255 &&
431 # Another linked list of commits on anotherbranch with no connection to
432 # main. The first is common; the rest are not.
433 git -C myserver checkout --orphan anotherbranch &&
434 test_commit -C myserver first_anotherbranch_commit &&
435 git -C myclient fetch origin anotherbranch:refs/heads/anotherbranch &&
436 git -C myclient checkout anotherbranch &&
437 test_commit_bulk -C myclient 255 &&
439 # The new commit that the client wants to fetch.
440 git -C myserver checkout main &&
441 test_commit -C myserver to_fetch &&
443 # The client will send (as "have"s) all 256 commits in anotherbranch
444 # first. The 256th commit is common between the client and the server,
445 # and should reset in_vain. This allows negotiation to continue until
446 # the client reports that first_anotherbranch_commit is common.
447 GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
448 grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
449 test_grep "Total 3 " log
452 test_expect_success
'fetch in shallow repo unreachable shallow objects' '
454 git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&
455 git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 &&
457 git tag -d TAGB1 TAGB2 &&
458 git update-ref refs/heads/B B~~ &&
459 git gc --prune=now &&
462 git fsck --no-dangling
465 test_expect_success
'fetch creating new shallow root' '
467 git clone "file://$(pwd)/." shallow10 &&
468 git commit --allow-empty -m empty &&
470 git fetch --depth=1 --progress 2>actual &&
471 # This should fetch only the empty commit, no tree or
473 test_grep "remote: Total 1" actual
477 test_expect_success
'setup tests for the --stdin parameter' '
480 add $head || return 1
482 for head in A B C D E F
484 git tag $head $head || return 1
486 cat >input <<-\EOF &&
498 sort <input >expect &&
506 test_expect_success
'setup fetch refs from cmdline v[12]' '
507 cp -r client client0 &&
508 cp -r client client1 &&
512 for version
in '' 0 1 2
514 test_expect_success
"protocol.version=$version fetch refs from cmdline" "
517 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
519 cut -d ' ' -f 2 <output | sort >actual &&
520 test_cmp expect actual
524 test_expect_success
'fetch refs from stdin' '
527 git fetch-pack --stdin --no-progress .. <../input
529 cut -d " " -f 2 <output | sort >actual &&
530 test_cmp expect actual
533 test_expect_success
'fetch mixed refs from cmdline and stdin' '
536 tail -n +5 ../input |
537 git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
539 cut -d " " -f 2 <output | sort >actual &&
540 test_cmp expect actual
543 test_expect_success
'test duplicate refs from stdin' '
546 git fetch-pack --stdin --no-progress .. <../input.dup
548 cut -d " " -f 2 <output | sort >actual &&
549 test_cmp expect actual
552 test_expect_success
'set up tests of missing reference' '
553 cat >expect-error <<-\EOF
554 error: no such remote ref refs/heads/xyzzy
558 test_expect_success
'test lonely missing ref' '
561 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
563 test_cmp expect-error error-m
566 test_expect_success
'test missing ref after existing' '
569 test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
571 test_cmp expect-error error-em
574 test_expect_success
'test missing ref before existing' '
577 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
579 test_cmp expect-error error-me
582 test_expect_success
'test --all, --depth, and explicit head' '
585 git fetch-pack --no-progress --all --depth=1 .. refs/heads/A
586 ) >out-adh 2>error-adh
589 test_expect_success
'test --all, --depth, and explicit tag' '
590 git tag OLDTAG refs/heads/B~5 &&
593 git fetch-pack --no-progress --all --depth=1 .. refs/tags/OLDTAG
594 ) >out-adt 2>error-adt
597 test_expect_success
'test --all with tag to non-tip' '
598 git commit --allow-empty -m non-tip &&
599 git commit --allow-empty -m tip &&
600 git tag -m "annotated" non-tip HEAD^ &&
603 git fetch-pack --all ..
607 test_expect_success
'test --all wrt tag to non-commits' '
608 # create tag-to-{blob,tree,commit,tag}, making sure all tagged objects
609 # are reachable only via created tag references.
610 blob=$(echo "hello blob" | git hash-object -t blob -w --stdin) &&
611 git tag -a -m "tag -> blob" tag-to-blob $blob &&
613 tree=$(printf "100644 blob $blob\tfile" | git mktree) &&
614 git tag -a -m "tag -> tree" tag-to-tree $tree &&
616 tree2=$(printf "100644 blob $blob\tfile2" | git mktree) &&
617 commit=$(git commit-tree -m "hello commit" $tree) &&
618 git tag -a -m "tag -> commit" tag-to-commit $commit &&
620 blob2=$(echo "hello blob2" | git hash-object -t blob -w --stdin) &&
621 tag=$(git mktag <<-EOF
625 tagger author A U Thor <author@example.com> 0 +0000
630 git tag -a -m "tag -> tag" tag-to-tag $tag &&
632 # `fetch-pack --all` should succeed fetching all those objects.
637 git fetch-pack --all .. &&
638 git cat-file blob $blob >/dev/null &&
639 git cat-file tree $tree >/dev/null &&
640 git cat-file commit $commit >/dev/null &&
641 git cat-file tag $tag >/dev/null
645 test_expect_success
'shallow fetch with tags does not break the repository' '
656 git fetch --depth=2 ../.git main:branch &&
661 test_expect_success
'fetch-pack can fetch a raw sha1' '
667 git update-ref refs/hidden/one HEAD^ &&
668 git config transfer.hiderefs refs/hidden &&
669 git config uploadpack.allowtipsha1inwant true
671 git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
674 test_expect_success
'fetch-pack can fetch a raw sha1 that is advertised as a ref' '
675 rm -rf server client &&
677 test_commit -C server 1 &&
680 git -C client fetch-pack ../server \
681 $(git -C server rev-parse refs/heads/main)
684 test_expect_success
'fetch-pack can fetch a raw sha1 overlapping a named ref' '
685 rm -rf server client &&
687 test_commit -C server 1 &&
688 test_commit -C server 2 &&
691 git -C client fetch-pack ../server \
692 $(git -C server rev-parse refs/tags/1) refs/tags/1
695 test_expect_success
'fetch-pack cannot fetch a raw sha1 that is not advertised as a ref' '
699 test_commit -C server 5 &&
700 git -C server tag -d 5 &&
701 test_commit -C server 6 &&
704 # Some protocol versions (e.g. 2) support fetching
705 # unadvertised objects, so restrict this test to v0.
706 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C client fetch-pack ../server \
707 $(git -C server rev-parse refs/heads/main^) 2>err &&
708 test_grep "Server does not allow request for unadvertised object" err
712 cat >expected
<<-EOF &&
717 git fetch-pack
--diag-url "$1" |
grep -v hostandport
= >actual
&&
718 test_cmp expected actual
721 check_prot_host_port_path
() {
726 ehost
=$
(echo $3 |
tr -d "[]")
727 diagport
="Diag: port=$4"
732 ehost
=$
(echo $3$4 |
sed -e "s/22$/:22/" -e "s/NONE//")
743 grep -v "^$" exp
>expected
744 git fetch-pack
--diag-url "$1" >actual
&&
745 test_cmp expected actual
748 for r
in repo re
:po re
/po
750 # git or ssh with scheme
751 for p
in "ssh+git" "git+ssh" git
ssh
753 for h
in host user@
host user@
[::1] user@
::1
757 test_expect_success
"fetch-pack --diag-url $p://$h$c/$r" '
758 check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
760 # "/~" -> "~" conversion
761 test_expect_success
"fetch-pack --diag-url $p://$h$c/~$r" '
762 check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
766 for h
in host User@
host User@
[::1]
768 test_expect_success
"fetch-pack --diag-url $p://$h:22/$r" '
769 check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
776 test_expect_success
!MINGW
"fetch-pack --diag-url $p://$h/$r" '
777 check_prot_path $p://$h/$r $p "/$r"
779 test_expect_success MINGW
"fetch-pack --diag-url $p://$h/$r" '
780 check_prot_path $p://$h/$r $p "//$h/$r"
782 test_expect_success MINGW
"fetch-pack --diag-url $p:///$r" '
783 check_prot_path $p:///$r $p "/$r"
785 # No "/~" -> "~" conversion for file
786 test_expect_success
!MINGW
"fetch-pack --diag-url $p://$h/~$r" '
787 check_prot_path $p://$h/~$r $p "/~$r"
789 test_expect_success MINGW
"fetch-pack --diag-url $p://$h/~$r" '
790 check_prot_path $p://$h/~$r $p "//$h/~$r"
793 # file without scheme
794 for h
in nohost nohost
:12 [::1] [::1]:23 [ [:aa
796 test_expect_success
"fetch-pack --diag-url ./$h:$r" '
797 check_prot_path ./$h:$r $p "./$h:$r"
799 # No "/~" -> "~" conversion for file
800 test_expect_success
"fetch-pack --diag-url ./$p:$h/~$r" '
801 check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r"
808 test_expect_success
"fetch-pack --diag-url $h:$r" '
809 check_prot_host_port_path $h:$r $p "$h" NONE "$r"
811 # Do "/~" -> "~" conversion
812 test_expect_success
"fetch-pack --diag-url $h:/~$r" '
813 check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
818 test_expect_success MINGW
'fetch-pack --diag-url file://c:/repo' '
819 check_prot_path file://c:/repo file c:/repo
821 test_expect_success MINGW
'fetch-pack --diag-url c:repo' '
822 check_prot_path c:repo file c:repo
825 test_expect_success
'clone shallow since ...' '
826 test_create_repo shallow-since &&
829 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
830 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
831 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
832 git clone --shallow-since "300000000 +0700" "file://$(pwd)/." ../shallow11 &&
833 git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
834 echo three >expected &&
835 test_cmp expected actual
839 test_expect_success
'fetch shallow since ...' '
840 GIT_TRACE2_EVENT=$(pwd)/shallow11/trace2_event \
841 git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
842 git -C shallow11 log --pretty=tformat:%s origin/main >actual &&
843 cat >expected <<-\EOF &&
847 test_cmp expected actual &&
848 grep \"fetch-info\".*\"deepen-since\":true shallow11/trace2_event
851 test_expect_success
'clone shallow since selects no commits' '
852 test_create_repo shallow-since-the-future &&
854 cd shallow-since-the-future &&
855 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
856 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
857 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
858 test_must_fail git clone --shallow-since "900000000 +0700" "file://$(pwd)/." ../shallow111
862 # A few subtle things about the request in this test:
864 # - the server must have commit-graphs present and enabled
866 # - the history is such that our want/have share a common ancestor ("base"
869 # - we send only a single have, which is fewer than a normal client would
870 # send. This ensures that we don't parse "base" up front with
871 # parse_object(), but rather traverse to it as a parent while deciding if we
872 # can stop the "have" negotiation, and call parse_commit(). The former
873 # sees the actual object data and so always loads the three oid, whereas the
874 # latter will try to load it lazily.
876 # - we must use protocol v2, because it handles the "have" negotiation before
877 # processing the shallow directives
879 test_expect_success
'shallow since with commit graph and already-seen commit' '
880 test_create_repo shallow-since-graph &&
882 cd shallow-since-graph &&
885 git checkout -b other HEAD^ &&
887 git commit-graph write --reachable &&
888 git config core.commitGraph true &&
890 GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
892 $(echo "object-format=$(test_oid algo)" | packetize)
893 00010013deepen-since 1
894 $(echo "want $(git rev-parse other)" | packetize)
895 $(echo "have $(git rev-parse main)" | packetize)
901 test_expect_success
'shallow clone exclude tag two' '
902 test_create_repo shallow-exclude &&
904 cd shallow-exclude &&
908 git clone --shallow-exclude two "file://$(pwd)/." ../shallow12 &&
909 git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
910 echo three >expected &&
911 test_cmp expected actual
915 test_expect_success
'fetch exclude tag one' '
916 git -C shallow12 fetch --shallow-exclude one origin &&
917 git -C shallow12 log --pretty=tformat:%s origin/main >actual &&
918 test_write_lines three two >expected &&
919 test_cmp expected actual
922 test_expect_success
'fetching deepen' '
923 test_create_repo shallow-deepen &&
929 git clone --depth 1 "file://$(pwd)/." deepen &&
931 git -C deepen log --pretty=tformat:%s main >actual &&
932 echo three >expected &&
933 test_cmp expected actual &&
934 git -C deepen fetch --deepen=1 &&
935 git -C deepen log --pretty=tformat:%s origin/main >actual &&
936 cat >expected <<-\EOF &&
941 test_cmp expected actual
945 test_negotiation_algorithm_default
() {
946 test_when_finished
rm -rf clientv0 clientv2
&&
947 rm -rf server client
&&
949 test_commit
-C server both_have_1
&&
950 git
-C server tag
-d both_have_1
&&
951 test_commit
-C server both_have_2
&&
953 git clone server client
&&
954 test_commit
-C server server_has
&&
955 test_commit
-C client client_has
&&
957 # In both protocol v0 and v2, ensure that the parent of both_have_2 is
958 # not sent as a "have" line. The client should know that the server has
959 # both_have_2, so it only needs to inform the server that it has
960 # both_have_2, and the server can infer the rest.
963 cp -r client clientv0
&&
964 GIT_TRACE_PACKET
="$(pwd)/trace" git
-C clientv0 \
965 "$@" fetch origin server_has both_have_2
&&
966 grep "have $(git -C client rev-parse client_has)" trace
&&
967 grep "have $(git -C client rev-parse both_have_2)" trace
&&
968 ! grep "have $(git -C client rev-parse both_have_2^)" trace
&&
971 cp -r client clientv2
&&
972 GIT_TRACE_PACKET
="$(pwd)/trace" git
-C clientv2
-c protocol.version
=2 \
973 "$@" fetch origin server_has both_have_2
&&
974 grep "have $(git -C client rev-parse client_has)" trace
&&
975 grep "have $(git -C client rev-parse both_have_2)" trace
&&
976 ! grep "have $(git -C client rev-parse both_have_2^)" trace
979 test_expect_success
'use ref advertisement to prune "have" lines sent' '
980 test_negotiation_algorithm_default
983 test_expect_success
'same as last but with config overrides' '
984 test_negotiation_algorithm_default \
985 -c feature.experimental=true \
986 -c fetch.negotiationAlgorithm=consecutive
989 test_expect_success
'ensure bogus fetch.negotiationAlgorithm yields error' '
990 test_when_finished rm -rf clientv0 &&
991 cp -r client clientv0 &&
992 test_must_fail git -C clientv0 --fetch.negotiationAlgorithm=bogus \
993 fetch origin server_has both_have_2
996 test_expect_success
'filtering by size' '
997 rm -rf server client &&
998 test_create_repo server &&
999 test_commit -C server one &&
1000 test_config -C server uploadpack.allowfilter 1 &&
1002 test_create_repo client &&
1003 GIT_TRACE2_EVENT=$(pwd)/client/trace2_event \
1004 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
1006 # Ensure that object is not inadvertently fetched
1007 commit=$(git -C server rev-parse HEAD) &&
1008 blob=$(git hash-object server/one.t) &&
1009 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1010 ! grep "$blob" oids &&
1012 grep \"fetch-info\".*\"filter\":\"blob:limit\" client/trace2_event
1015 test_expect_success
'filtering by size has no effect if support for it is not advertised' '
1016 rm -rf server client &&
1017 test_create_repo server &&
1018 test_commit -C server one &&
1020 test_create_repo client &&
1021 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD 2> err &&
1023 # Ensure that object is fetched
1024 commit=$(git -C server rev-parse HEAD) &&
1025 blob=$(git hash-object server/one.t) &&
1026 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1027 grep "$blob" oids &&
1029 test_grep "filtering not recognized by server" err
1032 fetch_filter_blob_limit_zero
() {
1036 rm -rf "$SERVER" client
&&
1037 test_create_repo
"$SERVER" &&
1038 test_commit
-C "$SERVER" one
&&
1039 test_config
-C "$SERVER" uploadpack.allowfilter
1 &&
1041 git clone
"$URL" client
&&
1043 test_commit
-C "$SERVER" two
&&
1045 git
-C client fetch
--filter=blob
:limit
=0 origin HEAD
:somewhere
&&
1047 # Ensure that commit is fetched, but blob is not
1048 commit
=$
(git
-C "$SERVER" rev-parse two
) &&
1049 blob
=$
(git hash-object server
/two.t
) &&
1050 git
-C client rev-list
--objects --missing=allow-any
"$commit" >oids
&&
1051 grep "$commit" oids
&&
1055 test_expect_success
'fetch with --filter=blob:limit=0' '
1056 fetch_filter_blob_limit_zero server server
1059 .
"$TEST_DIRECTORY"/lib-httpd.sh
1062 test_expect_success
'fetch with --filter=blob:limit=0 and HTTP' '
1063 fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
1066 # DO NOT add non-httpd-specific tests here, because the last part of this
1067 # test script is only executed when httpd is available and enabled.