unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t5500-fetch-pack.sh
blobd18f2823d86e8b94c5331b1087f962469fc91f2c
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 clone --single-branch --branch A "file://$(pwd)/." branch-a &&
136 test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
139 test_expect_success 'clone shallow depth 1' '
140 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0 &&
141 test "$(git --git-dir=shallow0/.git rev-list --count HEAD)" = 1
144 test_expect_success 'clone shallow depth 1 with fsck' '
145 git config --global fetch.fsckobjects true &&
146 git clone --no-single-branch --depth 1 "file://$(pwd)/." shallow0fsck &&
147 test "$(git --git-dir=shallow0fsck/.git rev-list --count HEAD)" = 1 &&
148 git config --global --unset fetch.fsckobjects
151 test_expect_success 'clone shallow' '
152 git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
155 test_expect_success 'clone shallow depth count' '
156 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 2
159 test_expect_success 'clone shallow object count' '
161 cd shallow &&
162 git count-objects -v
163 ) > count.shallow &&
164 grep "^in-pack: 12" count.shallow
167 test_expect_success 'clone shallow object count (part 2)' '
168 sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
169 -e "/: 0$/d" count.shallow > count_output &&
170 test_must_be_empty count_output
173 test_expect_success 'fsck in shallow repo' '
175 cd shallow &&
176 git fsck --full
180 test_expect_success 'simple fetch in shallow repo' '
182 cd shallow &&
183 git fetch
187 test_expect_success 'no changes expected' '
189 cd shallow &&
190 git count-objects -v
191 ) > count.shallow.2 &&
192 cmp count.shallow count.shallow.2
195 test_expect_success 'fetch same depth in shallow repo' '
197 cd shallow &&
198 git fetch --depth=2
202 test_expect_success 'no changes expected' '
204 cd shallow &&
205 git count-objects -v
206 ) > count.shallow.3 &&
207 cmp count.shallow count.shallow.3
210 test_expect_success 'add two more' '
211 add B66 $B65 &&
212 add B67 $B66
215 test_expect_success 'pull in shallow repo' '
217 cd shallow &&
218 git pull .. B
222 test_expect_success 'clone shallow object count' '
224 cd shallow &&
225 git count-objects -v
226 ) > count.shallow &&
227 grep "^count: 6" count.shallow
230 test_expect_success 'add two more (part 2)' '
231 add B68 $B67 &&
232 add B69 $B68
235 test_expect_success 'deepening pull in shallow repo' '
237 cd shallow &&
238 git pull --depth 4 .. B
242 test_expect_success 'clone shallow object count' '
244 cd shallow &&
245 git count-objects -v
246 ) > count.shallow &&
247 grep "^count: 12" count.shallow
250 test_expect_success 'deepening fetch in shallow repo' '
252 cd shallow &&
253 git fetch --depth 4 .. A:A
257 test_expect_success 'clone shallow object count' '
259 cd shallow &&
260 git count-objects -v
261 ) > count.shallow &&
262 grep "^count: 18" count.shallow
265 test_expect_success 'pull in shallow repo with missing merge base' '
267 cd shallow &&
268 git fetch --depth 4 .. A &&
269 test_must_fail git merge --allow-unrelated-histories FETCH_HEAD
273 test_expect_success 'additional simple shallow deepenings' '
275 cd shallow &&
276 git fetch --depth=8 &&
277 git fetch --depth=10 &&
278 git fetch --depth=11
282 test_expect_success 'clone shallow depth count' '
283 test "$(git --git-dir=shallow/.git rev-list --count HEAD)" = 11
286 test_expect_success 'clone shallow object count' '
288 cd shallow &&
289 git prune &&
290 git count-objects -v
291 ) > count.shallow &&
292 grep "^count: 54" count.shallow
295 test_expect_success 'fetch --no-shallow on full repo' '
296 test_must_fail git fetch --noshallow
299 test_expect_success 'fetch --depth --no-shallow' '
301 cd shallow &&
302 test_must_fail git fetch --depth=1 --noshallow
306 test_expect_success 'turn shallow to complete repository' '
308 cd shallow &&
309 git fetch --unshallow &&
310 ! test -f .git/shallow &&
311 git fsck --full
315 test_expect_success 'clone shallow without --no-single-branch' '
316 git clone --depth 1 "file://$(pwd)/." shallow2
319 test_expect_success 'clone shallow object count' '
321 cd shallow2 &&
322 git count-objects -v
323 ) > count.shallow2 &&
324 grep "^in-pack: 3" count.shallow2
327 test_expect_success 'clone shallow with --branch' '
328 git clone --depth 1 --branch A "file://$(pwd)/." shallow3
331 test_expect_success 'clone shallow object count' '
332 echo "in-pack: 3" > count3.expected &&
333 GIT_DIR=shallow3/.git git count-objects -v |
334 grep "^in-pack" > count3.actual &&
335 test_cmp count3.expected count3.actual
338 test_expect_success 'clone shallow with detached HEAD' '
339 git checkout HEAD^ &&
340 git clone --depth 1 "file://$(pwd)/." shallow5 &&
341 git checkout - &&
342 GIT_DIR=shallow5/.git git rev-parse HEAD >actual &&
343 git rev-parse HEAD^ >expected &&
344 test_cmp expected actual
347 test_expect_success 'shallow clone pulling tags' '
348 git tag -a -m A TAGA1 A &&
349 git tag -a -m B TAGB1 B &&
350 git tag TAGA2 A &&
351 git tag TAGB2 B &&
352 git clone --depth 1 "file://$(pwd)/." shallow6 &&
354 cat >taglist.expected <<\EOF &&
355 TAGB1
356 TAGB2
358 GIT_DIR=shallow6/.git git tag -l >taglist.actual &&
359 test_cmp taglist.expected taglist.actual &&
361 echo "in-pack: 4" > count6.expected &&
362 GIT_DIR=shallow6/.git git count-objects -v |
363 grep "^in-pack" > count6.actual &&
364 test_cmp count6.expected count6.actual
367 test_expect_success 'shallow cloning single tag' '
368 git clone --depth 1 --branch=TAGB1 "file://$(pwd)/." shallow7 &&
369 cat >taglist.expected <<\EOF &&
370 TAGB1
371 TAGB2
373 GIT_DIR=shallow7/.git git tag -l >taglist.actual &&
374 test_cmp taglist.expected taglist.actual &&
376 echo "in-pack: 4" > count7.expected &&
377 GIT_DIR=shallow7/.git git count-objects -v |
378 grep "^in-pack" > count7.actual &&
379 test_cmp count7.expected count7.actual
382 test_expect_success 'clone shallow with packed refs' '
383 git pack-refs --all &&
384 git clone --depth 1 --branch A "file://$(pwd)/." shallow8 &&
385 echo "in-pack: 4" > count8.expected &&
386 GIT_DIR=shallow8/.git git count-objects -v |
387 grep "^in-pack" > count8.actual &&
388 test_cmp count8.expected count8.actual
391 test_expect_success 'in_vain not triggered before first ACK' '
392 rm -rf myserver myclient &&
393 git init myserver &&
394 test_commit -C myserver foo &&
395 git clone "file://$(pwd)/myserver" myclient &&
397 # MAX_IN_VAIN is 256. Because of batching, the client will send 496
398 # (16+32+64+128+256) commits, not 256, before giving up. So create 496
399 # irrelevant commits.
400 test_commit_bulk -C myclient 496 &&
402 # The new commit that the client wants to fetch.
403 test_commit -C myserver bar &&
405 git -C myclient fetch --progress origin 2>log &&
406 test_i18ngrep "remote: Total 3 " log
409 test_expect_success 'in_vain resetted upon ACK' '
410 test_when_finished rm -f log trace2 &&
411 rm -rf myserver myclient &&
412 git init myserver &&
414 # Linked list of commits on main. The first is common; the rest are
415 # not.
416 test_commit -C myserver first_main_commit &&
417 git clone "file://$(pwd)/myserver" myclient &&
418 test_commit_bulk -C myclient 255 &&
420 # Another linked list of commits on anotherbranch with no connection to
421 # main. The first is common; the rest are not.
422 git -C myserver checkout --orphan anotherbranch &&
423 test_commit -C myserver first_anotherbranch_commit &&
424 git -C myclient fetch origin anotherbranch:refs/heads/anotherbranch &&
425 git -C myclient checkout anotherbranch &&
426 test_commit_bulk -C myclient 255 &&
428 # The new commit that the client wants to fetch.
429 git -C myserver checkout main &&
430 test_commit -C myserver to_fetch &&
432 # The client will send (as "have"s) all 256 commits in anotherbranch
433 # first. The 256th commit is common between the client and the server,
434 # and should reset in_vain. This allows negotiation to continue until
435 # the client reports that first_anotherbranch_commit is common.
436 GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
437 grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
438 test_i18ngrep "Total 3 " log
441 test_expect_success 'fetch in shallow repo unreachable shallow objects' '
443 git clone --bare --branch B --single-branch "file://$(pwd)/." no-reflog &&
444 git clone --depth 1 "file://$(pwd)/no-reflog" shallow9 &&
445 cd no-reflog &&
446 git tag -d TAGB1 TAGB2 &&
447 git update-ref refs/heads/B B~~ &&
448 git gc --prune=now &&
449 cd ../shallow9 &&
450 git fetch origin &&
451 git fsck --no-dangling
454 test_expect_success 'fetch creating new shallow root' '
456 git clone "file://$(pwd)/." shallow10 &&
457 git commit --allow-empty -m empty &&
458 cd shallow10 &&
459 git fetch --depth=1 --progress 2>actual &&
460 # This should fetch only the empty commit, no tree or
461 # blob objects
462 test_i18ngrep "remote: Total 1" actual
466 test_expect_success 'setup tests for the --stdin parameter' '
467 for head in C D E F
469 add $head || return 1
470 done &&
471 for head in A B C D E F
473 git tag $head $head || return 1
474 done &&
475 cat >input <<-\EOF &&
476 refs/heads/C
477 refs/heads/A
478 refs/heads/D
479 refs/tags/C
480 refs/heads/B
481 refs/tags/A
482 refs/heads/E
483 refs/tags/B
484 refs/tags/E
485 refs/tags/D
487 sort <input >expect &&
489 echo refs/heads/E &&
490 echo refs/tags/E &&
491 cat input
492 ) >input.dup
495 test_expect_success 'setup fetch refs from cmdline v[12]' '
496 cp -r client client0 &&
497 cp -r client client1 &&
498 cp -r client client2
501 for version in '' 0 1 2
503 test_expect_success "protocol.version=$version fetch refs from cmdline" "
505 cd client$version &&
506 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input)
507 ) >output &&
508 cut -d ' ' -f 2 <output | sort >actual &&
509 test_cmp expect actual
511 done
513 test_expect_success 'fetch refs from stdin' '
515 cd client &&
516 git fetch-pack --stdin --no-progress .. <../input
517 ) >output &&
518 cut -d " " -f 2 <output | sort >actual &&
519 test_cmp expect actual
522 test_expect_success 'fetch mixed refs from cmdline and stdin' '
524 cd client &&
525 tail -n +5 ../input |
526 git fetch-pack --stdin --no-progress .. $(head -n 4 ../input)
527 ) >output &&
528 cut -d " " -f 2 <output | sort >actual &&
529 test_cmp expect actual
532 test_expect_success 'test duplicate refs from stdin' '
534 cd client &&
535 git fetch-pack --stdin --no-progress .. <../input.dup
536 ) >output &&
537 cut -d " " -f 2 <output | sort >actual &&
538 test_cmp expect actual
541 test_expect_success 'set up tests of missing reference' '
542 cat >expect-error <<-\EOF
543 error: no such remote ref refs/heads/xyzzy
547 test_expect_success 'test lonely missing ref' '
549 cd client &&
550 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy 2>../error-m
551 ) &&
552 test_cmp expect-error error-m
555 test_expect_success 'test missing ref after existing' '
557 cd client &&
558 test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy 2>../error-em
559 ) &&
560 test_cmp expect-error error-em
563 test_expect_success 'test missing ref before existing' '
565 cd client &&
566 test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A 2>../error-me
567 ) &&
568 test_cmp expect-error error-me
571 test_expect_success 'test --all, --depth, and explicit head' '
573 cd client &&
574 git fetch-pack --no-progress --all --depth=1 .. refs/heads/A
575 ) >out-adh 2>error-adh
578 test_expect_success 'test --all, --depth, and explicit tag' '
579 git tag OLDTAG refs/heads/B~5 &&
581 cd client &&
582 git fetch-pack --no-progress --all --depth=1 .. refs/tags/OLDTAG
583 ) >out-adt 2>error-adt
586 test_expect_success 'test --all with tag to non-tip' '
587 git commit --allow-empty -m non-tip &&
588 git commit --allow-empty -m tip &&
589 git tag -m "annotated" non-tip HEAD^ &&
591 cd client &&
592 git fetch-pack --all ..
596 test_expect_success 'test --all wrt tag to non-commits' '
597 # create tag-to-{blob,tree,commit,tag}, making sure all tagged objects
598 # are reachable only via created tag references.
599 blob=$(echo "hello blob" | git hash-object -t blob -w --stdin) &&
600 git tag -a -m "tag -> blob" tag-to-blob $blob &&
602 tree=$(printf "100644 blob $blob\tfile" | git mktree) &&
603 git tag -a -m "tag -> tree" tag-to-tree $tree &&
605 tree2=$(printf "100644 blob $blob\tfile2" | git mktree) &&
606 commit=$(git commit-tree -m "hello commit" $tree) &&
607 git tag -a -m "tag -> commit" tag-to-commit $commit &&
609 blob2=$(echo "hello blob2" | git hash-object -t blob -w --stdin) &&
610 tag=$(git mktag <<-EOF
611 object $blob2
612 type blob
613 tag tag-to-blob2
614 tagger author A U Thor <author@example.com> 0 +0000
616 hello tag
618 ) &&
619 git tag -a -m "tag -> tag" tag-to-tag $tag &&
621 # `fetch-pack --all` should succeed fetching all those objects.
622 mkdir fetchall &&
624 cd fetchall &&
625 git init &&
626 git fetch-pack --all .. &&
627 git cat-file blob $blob >/dev/null &&
628 git cat-file tree $tree >/dev/null &&
629 git cat-file commit $commit >/dev/null &&
630 git cat-file tag $tag >/dev/null
634 test_expect_success 'shallow fetch with tags does not break the repository' '
635 mkdir repo1 &&
637 cd repo1 &&
638 git init &&
639 test_commit 1 &&
640 test_commit 2 &&
641 test_commit 3 &&
642 mkdir repo2 &&
643 cd repo2 &&
644 git init &&
645 git fetch --depth=2 ../.git main:branch &&
646 git fsck
650 test_expect_success 'fetch-pack can fetch a raw sha1' '
651 git init hidden &&
653 cd hidden &&
654 test_commit 1 &&
655 test_commit 2 &&
656 git update-ref refs/hidden/one HEAD^ &&
657 git config transfer.hiderefs refs/hidden &&
658 git config uploadpack.allowtipsha1inwant true
659 ) &&
660 git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
663 test_expect_success 'fetch-pack can fetch a raw sha1 that is advertised as a ref' '
664 rm -rf server client &&
665 git init server &&
666 test_commit -C server 1 &&
668 git init client &&
669 git -C client fetch-pack ../server \
670 $(git -C server rev-parse refs/heads/main)
673 test_expect_success 'fetch-pack can fetch a raw sha1 overlapping a named ref' '
674 rm -rf server client &&
675 git init server &&
676 test_commit -C server 1 &&
677 test_commit -C server 2 &&
679 git init client &&
680 git -C client fetch-pack ../server \
681 $(git -C server rev-parse refs/tags/1) refs/tags/1
684 test_expect_success 'fetch-pack cannot fetch a raw sha1 that is not advertised as a ref' '
685 rm -rf server &&
687 git init server &&
688 test_commit -C server 5 &&
689 git -C server tag -d 5 &&
690 test_commit -C server 6 &&
692 git init client &&
693 # Some protocol versions (e.g. 2) support fetching
694 # unadvertised objects, so restrict this test to v0.
695 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 git -C client fetch-pack ../server \
696 $(git -C server rev-parse refs/heads/main^) 2>err &&
697 test_i18ngrep "Server does not allow request for unadvertised object" err
700 check_prot_path () {
701 cat >expected <<-EOF &&
702 Diag: url=$1
703 Diag: protocol=$2
704 Diag: path=$3
706 git fetch-pack --diag-url "$1" | grep -v hostandport= >actual &&
707 test_cmp expected actual
710 check_prot_host_port_path () {
711 case "$2" in
712 *ssh*)
713 pp=ssh
714 uah=userandhost
715 ehost=$(echo $3 | tr -d "[]")
716 diagport="Diag: port=$4"
719 pp=$p
720 uah=hostandport
721 ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
722 diagport=""
724 esac
725 cat >exp <<-EOF &&
726 Diag: url=$1
727 Diag: protocol=$pp
728 Diag: $uah=$ehost
729 $diagport
730 Diag: path=$5
732 grep -v "^$" exp >expected
733 git fetch-pack --diag-url "$1" >actual &&
734 test_cmp expected actual
737 for r in repo re:po re/po
739 # git or ssh with scheme
740 for p in "ssh+git" "git+ssh" git ssh
742 for h in host user@host user@[::1] user@::1
744 for c in "" :
746 test_expect_success "fetch-pack --diag-url $p://$h$c/$r" '
747 check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
749 # "/~" -> "~" conversion
750 test_expect_success "fetch-pack --diag-url $p://$h$c/~$r" '
751 check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
753 done
754 done
755 for h in host User@host User@[::1]
757 test_expect_success "fetch-pack --diag-url $p://$h:22/$r" '
758 check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
760 done
761 done
762 # file with scheme
763 for p in file
765 test_expect_success !MINGW "fetch-pack --diag-url $p://$h/$r" '
766 check_prot_path $p://$h/$r $p "/$r"
768 test_expect_success MINGW "fetch-pack --diag-url $p://$h/$r" '
769 check_prot_path $p://$h/$r $p "//$h/$r"
771 test_expect_success MINGW "fetch-pack --diag-url $p:///$r" '
772 check_prot_path $p:///$r $p "/$r"
774 # No "/~" -> "~" conversion for file
775 test_expect_success !MINGW "fetch-pack --diag-url $p://$h/~$r" '
776 check_prot_path $p://$h/~$r $p "/~$r"
778 test_expect_success MINGW "fetch-pack --diag-url $p://$h/~$r" '
779 check_prot_path $p://$h/~$r $p "//$h/~$r"
781 done
782 # file without scheme
783 for h in nohost nohost:12 [::1] [::1]:23 [ [:aa
785 test_expect_success "fetch-pack --diag-url ./$h:$r" '
786 check_prot_path ./$h:$r $p "./$h:$r"
788 # No "/~" -> "~" conversion for file
789 test_expect_success "fetch-pack --diag-url ./$p:$h/~$r" '
790 check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r"
792 done
793 #ssh without scheme
794 p=ssh
795 for h in host [::1]
797 test_expect_success "fetch-pack --diag-url $h:$r" '
798 check_prot_host_port_path $h:$r $p "$h" NONE "$r"
800 # Do "/~" -> "~" conversion
801 test_expect_success "fetch-pack --diag-url $h:/~$r" '
802 check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
804 done
805 done
807 test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' '
808 check_prot_path file://c:/repo file c:/repo
810 test_expect_success MINGW 'fetch-pack --diag-url c:repo' '
811 check_prot_path c:repo file c:repo
814 test_expect_success 'clone shallow since ...' '
815 test_create_repo shallow-since &&
817 cd shallow-since &&
818 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
819 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
820 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
821 git clone --shallow-since "300000000 +0700" "file://$(pwd)/." ../shallow11 &&
822 git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
823 echo three >expected &&
824 test_cmp expected actual
828 test_expect_success 'fetch shallow since ...' '
829 git -C shallow11 fetch --shallow-since "200000000 +0700" origin &&
830 git -C shallow11 log --pretty=tformat:%s origin/main >actual &&
831 cat >expected <<-\EOF &&
832 three
835 test_cmp expected actual
838 test_expect_success 'clone shallow since selects no commits' '
839 test_create_repo shallow-since-the-future &&
841 cd shallow-since-the-future &&
842 GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
843 GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
844 GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
845 test_must_fail git clone --shallow-since "900000000 +0700" "file://$(pwd)/." ../shallow111
849 # A few subtle things about the request in this test:
851 # - the server must have commit-graphs present and enabled
853 # - the history is such that our want/have share a common ancestor ("base"
854 # here)
856 # - we send only a single have, which is fewer than a normal client would
857 # send. This ensures that we don't parse "base" up front with
858 # parse_object(), but rather traverse to it as a parent while deciding if we
859 # can stop the "have" negotiation, and call parse_commit(). The former
860 # sees the actual object data and so always loads the three oid, whereas the
861 # latter will try to load it lazily.
863 # - we must use protocol v2, because it handles the "have" negotiation before
864 # processing the shallow directives
866 test_expect_success 'shallow since with commit graph and already-seen commit' '
867 test_create_repo shallow-since-graph &&
869 cd shallow-since-graph &&
870 test_commit base &&
871 test_commit main &&
872 git checkout -b other HEAD^ &&
873 test_commit other &&
874 git commit-graph write --reachable &&
875 git config core.commitGraph true &&
877 GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
878 0012command=fetch
879 $(echo "object-format=$(test_oid algo)" | packetize)
880 00010013deepen-since 1
881 $(echo "want $(git rev-parse other)" | packetize)
882 $(echo "have $(git rev-parse main)" | packetize)
883 0000
888 test_expect_success 'shallow clone exclude tag two' '
889 test_create_repo shallow-exclude &&
891 cd shallow-exclude &&
892 test_commit one &&
893 test_commit two &&
894 test_commit three &&
895 git clone --shallow-exclude two "file://$(pwd)/." ../shallow12 &&
896 git -C ../shallow12 log --pretty=tformat:%s HEAD >actual &&
897 echo three >expected &&
898 test_cmp expected actual
902 test_expect_success 'fetch exclude tag one' '
903 git -C shallow12 fetch --shallow-exclude one origin &&
904 git -C shallow12 log --pretty=tformat:%s origin/main >actual &&
905 test_write_lines three two >expected &&
906 test_cmp expected actual
909 test_expect_success 'fetching deepen' '
910 test_create_repo shallow-deepen &&
912 cd shallow-deepen &&
913 test_commit one &&
914 test_commit two &&
915 test_commit three &&
916 git clone --depth 1 "file://$(pwd)/." deepen &&
917 test_commit four &&
918 git -C deepen log --pretty=tformat:%s main >actual &&
919 echo three >expected &&
920 test_cmp expected actual &&
921 git -C deepen fetch --deepen=1 &&
922 git -C deepen log --pretty=tformat:%s origin/main >actual &&
923 cat >expected <<-\EOF &&
924 four
925 three
928 test_cmp expected actual
932 test_negotiation_algorithm_default () {
933 test_when_finished rm -rf clientv0 clientv2 &&
934 rm -rf server client &&
935 git init server &&
936 test_commit -C server both_have_1 &&
937 git -C server tag -d both_have_1 &&
938 test_commit -C server both_have_2 &&
940 git clone server client &&
941 test_commit -C server server_has &&
942 test_commit -C client client_has &&
944 # In both protocol v0 and v2, ensure that the parent of both_have_2 is
945 # not sent as a "have" line. The client should know that the server has
946 # both_have_2, so it only needs to inform the server that it has
947 # both_have_2, and the server can infer the rest.
949 rm -f trace &&
950 cp -r client clientv0 &&
951 GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv0 \
952 "$@" fetch origin server_has both_have_2 &&
953 grep "have $(git -C client rev-parse client_has)" trace &&
954 grep "have $(git -C client rev-parse both_have_2)" trace &&
955 ! grep "have $(git -C client rev-parse both_have_2^)" trace &&
957 rm -f trace &&
958 cp -r client clientv2 &&
959 GIT_TRACE_PACKET="$(pwd)/trace" git -C clientv2 -c protocol.version=2 \
960 "$@" fetch origin server_has both_have_2 &&
961 grep "have $(git -C client rev-parse client_has)" trace &&
962 grep "have $(git -C client rev-parse both_have_2)" trace &&
963 ! grep "have $(git -C client rev-parse both_have_2^)" trace
966 test_expect_success 'use ref advertisement to prune "have" lines sent' '
967 test_negotiation_algorithm_default
970 test_expect_success 'same as last but with config overrides' '
971 test_negotiation_algorithm_default \
972 -c feature.experimental=true \
973 -c fetch.negotiationAlgorithm=consecutive
976 test_expect_success 'ensure bogus fetch.negotiationAlgorithm yields error' '
977 test_when_finished rm -rf clientv0 &&
978 cp -r client clientv0 &&
979 test_must_fail git -C clientv0 --fetch.negotiationAlgorithm=bogus \
980 fetch origin server_has both_have_2
983 test_expect_success 'filtering by size' '
984 rm -rf server client &&
985 test_create_repo server &&
986 test_commit -C server one &&
987 test_config -C server uploadpack.allowfilter 1 &&
989 test_create_repo client &&
990 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
992 # Ensure that object is not inadvertently fetched
993 commit=$(git -C server rev-parse HEAD) &&
994 blob=$(git hash-object server/one.t) &&
995 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
996 ! grep "$blob" oids
999 test_expect_success 'filtering by size has no effect if support for it is not advertised' '
1000 rm -rf server client &&
1001 test_create_repo server &&
1002 test_commit -C server one &&
1004 test_create_repo client &&
1005 git -C client fetch-pack --filter=blob:limit=0 ../server HEAD 2> err &&
1007 # Ensure that object is fetched
1008 commit=$(git -C server rev-parse HEAD) &&
1009 blob=$(git hash-object server/one.t) &&
1010 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1011 grep "$blob" oids &&
1013 test_i18ngrep "filtering not recognized by server" err
1016 fetch_filter_blob_limit_zero () {
1017 SERVER="$1"
1018 URL="$2"
1020 rm -rf "$SERVER" client &&
1021 test_create_repo "$SERVER" &&
1022 test_commit -C "$SERVER" one &&
1023 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
1025 git clone "$URL" client &&
1027 test_commit -C "$SERVER" two &&
1029 git -C client fetch --filter=blob:limit=0 origin HEAD:somewhere &&
1031 # Ensure that commit is fetched, but blob is not
1032 commit=$(git -C "$SERVER" rev-parse two) &&
1033 blob=$(git hash-object server/two.t) &&
1034 git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
1035 grep "$commit" oids &&
1036 ! grep "$blob" oids
1039 test_expect_success 'fetch with --filter=blob:limit=0' '
1040 fetch_filter_blob_limit_zero server server
1043 . "$TEST_DIRECTORY"/lib-httpd.sh
1044 start_httpd
1046 test_expect_success 'fetch with --filter=blob:limit=0 and HTTP' '
1047 fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
1050 # DO NOT add non-httpd-specific tests here, because the last part of this
1051 # test script is only executed when httpd is available and enabled.
1053 test_done