Merge branch 'fixes/2.45.1/2.41' into fixes/2.45.1/2.42
[alt-git.git] / t / t5601-clone.sh
blob17c287d7b8da5aa2a9f271a3e388fc1db2d14108
1 #!/bin/sh
3 test_description=clone
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
11 test_have_prereq !MINGW || X=.exe
13 test_expect_success setup '
15 rm -fr .git &&
16 test_create_repo src &&
18 cd src &&
19 >file &&
20 git add file &&
21 git commit -m initial &&
22 echo 1 >file &&
23 git add file &&
24 git commit -m updated
29 test_expect_success 'clone with excess parameters (1)' '
31 rm -fr dst &&
32 test_must_fail git clone -n src dst junk
36 test_expect_success 'clone with excess parameters (2)' '
38 rm -fr dst &&
39 test_must_fail git clone -n "file://$(pwd)/src" dst junk
43 test_expect_success 'output from clone' '
44 rm -fr dst &&
45 git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
46 test $(grep Clon output | wc -l) = 1
49 test_expect_success 'clone does not keep pack' '
51 rm -fr dst &&
52 git clone -n "file://$(pwd)/src" dst &&
53 ! test -f dst/file &&
54 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
58 test_expect_success 'clone checks out files' '
60 rm -fr dst &&
61 git clone src dst &&
62 test -f dst/file
66 test_expect_success 'clone respects GIT_WORK_TREE' '
68 GIT_WORK_TREE=worktree git clone src bare &&
69 test -f bare/config &&
70 test -f worktree/file
74 test_expect_success 'clone from hooks' '
76 test_create_repo r0 &&
77 cd r0 &&
78 test_commit initial &&
79 cd .. &&
80 git init r1 &&
81 cd r1 &&
82 test_hook pre-commit <<-\EOF &&
83 git clone ../r0 ../r2
84 exit 1
85 EOF
86 : >file &&
87 git add file &&
88 test_must_fail git commit -m invoke-hook &&
89 cd .. &&
90 test_cmp r0/.git/HEAD r2/.git/HEAD &&
91 test_cmp r0/initial.t r2/initial.t
95 test_expect_success 'clone creates intermediate directories' '
97 git clone src long/path/to/dst &&
98 test -f long/path/to/dst/file
102 test_expect_success 'clone creates intermediate directories for bare repo' '
104 git clone --bare src long/path/to/bare/dst &&
105 test -f long/path/to/bare/dst/config
109 test_expect_success 'clone --mirror' '
111 git clone --mirror src mirror &&
112 test -f mirror/HEAD &&
113 test ! -f mirror/file &&
114 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
115 test "+refs/*:refs/*" = "$FETCH" &&
116 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
117 test "$MIRROR" = true
121 test_expect_success 'clone --mirror with detached HEAD' '
123 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
124 git clone --mirror src mirror.detached &&
125 ( cd src && git checkout - ) &&
126 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
127 test_cmp expected actual
131 test_expect_success 'clone --bare with detached HEAD' '
133 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
134 git clone --bare src bare.detached &&
135 ( cd src && git checkout - ) &&
136 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
137 test_cmp expected actual
141 test_expect_success 'clone --bare names the local repository <name>.git' '
143 git clone --bare src &&
144 test -d src.git
148 test_expect_success 'clone --mirror does not repeat tags' '
150 (cd src &&
151 git tag some-tag HEAD) &&
152 git clone --mirror src mirror2 &&
153 (cd mirror2 &&
154 git show-ref 2> clone.err > clone.out) &&
155 ! grep Duplicate mirror2/clone.err &&
156 grep some-tag mirror2/clone.out
160 test_expect_success 'clone to destination with trailing /' '
162 git clone src target-1/ &&
163 T=$( cd target-1 && git rev-parse HEAD ) &&
164 S=$( cd src && git rev-parse HEAD ) &&
165 test "$T" = "$S"
169 test_expect_success 'clone to destination with extra trailing /' '
171 git clone src target-2/// &&
172 T=$( cd target-2 && git rev-parse HEAD ) &&
173 S=$( cd src && git rev-parse HEAD ) &&
174 test "$T" = "$S"
178 test_expect_success 'clone to an existing empty directory' '
179 mkdir target-3 &&
180 git clone src target-3 &&
181 T=$( cd target-3 && git rev-parse HEAD ) &&
182 S=$( cd src && git rev-parse HEAD ) &&
183 test "$T" = "$S"
186 test_expect_success 'clone to an existing non-empty directory' '
187 mkdir target-4 &&
188 >target-4/Fakefile &&
189 test_must_fail git clone src target-4
192 test_expect_success 'clone to an existing path' '
193 >target-5 &&
194 test_must_fail git clone src target-5
197 test_expect_success 'clone a void' '
198 mkdir src-0 &&
200 cd src-0 && git init
201 ) &&
202 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
203 ! grep "fatal:" err-6 &&
205 cd src-0 && test_commit A
206 ) &&
207 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
208 ! grep "fatal:" err-7 &&
209 # There is no reason to insist they are bit-for-bit
210 # identical, but this test should suffice for now.
211 test_cmp target-6/.git/config target-7/.git/config
214 test_expect_success 'clone respects global branch.autosetuprebase' '
216 test_config="$HOME/.gitconfig" &&
217 git config -f "$test_config" branch.autosetuprebase remote &&
218 rm -fr dst &&
219 git clone src dst &&
220 cd dst &&
221 actual="z$(git config branch.main.rebase)" &&
222 test ztrue = $actual
226 test_expect_success 'respect url-encoding of file://' '
227 git init x+y &&
228 git clone "file://$PWD/x+y" xy-url-1 &&
229 git clone "file://$PWD/x%2By" xy-url-2
232 test_expect_success 'do not query-string-decode + in URLs' '
233 rm -rf x+y &&
234 git init "x y" &&
235 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
238 test_expect_success 'do not respect url-encoding of non-url path' '
239 git init x+y &&
240 test_must_fail git clone x%2By xy-regular &&
241 git clone x+y xy-regular
244 test_expect_success 'clone separate gitdir' '
245 rm -rf dst &&
246 git clone --separate-git-dir realgitdir src dst &&
247 test -d realgitdir/refs
250 test_expect_success 'clone separate gitdir: output' '
251 echo "gitdir: $(pwd)/realgitdir" >expected &&
252 test_cmp expected dst/.git
255 test_expect_success 'clone from .git file' '
256 git clone dst/.git dst2
259 test_expect_success 'fetch from .git gitfile' '
261 cd dst2 &&
262 git fetch ../dst/.git
266 test_expect_success 'fetch from gitfile parent' '
268 cd dst2 &&
269 git fetch ../dst
273 test_expect_success 'clone separate gitdir where target already exists' '
274 rm -rf dst &&
275 echo foo=bar >>realgitdir/config &&
276 test_must_fail git clone --separate-git-dir realgitdir src dst &&
277 grep foo=bar realgitdir/config
280 test_expect_success 'clone --reference from original' '
281 git clone --shared --bare src src-1 &&
282 git clone --bare src src-2 &&
283 git clone --reference=src-2 --bare src-1 target-8 &&
284 grep /src-2/ target-8/objects/info/alternates
287 test_expect_success 'clone with more than one --reference' '
288 git clone --bare src src-3 &&
289 git clone --bare src src-4 &&
290 git clone --reference=src-3 --reference=src-4 src target-9 &&
291 grep /src-3/ target-9/.git/objects/info/alternates &&
292 grep /src-4/ target-9/.git/objects/info/alternates
295 test_expect_success 'clone from original with relative alternate' '
296 mkdir nest &&
297 git clone --bare src nest/src-5 &&
298 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
299 git clone --bare nest/src-5 target-10 &&
300 grep /src/\\.git/objects target-10/objects/info/alternates
303 test_expect_success 'clone checking out a tag' '
304 git clone --branch=some-tag src dst.tag &&
305 GIT_DIR=src/.git git rev-parse some-tag >expected &&
306 GIT_DIR=dst.tag/.git git rev-parse HEAD >actual &&
307 test_cmp expected actual &&
308 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
309 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
310 test_cmp fetch.expected fetch.actual
313 test_expect_success 'set up ssh wrapper' '
314 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \
315 "$TRASH_DIRECTORY/ssh$X" &&
316 GIT_SSH="$TRASH_DIRECTORY/ssh$X" &&
317 export GIT_SSH &&
318 export TRASH_DIRECTORY &&
319 >"$TRASH_DIRECTORY"/ssh-output
322 copy_ssh_wrapper_as () {
323 rm -f "${1%$X}$X" &&
324 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" &&
325 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" &&
326 GIT_SSH="${1%$X}$X" &&
327 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\""
330 expect_ssh () {
331 test_when_finished '
332 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
333 ' &&
335 case "$#" in
339 echo "ssh: $1 git-upload-pack '$2'"
342 echo "ssh: $1 $2 git-upload-pack '$3'"
345 echo "ssh: $1 $2 git-upload-pack '$3' $4"
346 esac
347 } >"$TRASH_DIRECTORY/ssh-expect" &&
348 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
351 test_expect_success 'clone myhost:src uses ssh' '
352 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone &&
353 expect_ssh myhost src
356 test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
357 cp -R src "foo:bar" &&
358 git clone "foo:bar" foobar &&
359 expect_ssh none
362 test_expect_success 'bracketed hostnames are still ssh' '
363 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone &&
364 expect_ssh "-p 123" myhost src
367 test_expect_success 'OpenSSH variant passes -4' '
368 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone &&
369 expect_ssh "-4 -p 123" myhost src
372 test_expect_success 'variant can be overridden' '
373 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
374 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
375 expect_ssh "-4 -P 123" myhost src
378 test_expect_success 'variant=auto picks based on basename' '
379 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
380 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
381 expect_ssh "-4 -P 123" myhost src
384 test_expect_success 'simple does not support -4/-6' '
385 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
386 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
389 test_expect_success 'simple does not support port' '
390 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
391 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
394 test_expect_success 'uplink is treated as simple' '
395 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
396 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
397 git clone "myhost:src" ssh-clone-uplink &&
398 expect_ssh myhost src
401 test_expect_success 'OpenSSH-like uplink is treated as ssh' '
402 write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
403 if test "\$1" = "-G"
404 then
405 exit 0
406 fi &&
407 exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
409 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" &&
410 GIT_SSH="$TRASH_DIRECTORY/uplink" &&
411 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" &&
412 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
413 expect_ssh "-p 123" myhost src
416 test_expect_success 'plink is treated specially (as putty)' '
417 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
418 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
419 expect_ssh "-P 123" myhost src
422 test_expect_success 'plink.exe is treated specially (as putty)' '
423 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
424 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
425 expect_ssh "-P 123" myhost src
428 test_expect_success 'tortoiseplink is like putty, with extra arguments' '
429 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
430 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
431 expect_ssh "-batch -P 123" myhost src
434 test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' '
435 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
436 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \
437 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 &&
438 expect_ssh "-v -P 123" myhost src
441 test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
442 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
443 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \
444 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 &&
445 expect_ssh "-v -P 123" myhost src
448 test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
449 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
450 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \
451 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
452 expect_ssh "-p 123" myhost src
455 test_expect_success 'ssh.variant overrides plink detection' '
456 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
457 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \
458 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
459 expect_ssh "-p 123" myhost src
462 test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
463 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
464 GIT_SSH_VARIANT=plink \
465 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
466 expect_ssh "-P 123" myhost src
469 test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
470 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
471 GIT_SSH_VARIANT=tortoiseplink \
472 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
473 expect_ssh "-batch -P 123" myhost src
476 test_expect_success 'clean failure on broken quoting' '
477 test_must_fail \
478 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
479 git clone "[myhost:123]:src" sq-failure
482 counter=0
483 # $1 url
484 # $2 none|host
485 # $3 path
486 test_clone_url () {
487 counter=$(($counter + 1))
488 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter &&
489 shift &&
490 expect_ssh "$@"
493 test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
494 test_clone_url c:temp c temp
497 test_expect_success MINGW 'clone c:temp is dos drive' '
498 test_clone_url c:temp none
501 #ip v4
502 for repo in rep rep/home/project 123
504 test_expect_success "clone host:$repo" '
505 test_clone_url host:$repo host $repo
507 done
509 #ipv6
510 for repo in rep rep/home/project 123
512 test_expect_success "clone [::1]:$repo" '
513 test_clone_url [::1]:$repo ::1 "$repo"
515 done
516 #home directory
517 test_expect_success "clone host:/~repo" '
518 test_clone_url host:/~repo host "~repo"
521 test_expect_success "clone [::1]:/~repo" '
522 test_clone_url [::1]:/~repo ::1 "~repo"
525 # Corner cases
526 for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
528 test_expect_success "clone $url is not ssh" '
529 test_clone_url $url none
531 done
533 #with ssh:// scheme
534 #ignore trailing colon
535 for tcol in "" :
537 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
538 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
540 # from home directory
541 test_expect_success "clone ssh://host.xz$tcol/~repo" '
542 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
544 done
546 # with port number
547 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
548 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
551 # from home directory with port number
552 test_expect_success 'clone ssh://host.xz:22/~repo' '
553 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
556 #IPv6
557 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
559 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]")
560 test_expect_success "clone ssh://$tuah/home/user/repo" "
561 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
563 done
565 #IPv6 from home directory
566 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
568 euah=$(echo $tuah | tr -d "[]")
569 test_expect_success "clone ssh://$tuah/~repo" "
570 test_clone_url ssh://$tuah/~repo $euah '~repo'
572 done
574 #IPv6 with port number
575 for tuah in [::1] user@[::1] [user@::1]
577 euah=$(echo $tuah | tr -d "[]")
578 test_expect_success "clone ssh://$tuah:22/home/user/repo" "
579 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
581 done
583 #IPv6 from home directory with port number
584 for tuah in [::1] user@[::1] [user@::1]
586 euah=$(echo $tuah | tr -d "[]")
587 test_expect_success "clone ssh://$tuah:22/~repo" "
588 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
590 done
592 test_expect_success 'clone from a repository with two identical branches' '
595 cd src &&
596 git checkout -b another main
597 ) &&
598 git clone src target-11 &&
599 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
603 test_expect_success 'shallow clone locally' '
604 git clone --depth=1 --no-local src ssrrcc &&
605 git clone ssrrcc ddsstt &&
606 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
607 ( cd ddsstt && git fsck )
610 test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
611 rm -rf dst.git &&
612 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
613 git init --bare replay.git &&
614 git -C replay.git index-pack -v --stdin <tmp.pack
617 test_expect_success 'clone on case-insensitive fs' '
618 git init icasefs &&
620 cd icasefs &&
621 o=$(git hash-object -w --stdin </dev/null | hex2oct) &&
622 t=$(printf "100644 X\0${o}100644 x\0${o}" |
623 git hash-object -w -t tree --stdin) &&
624 c=$(git commit-tree -m bogus $t) &&
625 git update-ref refs/heads/bogus $c &&
626 git clone -b bogus . bogus 2>warning
630 test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
631 grep X icasefs/warning &&
632 grep x icasefs/warning &&
633 test_i18ngrep "the following paths have collided" icasefs/warning
636 test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \
637 'colliding symlink/directory keeps directory' '
638 git init icasefs-colliding-symlink &&
640 cd icasefs-colliding-symlink &&
641 a=$(printf a | git hash-object -w --stdin) &&
642 printf "100644 %s 0\tA/dir/b\n120000 %s 0\ta\n" $a $a >idx &&
643 git update-index --index-info <idx &&
644 test_tick &&
645 git commit -m initial
646 ) &&
647 git clone icasefs-colliding-symlink icasefs-colliding-symlink-clone &&
648 test_file_not_empty icasefs-colliding-symlink-clone/A/dir/b
651 test_expect_success 'clone with GIT_DEFAULT_HASH' '
653 sane_unset GIT_DEFAULT_HASH &&
654 git init --object-format=sha1 test-sha1 &&
655 git init --object-format=sha256 test-sha256
656 ) &&
657 test_commit -C test-sha1 foo &&
658 test_commit -C test-sha256 foo &&
659 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
660 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
661 git -C test-clone-sha1 status &&
662 git -C test-clone-sha256 status
665 partial_clone_server () {
666 SERVER="$1" &&
668 rm -rf "$SERVER" client &&
669 test_create_repo "$SERVER" &&
670 test_commit -C "$SERVER" one &&
671 HASH1=$(git -C "$SERVER" hash-object one.t) &&
672 git -C "$SERVER" revert HEAD &&
673 test_commit -C "$SERVER" two &&
674 HASH2=$(git -C "$SERVER" hash-object two.t) &&
675 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
676 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1
679 partial_clone () {
680 SERVER="$1" &&
681 URL="$2" &&
683 partial_clone_server "${SERVER}" &&
684 git clone --filter=blob:limit=0 "$URL" client &&
686 git -C client fsck &&
688 # Ensure that unneeded blobs are not inadvertently fetched.
689 test_config -C client remote.origin.promisor "false" &&
690 git -C client config --unset remote.origin.partialclonefilter &&
691 test_must_fail git -C client cat-file -e "$HASH1" &&
693 # But this blob was fetched, because clone performs an initial checkout
694 git -C client cat-file -e "$HASH2"
697 test_expect_success 'partial clone' '
698 partial_clone server "file://$(pwd)/server"
701 test_expect_success 'partial clone with -o' '
702 partial_clone_server server &&
703 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
704 test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
707 test_expect_success 'partial clone: warn if server does not support object filtering' '
708 rm -rf server client &&
709 test_create_repo server &&
710 test_commit -C server one &&
712 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
714 test_i18ngrep "filtering not recognized by server" err
717 test_expect_success 'batch missing blob request during checkout' '
718 rm -rf server client &&
720 test_create_repo server &&
721 echo a >server/a &&
722 echo b >server/b &&
723 git -C server add a b &&
725 git -C server commit -m x &&
726 echo aa >server/a &&
727 echo bb >server/b &&
728 git -C server add a b &&
729 git -C server commit -m x &&
731 test_config -C server uploadpack.allowfilter 1 &&
732 test_config -C server uploadpack.allowanysha1inwant 1 &&
734 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
736 # Ensure that there is only one negotiation by checking that there is
737 # only "done" line sent. ("done" marks the end of negotiation.)
738 GIT_TRACE_PACKET="$(pwd)/trace" \
739 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
740 git -C client -c trace2.eventNesting=5 checkout HEAD^ &&
741 grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines &&
742 test_line_count = 1 trace_lines &&
743 grep "fetch> done" trace >done_lines &&
744 test_line_count = 1 done_lines
747 test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' '
748 rm -rf server client &&
750 test_create_repo repo_for_submodule &&
751 test_commit -C repo_for_submodule x &&
753 test_create_repo server &&
754 echo a >server/a &&
755 echo b >server/b &&
756 git -C server add a b &&
757 git -C server commit -m x &&
759 echo aa >server/a &&
760 echo bb >server/b &&
761 # Also add a gitlink pointing to an arbitrary repository
762 test_config_global protocol.file.allow always &&
763 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
764 git -C server add a b c &&
765 git -C server commit -m x &&
767 test_config -C server uploadpack.allowfilter 1 &&
768 test_config -C server uploadpack.allowanysha1inwant 1 &&
770 # Make sure that it succeeds
771 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
774 . "$TEST_DIRECTORY"/lib-httpd.sh
775 start_httpd
777 test_expect_success 'partial clone using HTTP' '
778 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
781 test_expect_success 'reject cloning shallow repository using HTTP' '
782 test_when_finished "rm -rf repo" &&
783 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
784 test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err &&
785 test_i18ngrep -e "source repository is shallow, reject to clone." err &&
787 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
790 test_expect_success 'auto-discover bundle URI from HTTP clone' '
791 test_when_finished rm -rf trace.txt repo2 "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
792 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/everything.bundle" --all &&
793 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
795 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
796 uploadpack.advertiseBundleURIs true &&
797 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
798 bundle.version 1 &&
799 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
800 bundle.mode all &&
801 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
802 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
804 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
805 git -c protocol.version=2 \
806 -c transfer.bundleURI=true clone \
807 $HTTPD_URL/smart/repo2.git repo2 &&
808 cat >pattern <<-EOF &&
809 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
811 grep -f pattern trace.txt
814 test_expect_success 'auto-discover multiple bundles from HTTP clone' '
815 test_when_finished rm -rf trace.txt repo3 "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
817 test_commit -C src new &&
818 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/new.bundle" HEAD~1..HEAD &&
819 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
821 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
822 uploadpack.advertiseBundleURIs true &&
823 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
824 bundle.version 1 &&
825 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
826 bundle.mode all &&
828 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
829 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
830 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
831 bundle.new.uri "$HTTPD_URL/new.bundle" &&
833 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
834 git -c protocol.version=2 \
835 -c transfer.bundleURI=true clone \
836 $HTTPD_URL/smart/repo3.git repo3 &&
838 # We should fetch _both_ bundles
839 cat >pattern <<-EOF &&
840 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
842 grep -f pattern trace.txt &&
843 cat >pattern <<-EOF &&
844 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/new.bundle"\]
846 grep -f pattern trace.txt
849 test_expect_success 'auto-discover multiple bundles from HTTP clone: creationToken heuristic' '
850 test_when_finished rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
851 test_when_finished rm -rf clone-heuristic trace*.txt &&
853 test_commit -C src newest &&
854 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/newest.bundle" HEAD~1..HEAD &&
855 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
857 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/repo4.git/config" <<-EOF &&
858 [uploadPack]
859 advertiseBundleURIs = true
861 [bundle]
862 version = 1
863 mode = all
864 heuristic = creationToken
866 [bundle "everything"]
867 uri = $HTTPD_URL/everything.bundle
868 creationtoken = 1
870 [bundle "new"]
871 uri = $HTTPD_URL/new.bundle
872 creationtoken = 2
874 [bundle "newest"]
875 uri = $HTTPD_URL/newest.bundle
876 creationtoken = 3
879 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
880 git -c protocol.version=2 \
881 -c transfer.bundleURI=true clone \
882 "$HTTPD_URL/smart/repo4.git" clone-heuristic &&
884 cat >expect <<-EOF &&
885 $HTTPD_URL/newest.bundle
886 $HTTPD_URL/new.bundle
887 $HTTPD_URL/everything.bundle
890 # We should fetch all bundles in the expected order.
891 test_remote_https_urls <trace-clone.txt >actual &&
892 test_cmp expect actual
895 # DO NOT add non-httpd-specific tests here, because the last part of this
896 # test script is only executed when httpd is available and enabled.
898 test_done