Sync with 'maint'
[alt-git.git] / t / t5500-fetch-pack.sh
blob6552da78d19490274df3013ae1af2bf8e179d01d
1 #!/bin/sh
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
12 . ./test-lib.sh
14 # Test fetch-pack/upload-pack pair.
16 # Some convenience functions
18 add () {
19 name=$1 &&
20 text="$@" &&
21 branch=$(echo $name | sed -e 's/^\(.\).*$/\1/') &&
22 parents="" &&
24 shift &&
25 while test $1; do
26 parents="$parents -p $1" &&
27 shift
28 done &&
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
34 test_tick &&
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
41 pull_to_client () {
42 number=$1 &&
43 heads=$2 &&
44 count=$3 &&
45 test_expect_success "$number pull" '
47 cd client &&
48 git fetch-pack -k -v .. $heads &&
50 case "$heads" in
51 *A*)
52 git update-ref refs/heads/A "$ATIP";;
53 esac &&
54 case "$heads" in *B*)
55 git update-ref refs/heads/B "$BTIP";;
56 esac &&
58 git symbolic-ref HEAD refs/heads/$(
59 echo $heads |
60 sed -e "s/^\(.\).*$/\1/"
61 ) &&
63 git fsck --full &&
65 mv .git/objects/pack/pack-* . &&
66 p=$(ls -1 pack-*.pack) &&
67 git unpack-objects <$p &&
68 git fsck --full &&
70 idx=$(echo pack-*.idx) &&
71 pack_count=$(git show-index <$idx | wc -l) &&
72 test $pack_count = $count &&
73 rm -f pack-*
78 # Here begins the actual testing
80 # A1 - ... - A20 - A21
81 # \
82 # B1 - B2 - .. - B70
84 # client pulls A20, B1. Then tracks only B. Then pulls A.
86 test_expect_success 'setup' '
87 mkdir client &&
89 cd client &&
90 git init &&
91 git config transfer.unpacklimit 0
92 ) &&
93 add A1 &&
94 prev=1 &&
95 cur=2 &&
96 while [ $cur -le 10 ]; do
97 add A$cur $(eval echo \$A$prev) &&
98 prev=$cur &&
99 cur=$(($cur+1)) || return 1
100 done &&
101 add B1 $A1 &&
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' '
110 add A11 $A10 &&
111 prev=1 &&
112 cur=2 &&
113 while [ $cur -le 65 ]; do
114 add B$cur $(eval echo \$B$prev) &&
115 prev=$cur &&
116 cur=$(($cur+1)) || return 1
117 done
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' '
167 cd shallow &&
168 git count-objects -v
169 ) > count.shallow &&
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' '
181 cd shallow &&
182 git fsck --full
186 test_expect_success 'simple fetch in shallow repo' '
188 cd shallow &&
189 git fetch
193 test_expect_success 'no changes expected' '
195 cd shallow &&
196 git count-objects -v
197 ) > count.shallow.2 &&
198 cmp count.shallow count.shallow.2
201 test_expect_success 'fetch same depth in shallow repo' '
203 cd shallow &&
204 git fetch --depth=2
208 test_expect_success 'no changes expected' '
210 cd shallow &&
211 git count-objects -v
212 ) > count.shallow.3 &&
213 cmp count.shallow count.shallow.3
216 test_expect_success 'add two more' '
217 add B66 $B65 &&
218 add B67 $B66
221 test_expect_success 'pull in shallow repo' '
223 cd shallow &&
224 git pull .. B
228 test_expect_success 'clone shallow object count' '
230 cd shallow &&
231 git count-objects -v
232 ) > count.shallow &&
233 grep "^count: 6" count.shallow
236 test_expect_success 'add two more (part 2)' '
237 add B68 $B67 &&
238 add B69 $B68
241 test_expect_success 'deepening pull in shallow repo' '
243 cd shallow &&
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' '
253 cd shallow &&
254 git count-objects -v
255 ) > count.shallow &&
256 grep "^count: 12" count.shallow
259 test_expect_success 'deepening fetch in shallow repo' '
261 cd shallow &&
262 git fetch --depth 4 .. A:A
266 test_expect_success 'clone shallow object count' '
268 cd shallow &&
269 git count-objects -v
270 ) > count.shallow &&
271 grep "^count: 18" count.shallow
274 test_expect_success 'pull in shallow repo with missing merge base' '
276 cd shallow &&
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' '
284 cd shallow &&
285 git fetch --depth=8 &&
286 git fetch --depth=10 &&
287 git fetch --depth=11
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' '
297 cd shallow &&
298 git prune &&
299 git count-objects -v
300 ) > count.shallow &&
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' '
310 cd shallow &&
311 test_must_fail git fetch --depth=1 --noshallow
315 test_expect_success 'turn shallow to complete repository' '
317 cd shallow &&
318 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
319 git fetch --unshallow &&
320 ! test -f .git/shallow &&
321 git fsck --full &&
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' '
333 cd shallow2 &&
334 git count-objects -v
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 &&
353 git checkout - &&
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 &&
362 git tag TAGA2 A &&
363 git tag TAGB2 B &&
364 git clone --depth 1 "file://$(pwd)/." shallow6 &&
366 cat >taglist.expected <<\EOF &&
367 TAGB1
368 TAGB2
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 &&
382 TAGB1
383 TAGB2
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 &&
405 git init myserver &&
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 &&
424 git init myserver &&
426 # Linked list of commits on main. The first is common; the rest are
427 # not.
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 &&
457 cd no-reflog &&
458 git tag -d TAGB1 TAGB2 &&
459 git update-ref refs/heads/B B~~ &&
460 git gc --prune=now &&
461 cd ../shallow9 &&
462 git fetch origin &&
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 &&
470 cd shallow10 &&
471 git fetch --depth=1 --progress 2>actual &&
472 # This should fetch only the empty commit, no tree or
473 # blob objects
474 test_grep "remote: Total 1" actual
478 test_expect_success 'setup tests for the --stdin parameter' '
479 for head in C D E F
481 add $head || return 1
482 done &&
483 for head in A B C D E F
485 git tag $head $head || return 1
486 done &&
487 cat >input <<-\EOF &&
488 refs/heads/C
489 refs/heads/A
490 refs/heads/D
491 refs/tags/C
492 refs/heads/B
493 refs/tags/A
494 refs/heads/E
495 refs/tags/B
496 refs/tags/E
497 refs/tags/D
499 sort <input >expect &&
501 echo refs/heads/E &&
502 echo refs/tags/E &&
503 cat input
504 ) >input.dup
507 test_expect_success 'setup fetch refs from cmdline v[12]' '
508 cp -r client client0 &&
509 cp -r client client1 &&
510 cp -r client client2
513 for version in '' 0 1 2
515 test_expect_success "protocol.version=$version fetch refs from cmdline" "
517 cd client$version &&
518 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
519 ) >output &&
520 cut -d ' ' -f 2 <output | sort >actual &&
521 test_cmp expect actual
523 done
525 test_expect_success 'fetch refs from stdin' '
527 cd client &&
528 git fetch-pack --stdin --no-progress .. <../input
529 ) >output &&
530 cut -d " " -f 2 <output | sort >actual &&
531 test_cmp expect actual
534 test_expect_success 'fetch mixed refs from cmdline and stdin' '
536 cd client &&
537 tail -n +5 ../input |
538 git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
539 ) >output &&
540 cut -d " " -f 2 <output | sort >actual &&
541 test_cmp expect actual
544 test_expect_success 'test duplicate refs from stdin' '
546 cd client &&
547 git fetch-pack --stdin --no-progress .. <../input.dup
548 ) >output &&
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' '
561 cd client &&
562 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
563 ) &&
564 test_cmp expect-error error-m
567 test_expect_success 'test missing ref after existing' '
569 cd client &&
570 test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
571 ) &&
572 test_cmp expect-error error-em
575 test_expect_success 'test missing ref before existing' '
577 cd client &&
578 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
579 ) &&
580 test_cmp expect-error error-me
583 test_expect_success 'test --all, --depth, and explicit head' '
585 cd client &&
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 &&
593 cd client &&
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^ &&
603 cd client &&
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
623 object $blob2
624 type blob
625 tag tag-to-blob2
626 tagger author A U Thor <author@example.com> 0 +0000
628 hello tag
630 ) &&
631 git tag -a -m "tag -> tag" tag-to-tag $tag &&
633 # `fetch-pack --all` should succeed fetching all those objects.
634 mkdir fetchall &&
636 cd fetchall &&
637 git init &&
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' '
647 mkdir repo1 &&
649 cd repo1 &&
650 git init &&
651 test_commit 1 &&
652 test_commit 2 &&
653 test_commit 3 &&
654 mkdir repo2 &&
655 cd repo2 &&
656 git init &&
657 git fetch --depth=2 ../.git main:branch &&
658 git fsck
662 test_expect_success 'fetch-pack can fetch a raw sha1' '
663 git init hidden &&
665 cd hidden &&
666 test_commit 1 &&
667 test_commit 2 &&
668 git update-ref refs/hidden/one HEAD^ &&
669 git config transfer.hiderefs refs/hidden &&
670 git config uploadpack.allowtipsha1inwant true
671 ) &&
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 &&
677 git init server &&
678 test_commit -C server 1 &&
680 git init client &&
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 &&
687 git init server &&
688 test_commit -C server 1 &&
689 test_commit -C server 2 &&
691 git init client &&
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' '
697 rm -rf server &&
699 git init server &&
700 test_commit -C server 5 &&
701 git -C server tag -d 5 &&
702 test_commit -C server 6 &&
704 git init client &&
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
712 check_prot_path () {
713 cat >expected <<-EOF &&
714 Diag: url=$1
715 Diag: protocol=$2
716 Diag: path=$3
718 git fetch-pack --diag-url "$1" | grep -v hostandport= >actual &&
719 test_cmp expected actual
722 check_prot_host_port_path () {
723 case "$2" in
724 *ssh*)
725 pp=ssh
726 uah=userandhost
727 ehost=$(echo $3 | tr -d "[]")
728 diagport="Diag: port=$4"
731 pp=$p
732 uah=hostandport
733 ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
734 diagport=""
736 esac
737 cat >exp <<-EOF &&
738 Diag: url=$1
739 Diag: protocol=$pp
740 Diag: $uah=$ehost
741 $diagport
742 Diag: path=$5
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
756 for c in "" :
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"
765 done
766 done
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"
772 done
773 done
774 # file with scheme
775 for p in file
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"
793 done
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"
804 done
805 #ssh without scheme
806 p=ssh
807 for h in host [::1]
809 expectation="success"
810 if test_have_prereq CYGWIN && test "$h" = "[::1]"
811 then
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"
822 done
823 done
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 &&
835 cd 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 &&
851 three
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"
874 # here)
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 &&
890 test_commit base &&
891 test_commit main &&
892 git checkout -b other HEAD^ &&
893 test_commit other &&
894 git commit-graph write --reachable &&
895 git config core.commitGraph true &&
897 GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
898 0012command=fetch
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)
903 0000
908 test_expect_success 'shallow clone exclude tag two' '
909 test_create_repo shallow-exclude &&
911 cd shallow-exclude &&
912 test_commit one &&
913 test_commit two &&
914 test_commit three &&
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 &&
939 cd shallow-deepen &&
940 test_commit one &&
941 test_commit two &&
942 test_commit three &&
943 git clone --depth 1 "file://$(pwd)/." deepen &&
944 test_commit four &&
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 &&
951 four
952 three
955 test_cmp expected actual
959 test_negotiation_algorithm_default () {
960 test_when_finished rm -rf clientv0 clientv2 &&
961 rm -rf server client &&
962 git init server &&
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.
976 rm -f trace &&
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 &&
984 rm -f 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 () {
1057 SERVER="$1"
1058 URL="$2"
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 &&
1076 ! grep "$blob" 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
1084 start_httpd
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.
1093 test_done