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
11 TEST_PASSES_SANITIZE_LEAK
=true
14 # Test fetch-pack/upload-pack pair.
16 # Some convenience functions
21 branch
=$
(echo $name |
sed -e 's/^\(.\).*$/\1/') &&
26 parents
="$parents -p $1" &&
30 echo "$text" > test.txt
&&
31 git update-index
--add test.txt
&&
32 tree
=$
(git write-tree
) &&
33 # make sure timestamps are in correct order
35 commit
=$
(echo "$text" | git commit-tree
$tree $parents) &&
36 eval "$name=$commit; export $name" &&
37 git update-ref
"refs/heads/$branch" "$commit" &&
38 eval ${branch}TIP
=$commit
45 test_expect_success
"$number pull" '
48 git fetch-pack -k -v .. $heads &&
52 git update-ref refs/heads/A "$ATIP";;
55 git update-ref refs/heads/B "$BTIP";;
58 git symbolic-ref HEAD refs/heads/$(
60 sed -e "s/^\(.\).*$/\1/"
65 mv .git/objects/pack/pack-* . &&
66 p=$(ls -1 pack-*.pack) &&
67 git unpack-objects <$p &&
70 idx=$(echo pack-*.idx) &&
71 pack_count=$(git show-index <$idx | wc -l) &&
72 test $pack_count = $count &&
78 # Here begins the actual testing
80 # A1 - ... - A20 - A21
84 # client pulls A20, B1. Then tracks only B. Then pulls A.
86 test_expect_success
'setup' '
91 git config transfer.unpacklimit 0
96 while [ $cur -le 10 ]; do
97 add A$cur $(eval echo \$A$prev) &&
99 cur=$(($cur+1)) || return 1
102 git update-ref refs/heads/A "$ATIP" &&
103 git update-ref refs/heads/B "$BTIP" &&
104 git symbolic-ref HEAD refs/heads/B
107 pull_to_client
1st
"refs/heads/B refs/heads/A" $
((11*3))
109 test_expect_success
'post 1st pull setup' '
113 while [ $cur -le 65 ]; do
114 add B$cur $(eval echo \$B$prev) &&
116 cur=$(($cur+1)) || return 1
120 pull_to_client
2nd
"refs/heads/B" $
((64*3))
122 pull_to_client
3rd
"refs/heads/A" $
((1*3))
124 test_expect_success
'single branch clone' '
125 git clone --single-branch "file://$(pwd)/." singlebranch
128 test_expect_success
'single branch object count' '
129 GIT_DIR=singlebranch/.git git count-objects -v |
130 grep "^in-pack:" > count.singlebranch &&
131 echo "in-pack: 198" >expected &&
132 test_cmp expected count.singlebranch
135 test_expect_success
'single given branch clone' '
136 GIT_TRACE2_EVENT="$(pwd)/branch-a/trace2_event" \
137 git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
138 test_must_fail git --git-dir=branch-a/.git rev-parse origin/B &&
139 grep \"fetch-info\".*\"haves\":0 branch-a/trace2_event &&
140 grep \"fetch-info\".*\"wants\":1 branch-a/trace2_event
143 test_expect_success
'clone shallow depth 1' '
144 GIT_TRACE2_EVENT="$(pwd)/shallow0/trace2_event" \
145 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
146 test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1 &&
147 grep \"fetch-info\".*\"depth\":1 shallow0/trace2_event
150 test_expect_success
'clone shallow depth 1 with fsck' '
151 git config --global fetch.fsckobjects true &&
152 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0fsck &&
153 test "$(git --git-dir=shallow0fsck/.git rev-list --count HEAD)" = 1 &&
154 git config --global --unset fetch.fsckobjects
157 test_expect_success
'clone shallow' '
158 git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
161 test_expect_success
'clone shallow depth count' '
162 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 2
165 test_expect_success
'clone shallow object count' '
170 grep "^in-pack: 12" count.shallow
173 test_expect_success
'clone shallow object count (part 2)' '
174 sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
175 -e "/: 0$/d" count.shallow > count_output &&
176 test_must_be_empty count_output
179 test_expect_success
'fsck in shallow repo' '
186 test_expect_success
'simple fetch in shallow repo' '
193 test_expect_success
'no changes expected' '
197 ) > count.shallow.2 &&
198 cmp count.shallow count.shallow.2
201 test_expect_success
'fetch same depth in shallow repo' '
208 test_expect_success
'no changes expected' '
212 ) > count.shallow.3 &&
213 cmp count.shallow count.shallow.3
216 test_expect_success
'add two more' '
221 test_expect_success
'pull in shallow repo' '
228 test_expect_success
'clone shallow object count' '
233 grep "^count: 6" count.shallow
236 test_expect_success
'add two more (part 2)' '
241 test_expect_success
'deepening pull in shallow repo' '
244 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
245 git pull --depth 4 .. B &&
246 grep \"fetch-info\".*\"depth\":4 trace2_event &&
247 grep \"fetch-info\".*\"shallows\":2 trace2_event
251 test_expect_success
'clone shallow object count' '
256 grep "^count: 12" count.shallow
259 test_expect_success
'deepening fetch in shallow repo' '
262 git fetch --depth 4 .. A:A
266 test_expect_success
'clone shallow object count' '
271 grep "^count: 18" count.shallow
274 test_expect_success
'pull in shallow repo with missing merge base' '
277 git fetch --depth 4 .. A &&
278 test_must_fail git merge --allow-unrelated-histories FETCH_HEAD
282 test_expect_success
'additional simple shallow deepenings' '
285 git fetch --depth=8 &&
286 git fetch --depth=10 &&
291 test_expect_success
'clone shallow depth count' '
292 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 11
295 test_expect_success
'clone shallow object count' '
301 grep "^count: 54" count.shallow
304 test_expect_success
'fetch --no-shallow on full repo' '
305 test_must_fail git fetch --noshallow
308 test_expect_success
'fetch --depth --no-shallow' '
311 test_must_fail git fetch --depth=1 --noshallow
315 test_expect_success
'turn shallow to complete repository' '
318 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
319 git fetch --unshallow &&
320 ! test -f .git/shallow &&
322 grep \"fetch-info\".*\"shallows\":2 trace2_event &&
323 grep \"fetch-info\".*\"depth\":2147483647 trace2_event
327 test_expect_success
'clone shallow without --no-single-branch' '
328 git clone --depth 1 "file://$(pwd)/." shallow2
331 test_expect_success
'clone shallow object count' '
335 ) > count.shallow2 &&
336 grep "^in-pack: 3" count.shallow2
339 test_expect_success
'clone shallow with --branch' '
340 git clone --depth 1 --branch A "file://$(pwd)/." shallow3
343 test_expect_success
'clone shallow object count' '
344 echo "in-pack: 3" > count3.expected &&
345 GIT_DIR=shallow3/.git git count-objects -v |
346 grep "^in-pack" > count3.actual &&
347 test_cmp count3.expected count3.actual
350 test_expect_success
'clone shallow with detached HEAD' '
351 git checkout HEAD^ &&
352 git clone --depth 1 "file://$(pwd)/." shallow5 &&
354 GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
355 git rev-parse HEAD^ >expected &&
356 test_cmp expected actual
359 test_expect_success
'shallow clone pulling tags' '
360 git tag -a -m A TAGA1 A &&
361 git tag -a -m B TAGB1 B &&
364 git clone --depth 1 "file://$(pwd)/." shallow6 &&
366 cat >taglist.expected <<\EOF &&
370 GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
371 test_cmp taglist.expected taglist.actual &&
373 echo "in-pack: 4" > count6.expected &&
374 GIT_DIR=shallow6/.git git count-objects -v |
375 grep "^in-pack" > count6.actual &&
376 test_cmp count6.expected count6.actual
379 test_expect_success
'shallow cloning single tag' '
380 git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
381 cat >taglist.expected <<\EOF &&
385 GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
386 test_cmp taglist.expected taglist.actual &&
388 echo "in-pack: 4" > count7.expected &&
389 GIT_DIR=shallow7/.git git count-objects -v |
390 grep "^in-pack" > count7.actual &&
391 test_cmp count7.expected count7.actual
394 test_expect_success
'clone shallow with packed refs' '
395 git pack-refs --all &&
396 git clone --depth 1 --branch A "file://$(pwd)/." shallow8 &&
397 echo "in-pack: 4" > count8.expected &&
398 GIT_DIR=shallow8/.git git count-objects -v |
399 grep "^in-pack" > count8.actual &&
400 test_cmp count8.expected count8.actual
403 test_expect_success
'in_vain not triggered before first ACK' '
404 rm -rf myserver myclient &&
406 test_commit -C myserver foo &&
407 git clone "file://$(pwd)/myserver" myclient &&
409 # MAX_IN_VAIN is 256. Because of batching, the client will send 496
410 # (16+32+64+128+256) commits, not 256, before giving up. So create 496
411 # irrelevant commits.
412 test_commit_bulk -C myclient 496 &&
414 # The new commit that the client wants to fetch.
415 test_commit -C myserver bar &&
417 git -C myclient fetch --progress origin 2>log &&
418 test_grep "remote: Total 3 " log
421 test_expect_success
'in_vain reset upon ACK' '
422 test_when_finished rm -f log trace2 &&
423 rm -rf myserver myclient &&
426 # Linked list of commits on main. The first is common; the rest are
428 test_commit -C myserver first_main_commit &&
429 git clone "file://$(pwd)/myserver" myclient &&
430 test_commit_bulk -C myclient 255 &&
432 # Another linked list of commits on anotherbranch with no connection to
433 # main. The first is common; the rest are not.
434 git -C myserver checkout --orphan anotherbranch &&
435 test_commit -C myserver first_anotherbranch_commit &&
436 git -C myclient fetch origin anotherbranch:refs/heads/anotherbranch &&
437 git -C myclient checkout anotherbranch &&
438 test_commit_bulk -C myclient 255 &&
440 # The new commit that the client wants to fetch.
441 git -C myserver checkout main &&
442 test_commit -C myserver to_fetch &&
444 # The client will send (as "have"s) all 256 commits in anotherbranch
445 # first. The 256th commit is common between the client and the server,
446 # and should reset in_vain. This allows negotiation to continue until
447 # the client reports that first_anotherbranch_commit is common.
448 GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
449 grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
450 test_grep "Total 3 " log
453 test_expect_success
'fetch in shallow repo unreachable shallow objects' '
455 git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&
456 git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 &&
458 git tag -d TAGB1 TAGB2 &&
459 git update-ref refs/heads/B B~~ &&
460 git gc --prune=now &&
463 git fsck --no-dangling
466 test_expect_success
'fetch creating new shallow root' '
468 git clone "file://$(pwd)/." shallow10 &&
469 git commit --allow-empty -m empty &&
471 git fetch --depth=1 --progress 2>actual &&
472 # This should fetch only the empty commit, no tree or
474 test_grep "remote: Total 1" actual
478 test_expect_success
'setup tests for the --stdin parameter' '
481 add $head || return 1
483 for head in A B C D E F
485 git tag $head $head || return 1
487 cat >input <<-\EOF &&
499 sort <input >expect &&
507 test_expect_success
'setup fetch refs from cmdline v[12]' '
508 cp -r client client0 &&
509 cp -r client client1 &&
513 for version
in '' 0 1 2
515 test_expect_success
"protocol.version=$version fetch refs from cmdline" "
518 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
520 cut -d ' ' -f 2 <output | sort >actual &&
521 test_cmp expect actual
525 test_expect_success
'fetch refs from stdin' '
528 git fetch-pack --stdin --no-progress .. <../input
530 cut -d " " -f 2 <output | sort >actual &&
531 test_cmp expect actual
534 test_expect_success
'fetch mixed refs from cmdline and stdin' '
537 tail -n +5 ../input |
538 git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
540 cut -d " " -f 2 <output | sort >actual &&
541 test_cmp expect actual
544 test_expect_success
'test duplicate refs from stdin' '
547 git fetch-pack --stdin --no-progress .. <../input.dup
549 cut -d " " -f 2 <output | sort >actual &&
550 test_cmp expect actual
553 test_expect_success
'set up tests of missing reference' '
554 cat >expect-error <<-\EOF
555 error: no such remote ref refs/heads/xyzzy
559 test_expect_success
'test lonely missing ref' '
562 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
564 test_cmp expect-error error-m
567 test_expect_success
'test missing ref after existing' '
570 test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
572 test_cmp expect-error error-em
575 test_expect_success
'test missing ref before existing' '
578 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
580 test_cmp expect-error error-me
583 test_expect_success
'test --all, --depth, and explicit head' '
586 git fetch-pack --no-progress --all --depth=1 .. refs/heads/A
587 ) >out-adh 2>error-adh
590 test_expect_success
'test --all, --depth, and explicit tag' '
591 git tag OLDTAG refs/heads/B~5 &&
594 git fetch-pack --no-progress --all --depth=1 .. refs/tags/OLDTAG
595 ) >out-adt 2>error-adt
598 test_expect_success
'test --all with tag to non-tip' '
599 git commit --allow-empty -m non-tip &&
600 git commit --allow-empty -m tip &&
601 git tag -m "annotated" non-tip HEAD^ &&
604 git fetch-pack --all ..
608 test_expect_success
'test --all wrt tag to non-commits' '
609 # create tag-to-{blob,tree,commit,tag}, making sure all tagged objects
610 # are reachable only via created tag references.
611 blob=$(echo "hello blob" | git hash-object -t blob -w --stdin) &&
612 git tag -a -m "tag -> blob" tag-to-blob $blob &&
614 tree=$(printf "100644 blob $blob\tfile" | git mktree) &&
615 git tag -a -m "tag -> tree" tag-to-tree $tree &&
617 tree2=$(printf "100644 blob $blob\tfile2" | git mktree) &&
618 commit=$(git commit-tree -m "hello commit" $tree) &&
619 git tag -a -m "tag -> commit" tag-to-commit $commit &&
621 blob2=$(echo "hello blob2" | git hash-object -t blob -w --stdin) &&
622 tag=$(git mktag <<-EOF
626 tagger author A U Thor <author@example.com> 0 +0000
631 git tag -a -m "tag -> tag" tag-to-tag $tag &&
633 # `fetch-pack --all` should succeed fetching all those objects.
638 git fetch-pack --all .. &&
639 git cat-file blob $blob >/dev/null &&
640 git cat-file tree $tree >/dev/null &&
641 git cat-file commit $commit >/dev/null &&
642 git cat-file tag $tag >/dev/null
646 test_expect_success
'shallow fetch with tags does not break the repository' '
657 git fetch --depth=2 ../.git main:branch &&
662 test_expect_success
'fetch-pack can fetch a raw sha1' '
668 git update-ref refs/hidden/one HEAD^ &&
669 git config transfer.hiderefs refs/hidden &&
670 git config uploadpack.allowtipsha1inwant true
672 git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
675 test_expect_success
'fetch-pack can fetch a raw sha1 that is advertised as a ref' '
676 rm -rf server client &&
678 test_commit -C server 1 &&
681 git -C client fetch-pack ../server \
682 $(git -C server rev-parse refs/heads/main)
685 test_expect_success
'fetch-pack can fetch a raw sha1 overlapping a named ref' '
686 rm -rf server client &&
688 test_commit -C server 1 &&
689 test_commit -C server 2 &&
692 git -C client fetch-pack ../server \
693 $(git -C server rev-parse refs/tags/1) refs/tags/1
696 test_expect_success
'fetch-pack cannot fetch a raw sha1 that is not advertised as a ref' '
700 test_commit -C server 5 &&
701 git -C server tag -d 5 &&
702 test_commit -C server 6 &&
705 # Some protocol versions (e.g. 2) support fetching
706 # unadvertised objects, so restrict this test to v0.
707 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C client fetch-pack ../server \
708 $(git -C server rev-parse refs/heads/main^) 2>err &&
709 test_grep "Server does not allow request for unadvertised object" err
713 cat >expected
<<-EOF &&
718 git fetch-pack
--diag-url "$1" |
grep -v hostandport
= >actual
&&
719 test_cmp expected actual
722 check_prot_host_port_path
() {
727 ehost
=$
(echo $3 |
tr -d "[]")
728 diagport
="Diag: port=$4"
733 ehost
=$
(echo $3$4 |
sed -e "s/22$/:22/" -e "s/NONE//")
744 grep -v "^$" exp
>expected
745 git fetch-pack
--diag-url "$1" >actual
&&
746 test_cmp expected actual
749 for r
in repo re
:po re
/po
751 # git or ssh with scheme
752 for p
in "ssh+git" "git+ssh" git
ssh
754 for h
in host user@
host user@
[::1] user@
::1
758 test_expect_success
"fetch-pack --diag-url $p://$h$c/$r" '
759 check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
761 # "/~" -> "~" conversion
762 test_expect_success
"fetch-pack --diag-url $p://$h$c/~$r" '
763 check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
767 for h
in host User@
host User@
[::1]
769 test_expect_success
"fetch-pack --diag-url $p://$h:22/$r" '
770 check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
777 test_expect_success
!WINDOWS
"fetch-pack --diag-url $p://$h/$r" '
778 check_prot_path $p://$h/$r $p "/$r"
780 test_expect_success MINGW
"fetch-pack --diag-url $p://$h/$r" '
781 check_prot_path $p://$h/$r $p "//$h/$r"
783 test_expect_success MINGW
"fetch-pack --diag-url $p:///$r" '
784 check_prot_path $p:///$r $p "/$r"
786 # No "/~" -> "~" conversion for file
787 test_expect_success
!WINDOWS
"fetch-pack --diag-url $p://$h/~$r" '
788 check_prot_path $p://$h/~$r $p "/~$r"
790 test_expect_success MINGW
"fetch-pack --diag-url $p://$h/~$r" '
791 check_prot_path $p://$h/~$r $p "//$h/~$r"
794 # file without scheme
795 for h
in nohost nohost
:12 [::1] [::1]:23 [ [:aa
797 test_expect_success
"fetch-pack --diag-url ./$h:$r" '
798 check_prot_path ./$h:$r $p "./$h:$r"
800 # No "/~" -> "~" conversion for file
801 test_expect_success
"fetch-pack --diag-url ./$p:$h/~$r" '
802 check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r"
809 expectation
="success"
810 if test_have_prereq CYGWIN
&& test "$h" = "[::1]"
812 expectation
="failure"
815 test_expect_
$expectation "fetch-pack --diag-url $h:$r" '
816 check_prot_host_port_path $h:$r $p "$h" NONE "$r"
818 # Do "/~" -> "~" conversion
819 test_expect_
$expectation "fetch-pack --diag-url $h:/~$r" '
820 check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
825 test_expect_success MINGW
'fetch-pack --diag-url file://c:/repo' '
826 check_prot_path file://c:/repo file c:/repo
828 test_expect_success MINGW
'fetch-pack --diag-url c:repo' '
829 check_prot_path c:repo file c:repo
832 test_expect_success
'clone shallow since ...' '
833 test_create_repo shallow-since &&
836 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
837 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
838 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
839 git clone --shallow-since "300000000 +0700" "file://$(pwd)/." ../shallow11 &&
840 git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
841 echo three >expected &&
842 test_cmp expected actual
846 test_expect_success
'fetch shallow since ...' '
847 GIT_TRACE2_EVENT=$(pwd)/shallow11/trace2_event \
848 git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
849 git -C shallow11 log --pretty=tformat:%s origin/main >actual &&
850 cat >expected <<-\EOF &&
854 test_cmp expected actual &&
855 grep \"fetch-info\".*\"deepen-since\":true shallow11/trace2_event
858 test_expect_success
'clone shallow since selects no commits' '
859 test_create_repo shallow-since-the-future &&
861 cd shallow-since-the-future &&
862 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
863 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
864 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
865 test_must_fail git clone --shallow-since "900000000 +0700" "file://$(pwd)/." ../shallow111
869 # A few subtle things about the request in this test:
871 # - the server must have commit-graphs present and enabled
873 # - the history is such that our want/have share a common ancestor ("base"
876 # - we send only a single have, which is fewer than a normal client would
877 # send. This ensures that we don't parse "base" up front with
878 # parse_object(), but rather traverse to it as a parent while deciding if we
879 # can stop the "have" negotiation, and call parse_commit(). The former
880 # sees the actual object data and so always loads the three oid, whereas the
881 # latter will try to load it lazily.
883 # - we must use protocol v2, because it handles the "have" negotiation before
884 # processing the shallow directives
886 test_expect_success
'shallow since with commit graph and already-seen commit' '
887 test_create_repo shallow-since-graph &&
889 cd shallow-since-graph &&
892 git checkout -b other HEAD^ &&
894 git commit-graph write --reachable &&
895 git config core.commitGraph true &&
897 GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
899 $(echo "object-format=$(test_oid algo)" | packetize)
900 00010013deepen-since 1
901 $(echo "want $(git rev-parse other)" | packetize)
902 $(echo "have $(git rev-parse main)" | packetize)
908 test_expect_success
'shallow clone exclude tag two' '
909 test_create_repo shallow-exclude &&
911 cd shallow-exclude &&
915 git clone --shallow-exclude two "file://$(pwd)/." ../shallow12 &&
916 git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
917 echo three >expected &&
918 test_cmp expected actual
922 test_expect_success
'fetch exclude tag one' '
923 git -C shallow12 fetch --shallow-exclude one origin &&
924 git -C shallow12 log --pretty=tformat:%s origin/main >actual &&
925 test_write_lines three two >expected &&
926 test_cmp expected actual
929 test_expect_success
'fetch exclude tag one as revision' '
930 test_when_finished rm -f rev err &&
931 git -C shallow-exclude rev-parse one >rev &&
932 test_must_fail git -C shallow12 fetch --shallow-exclude $(cat rev) origin 2>err &&
933 grep "deepen-not is not a ref:" err
936 test_expect_success
'fetching deepen' '
937 test_create_repo shallow-deepen &&
943 git clone --depth 1 "file://$(pwd)/." deepen &&
945 git -C deepen log --pretty=tformat:%s main >actual &&
946 echo three >expected &&
947 test_cmp expected actual &&
948 git -C deepen fetch --deepen=1 &&
949 git -C deepen log --pretty=tformat:%s origin/main >actual &&
950 cat >expected <<-\EOF &&
955 test_cmp expected actual
959 test_negotiation_algorithm_default
() {
960 test_when_finished
rm -rf clientv0 clientv2
&&
961 rm -rf server client
&&
963 test_commit
-C server both_have_1
&&
964 git
-C server tag
-d both_have_1
&&
965 test_commit
-C server both_have_2
&&
967 git clone server client
&&
968 test_commit
-C server server_has
&&
969 test_commit
-C client client_has
&&
971 # In both protocol v0 and v2, ensure that the parent of both_have_2 is
972 # not sent as a "have" line. The client should know that the server has
973 # both_have_2, so it only needs to inform the server that it has
974 # both_have_2, and the server can infer the rest.
977 cp -r client clientv0
&&
978 GIT_TRACE_PACKET
="$(pwd)/trace" git
-C clientv0 \
979 "$@" fetch origin server_has both_have_2
&&
980 grep "have $(git -C client rev-parse client_has)" trace
&&
981 grep "have $(git -C client rev-parse both_have_2)" trace
&&
982 ! grep "have $(git -C client rev-parse both_have_2^)" trace
&&
985 cp -r client clientv2
&&
986 GIT_TRACE_PACKET
="$(pwd)/trace" git
-C clientv2
-c protocol.version
=2 \
987 "$@" fetch origin server_has both_have_2
&&
988 grep "have $(git -C client rev-parse client_has)" trace
&&
989 grep "have $(git -C client rev-parse both_have_2)" trace
&&
990 ! grep "have $(git -C client rev-parse both_have_2^)" trace
993 test_expect_success
'use ref advertisement to prune "have" lines sent' '
994 test_negotiation_algorithm_default
997 test_expect_success
'same as last but with config overrides' '
998 test_negotiation_algorithm_default \
999 -c feature.experimental=true \
1000 -c fetch.negotiationAlgorithm=consecutive
1003 test_expect_success
'ensure bogus fetch.negotiationAlgorithm yields error' '
1004 test_when_finished rm -rf clientv0 &&
1005 cp -r client clientv0 &&
1006 test_must_fail git -C clientv0 --fetch.negotiationAlgorithm=bogus \
1007 fetch origin server_has both_have_2
1010 test_expect_success
'fetch-pack with fsckObjects and keep-file does not segfault' '
1011 rm -rf server client &&
1012 test_create_repo server &&
1013 test_commit -C server one &&
1015 test_create_repo client &&
1016 git -c fetch.fsckObjects=true \
1017 -C client fetch-pack -k -k ../server HEAD
1020 test_expect_success
'filtering by size' '
1021 rm -rf server client &&
1022 test_create_repo server &&
1023 test_commit -C server one &&
1024 test_config -C server uploadpack.allowfilter 1 &&
1026 test_create_repo client &&
1027 GIT_TRACE2_EVENT=$(pwd)/client/trace2_event \
1028 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
1030 # Ensure that object is not inadvertently fetched
1031 commit=$(git -C server rev-parse HEAD) &&
1032 blob=$(git hash-object server/one.t) &&
1033 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1034 ! grep "$blob" oids &&
1036 grep \"fetch-info\".*\"filter\":\"blob:limit\" client/trace2_event
1039 test_expect_success
'filtering by size has no effect if support for it is not advertised' '
1040 rm -rf server client &&
1041 test_create_repo server &&
1042 test_commit -C server one &&
1044 test_create_repo client &&
1045 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD 2> err &&
1047 # Ensure that object is fetched
1048 commit=$(git -C server rev-parse HEAD) &&
1049 blob=$(git hash-object server/one.t) &&
1050 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1051 grep "$blob" oids &&
1053 test_grep "filtering not recognized by server" err
1056 fetch_filter_blob_limit_zero
() {
1060 rm -rf "$SERVER" client
&&
1061 test_create_repo
"$SERVER" &&
1062 test_commit
-C "$SERVER" one
&&
1063 test_config
-C "$SERVER" uploadpack.allowfilter
1 &&
1065 git clone
"$URL" client
&&
1067 test_commit
-C "$SERVER" two
&&
1069 git
-C client fetch
--filter=blob
:limit
=0 origin HEAD
:somewhere
&&
1071 # Ensure that commit is fetched, but blob is not
1072 commit
=$
(git
-C "$SERVER" rev-parse two
) &&
1073 blob
=$
(git hash-object
"$SERVER/two.t") &&
1074 git
-C client rev-list
--objects --missing=allow-any
"$commit" >oids
&&
1075 grep "$commit" oids
&&
1079 test_expect_success
'fetch with --filter=blob:limit=0' '
1080 fetch_filter_blob_limit_zero server server
1083 .
"$TEST_DIRECTORY"/lib-httpd.sh
1086 test_expect_success
'fetch with --filter=blob:limit=0 and HTTP' '
1087 fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
1090 # DO NOT add non-httpd-specific tests here, because the last part of this
1091 # test script is only executed when httpd is available and enabled.