Merge branch 'rj/add-p-typo-reaction'
[git/gitster.git] / t / t5500-fetch-pack.sh
blob1bc15a3f080d3930f4f726ef7ad2bb9de38d368e
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-lib.sh
13 # Test fetch-pack/upload-pack pair.
15 # Some convenience functions
17 add () {
18 name=$1 &&
19 text="$@" &&
20 branch=$(echo $name | sed -e 's/^\(.\).*$/\1/') &&
21 parents="" &&
23 shift &&
24 while test $1; do
25 parents="$parents -p $1" &&
26 shift
27 done &&
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
33 test_tick &&
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
40 pull_to_client () {
41 number=$1 &&
42 heads=$2 &&
43 count=$3 &&
44 test_expect_success "$number pull" '
46 cd client &&
47 git fetch-pack -k -v .. $heads &&
49 case "$heads" in
50 *A*)
51 git update-ref refs/heads/A "$ATIP";;
52 esac &&
53 case "$heads" in *B*)
54 git update-ref refs/heads/B "$BTIP";;
55 esac &&
57 git symbolic-ref HEAD refs/heads/$(
58 echo $heads |
59 sed -e "s/^\(.\).*$/\1/"
60 ) &&
62 git fsck --full &&
64 mv .git/objects/pack/pack-* . &&
65 p=$(ls -1 pack-*.pack) &&
66 git unpack-objects <$p &&
67 git fsck --full &&
69 idx=$(echo pack-*.idx) &&
70 pack_count=$(git show-index <$idx | wc -l) &&
71 test $pack_count = $count &&
72 rm -f pack-*
77 # Here begins the actual testing
79 # A1 - ... - A20 - A21
80 # \
81 # B1 - B2 - .. - B70
83 # client pulls A20, B1. Then tracks only B. Then pulls A.
85 test_expect_success 'setup' '
86 mkdir client &&
88 cd client &&
89 git init &&
90 git config transfer.unpacklimit 0
91 ) &&
92 add A1 &&
93 prev=1 &&
94 cur=2 &&
95 while [ $cur -le 10 ]; do
96 add A$cur $(eval echo \$A$prev) &&
97 prev=$cur &&
98 cur=$(($cur+1)) || return 1
99 done &&
100 add B1 $A1 &&
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' '
109 add A11 $A10 &&
110 prev=1 &&
111 cur=2 &&
112 while [ $cur -le 65 ]; do
113 add B$cur $(eval echo \$B$prev) &&
114 prev=$cur &&
115 cur=$(($cur+1)) || return 1
116 done
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' '
166 cd shallow &&
167 git count-objects -v
168 ) > count.shallow &&
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' '
180 cd shallow &&
181 git fsck --full
185 test_expect_success 'simple fetch in shallow repo' '
187 cd shallow &&
188 git fetch
192 test_expect_success 'no changes expected' '
194 cd shallow &&
195 git count-objects -v
196 ) > count.shallow.2 &&
197 cmp count.shallow count.shallow.2
200 test_expect_success 'fetch same depth in shallow repo' '
202 cd shallow &&
203 git fetch --depth=2
207 test_expect_success 'no changes expected' '
209 cd shallow &&
210 git count-objects -v
211 ) > count.shallow.3 &&
212 cmp count.shallow count.shallow.3
215 test_expect_success 'add two more' '
216 add B66 $B65 &&
217 add B67 $B66
220 test_expect_success 'pull in shallow repo' '
222 cd shallow &&
223 git pull .. B
227 test_expect_success 'clone shallow object count' '
229 cd shallow &&
230 git count-objects -v
231 ) > count.shallow &&
232 grep "^count: 6" count.shallow
235 test_expect_success 'add two more (part 2)' '
236 add B68 $B67 &&
237 add B69 $B68
240 test_expect_success 'deepening pull in shallow repo' '
242 cd shallow &&
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' '
252 cd shallow &&
253 git count-objects -v
254 ) > count.shallow &&
255 grep "^count: 12" count.shallow
258 test_expect_success 'deepening fetch in shallow repo' '
260 cd shallow &&
261 git fetch --depth 4 .. A:A
265 test_expect_success 'clone shallow object count' '
267 cd shallow &&
268 git count-objects -v
269 ) > count.shallow &&
270 grep "^count: 18" count.shallow
273 test_expect_success 'pull in shallow repo with missing merge base' '
275 cd shallow &&
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' '
283 cd shallow &&
284 git fetch --depth=8 &&
285 git fetch --depth=10 &&
286 git fetch --depth=11
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' '
296 cd shallow &&
297 git prune &&
298 git count-objects -v
299 ) > count.shallow &&
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' '
309 cd shallow &&
310 test_must_fail git fetch --depth=1 --noshallow
314 test_expect_success 'turn shallow to complete repository' '
316 cd shallow &&
317 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
318 git fetch --unshallow &&
319 ! test -f .git/shallow &&
320 git fsck --full &&
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' '
332 cd shallow2 &&
333 git count-objects -v
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 &&
352 git checkout - &&
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 &&
361 git tag TAGA2 A &&
362 git tag TAGB2 B &&
363 git clone --depth 1 "file://$(pwd)/." shallow6 &&
365 cat >taglist.expected <<\EOF &&
366 TAGB1
367 TAGB2
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 &&
381 TAGB1
382 TAGB2
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 &&
404 git init myserver &&
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 &&
423 git init myserver &&
425 # Linked list of commits on main. The first is common; the rest are
426 # not.
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 &&
456 cd no-reflog &&
457 git tag -d TAGB1 TAGB2 &&
458 git update-ref refs/heads/B B~~ &&
459 git gc --prune=now &&
460 cd ../shallow9 &&
461 git fetch origin &&
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 &&
469 cd shallow10 &&
470 git fetch --depth=1 --progress 2>actual &&
471 # This should fetch only the empty commit, no tree or
472 # blob objects
473 test_grep "remote: Total 1" actual
477 test_expect_success 'setup tests for the --stdin parameter' '
478 for head in C D E F
480 add $head || return 1
481 done &&
482 for head in A B C D E F
484 git tag $head $head || return 1
485 done &&
486 cat >input <<-\EOF &&
487 refs/heads/C
488 refs/heads/A
489 refs/heads/D
490 refs/tags/C
491 refs/heads/B
492 refs/tags/A
493 refs/heads/E
494 refs/tags/B
495 refs/tags/E
496 refs/tags/D
498 sort <input >expect &&
500 echo refs/heads/E &&
501 echo refs/tags/E &&
502 cat input
503 ) >input.dup
506 test_expect_success 'setup fetch refs from cmdline v[12]' '
507 cp -r client client0 &&
508 cp -r client client1 &&
509 cp -r client client2
512 for version in '' 0 1 2
514 test_expect_success "protocol.version=$version fetch refs from cmdline" "
516 cd client$version &&
517 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
518 ) >output &&
519 cut -d ' ' -f 2 <output | sort >actual &&
520 test_cmp expect actual
522 done
524 test_expect_success 'fetch refs from stdin' '
526 cd client &&
527 git fetch-pack --stdin --no-progress .. <../input
528 ) >output &&
529 cut -d " " -f 2 <output | sort >actual &&
530 test_cmp expect actual
533 test_expect_success 'fetch mixed refs from cmdline and stdin' '
535 cd client &&
536 tail -n +5 ../input |
537 git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
538 ) >output &&
539 cut -d " " -f 2 <output | sort >actual &&
540 test_cmp expect actual
543 test_expect_success 'test duplicate refs from stdin' '
545 cd client &&
546 git fetch-pack --stdin --no-progress .. <../input.dup
547 ) >output &&
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' '
560 cd client &&
561 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
562 ) &&
563 test_cmp expect-error error-m
566 test_expect_success 'test missing ref after existing' '
568 cd client &&
569 test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
570 ) &&
571 test_cmp expect-error error-em
574 test_expect_success 'test missing ref before existing' '
576 cd client &&
577 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
578 ) &&
579 test_cmp expect-error error-me
582 test_expect_success 'test --all, --depth, and explicit head' '
584 cd client &&
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 &&
592 cd client &&
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^ &&
602 cd client &&
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
622 object $blob2
623 type blob
624 tag tag-to-blob2
625 tagger author A U Thor <author@example.com> 0 +0000
627 hello tag
629 ) &&
630 git tag -a -m "tag -> tag" tag-to-tag $tag &&
632 # `fetch-pack --all` should succeed fetching all those objects.
633 mkdir fetchall &&
635 cd fetchall &&
636 git init &&
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' '
646 mkdir repo1 &&
648 cd repo1 &&
649 git init &&
650 test_commit 1 &&
651 test_commit 2 &&
652 test_commit 3 &&
653 mkdir repo2 &&
654 cd repo2 &&
655 git init &&
656 git fetch --depth=2 ../.git main:branch &&
657 git fsck
661 test_expect_success 'fetch-pack can fetch a raw sha1' '
662 git init hidden &&
664 cd hidden &&
665 test_commit 1 &&
666 test_commit 2 &&
667 git update-ref refs/hidden/one HEAD^ &&
668 git config transfer.hiderefs refs/hidden &&
669 git config uploadpack.allowtipsha1inwant true
670 ) &&
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 &&
676 git init server &&
677 test_commit -C server 1 &&
679 git init client &&
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 &&
686 git init server &&
687 test_commit -C server 1 &&
688 test_commit -C server 2 &&
690 git init client &&
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' '
696 rm -rf server &&
698 git init server &&
699 test_commit -C server 5 &&
700 git -C server tag -d 5 &&
701 test_commit -C server 6 &&
703 git init client &&
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
711 check_prot_path () {
712 cat >expected <<-EOF &&
713 Diag: url=$1
714 Diag: protocol=$2
715 Diag: path=$3
717 git fetch-pack --diag-url "$1" | grep -v hostandport= >actual &&
718 test_cmp expected actual
721 check_prot_host_port_path () {
722 case "$2" in
723 *ssh*)
724 pp=ssh
725 uah=userandhost
726 ehost=$(echo $3 | tr -d "[]")
727 diagport="Diag: port=$4"
730 pp=$p
731 uah=hostandport
732 ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
733 diagport=""
735 esac
736 cat >exp <<-EOF &&
737 Diag: url=$1
738 Diag: protocol=$pp
739 Diag: $uah=$ehost
740 $diagport
741 Diag: path=$5
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
755 for c in "" :
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"
764 done
765 done
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"
771 done
772 done
773 # file with scheme
774 for p in file
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"
792 done
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"
803 done
804 #ssh without scheme
805 p=ssh
806 for h in host [::1]
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"
815 done
816 done
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 &&
828 cd 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 &&
844 three
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"
867 # here)
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 &&
883 test_commit base &&
884 test_commit main &&
885 git checkout -b other HEAD^ &&
886 test_commit other &&
887 git commit-graph write --reachable &&
888 git config core.commitGraph true &&
890 GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
891 0012command=fetch
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)
896 0000
901 test_expect_success 'shallow clone exclude tag two' '
902 test_create_repo shallow-exclude &&
904 cd shallow-exclude &&
905 test_commit one &&
906 test_commit two &&
907 test_commit three &&
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 &&
925 cd shallow-deepen &&
926 test_commit one &&
927 test_commit two &&
928 test_commit three &&
929 git clone --depth 1 "file://$(pwd)/." deepen &&
930 test_commit four &&
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 &&
937 four
938 three
941 test_cmp expected actual
945 test_negotiation_algorithm_default () {
946 test_when_finished rm -rf clientv0 clientv2 &&
947 rm -rf server client &&
948 git init server &&
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.
962 rm -f trace &&
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 &&
970 rm -f 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 () {
1033 SERVER="$1"
1034 URL="$2"
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 &&
1052 ! grep "$blob" 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
1060 start_httpd
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.
1069 test_done