The 19th batch
[alt-git.git] / t / t5601-clone.sh
blob5d7ea147f1abc5ffae19ad093f8e12c3427a970a
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 'output from clone with core.abbrev does not crash' '
50 rm -fr dst &&
51 echo "Cloning into ${SQ}dst${SQ}..." >expect &&
52 git -c core.abbrev=12 clone -n "file://$(pwd)/src" dst >actual 2>&1 &&
53 test_cmp expect actual
56 test_expect_success 'clone does not keep pack' '
58 rm -fr dst &&
59 git clone -n "file://$(pwd)/src" dst &&
60 ! test -f dst/file &&
61 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
65 test_expect_success 'clone checks out files' '
67 rm -fr dst &&
68 git clone src dst &&
69 test -f dst/file
73 test_expect_success 'clone respects GIT_WORK_TREE' '
75 GIT_WORK_TREE=worktree git clone src bare &&
76 test -f bare/config &&
77 test -f worktree/file
81 test_expect_success 'clone from hooks' '
83 test_create_repo r0 &&
84 cd r0 &&
85 test_commit initial &&
86 cd .. &&
87 git init r1 &&
88 cd r1 &&
89 test_hook pre-commit <<-\EOF &&
90 git clone ../r0 ../r2
91 exit 1
92 EOF
93 : >file &&
94 git add file &&
95 test_must_fail git commit -m invoke-hook &&
96 cd .. &&
97 test_cmp r0/.git/HEAD r2/.git/HEAD &&
98 test_cmp r0/initial.t r2/initial.t
102 test_expect_success 'clone creates intermediate directories' '
104 git clone src long/path/to/dst &&
105 test -f long/path/to/dst/file
109 test_expect_success 'clone creates intermediate directories for bare repo' '
111 git clone --bare src long/path/to/bare/dst &&
112 test -f long/path/to/bare/dst/config
116 test_expect_success 'clone --mirror' '
118 git clone --mirror src mirror &&
119 test -f mirror/HEAD &&
120 test ! -f mirror/file &&
121 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
122 test "+refs/*:refs/*" = "$FETCH" &&
123 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
124 test "$MIRROR" = true
128 test_expect_success 'clone --mirror with detached HEAD' '
130 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
131 git clone --mirror src mirror.detached &&
132 ( cd src && git checkout - ) &&
133 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
134 test_cmp expected actual
138 test_expect_success 'clone --bare with detached HEAD' '
140 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
141 git clone --bare src bare.detached &&
142 ( cd src && git checkout - ) &&
143 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
144 test_cmp expected actual
148 test_expect_success 'clone --bare names the local repository <name>.git' '
150 git clone --bare src &&
151 test -d src.git
155 test_expect_success 'clone --mirror does not repeat tags' '
157 (cd src &&
158 git tag some-tag HEAD) &&
159 git clone --mirror src mirror2 &&
160 (cd mirror2 &&
161 git show-ref 2> clone.err > clone.out) &&
162 ! grep Duplicate mirror2/clone.err &&
163 grep some-tag mirror2/clone.out
167 test_expect_success 'clone with files ref format' '
168 test_when_finished "rm -rf ref-storage" &&
169 git clone --ref-format=files --mirror src ref-storage &&
170 echo files >expect &&
171 git -C ref-storage rev-parse --show-ref-format >actual &&
172 test_cmp expect actual
175 test_expect_success 'clone with garbage ref format' '
176 cat >expect <<-EOF &&
177 fatal: unknown ref storage format ${SQ}garbage${SQ}
179 test_must_fail git clone --ref-format=garbage --mirror src ref-storage 2>err &&
180 test_cmp expect err &&
181 test_path_is_missing ref-storage
184 test_expect_success 'clone to destination with trailing /' '
186 git clone src target-1/ &&
187 T=$( cd target-1 && git rev-parse HEAD ) &&
188 S=$( cd src && git rev-parse HEAD ) &&
189 test "$T" = "$S"
193 test_expect_success 'clone to destination with extra trailing /' '
195 git clone src target-2/// &&
196 T=$( cd target-2 && git rev-parse HEAD ) &&
197 S=$( cd src && git rev-parse HEAD ) &&
198 test "$T" = "$S"
202 test_expect_success 'clone to an existing empty directory' '
203 mkdir target-3 &&
204 git clone src target-3 &&
205 T=$( cd target-3 && git rev-parse HEAD ) &&
206 S=$( cd src && git rev-parse HEAD ) &&
207 test "$T" = "$S"
210 test_expect_success 'clone to an existing non-empty directory' '
211 mkdir target-4 &&
212 >target-4/Fakefile &&
213 test_must_fail git clone src target-4
216 test_expect_success 'clone to an existing path' '
217 >target-5 &&
218 test_must_fail git clone src target-5
221 test_expect_success 'clone a void' '
222 mkdir src-0 &&
224 cd src-0 && git init
225 ) &&
226 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
227 ! grep "fatal:" err-6 &&
229 cd src-0 && test_commit A
230 ) &&
231 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
232 ! grep "fatal:" err-7 &&
233 # There is no reason to insist they are bit-for-bit
234 # identical, but this test should suffice for now.
235 test_cmp target-6/.git/config target-7/.git/config
238 test_expect_success 'clone respects global branch.autosetuprebase' '
240 test_config="$HOME/.gitconfig" &&
241 git config -f "$test_config" branch.autosetuprebase remote &&
242 rm -fr dst &&
243 git clone src dst &&
244 cd dst &&
245 actual="z$(git config branch.main.rebase)" &&
246 test ztrue = $actual
250 test_expect_success 'respect url-encoding of file://' '
251 git init x+y &&
252 git clone "file://$PWD/x+y" xy-url-1 &&
253 git clone "file://$PWD/x%2By" xy-url-2
256 test_expect_success 'do not query-string-decode + in URLs' '
257 rm -rf x+y &&
258 git init "x y" &&
259 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
262 test_expect_success 'do not respect url-encoding of non-url path' '
263 git init x+y &&
264 test_must_fail git clone x%2By xy-regular &&
265 git clone x+y xy-regular
268 test_expect_success 'clone separate gitdir' '
269 rm -rf dst &&
270 git clone --separate-git-dir realgitdir src dst &&
271 test -d realgitdir/refs
274 test_expect_success 'clone separate gitdir: output' '
275 echo "gitdir: $(pwd)/realgitdir" >expected &&
276 test_cmp expected dst/.git
279 test_expect_success 'clone from .git file' '
280 git clone dst/.git dst2
283 test_expect_success 'fetch from .git gitfile' '
285 cd dst2 &&
286 git fetch ../dst/.git
290 test_expect_success 'fetch from gitfile parent' '
292 cd dst2 &&
293 git fetch ../dst
297 test_expect_success 'clone separate gitdir where target already exists' '
298 rm -rf dst &&
299 echo foo=bar >>realgitdir/config &&
300 test_must_fail git clone --separate-git-dir realgitdir src dst &&
301 grep foo=bar realgitdir/config
304 test_expect_success 'clone --reference from original' '
305 git clone --shared --bare src src-1 &&
306 git clone --bare src src-2 &&
307 git clone --reference=src-2 --bare src-1 target-8 &&
308 grep /src-2/ target-8/objects/info/alternates
311 test_expect_success 'clone with more than one --reference' '
312 git clone --bare src src-3 &&
313 git clone --bare src src-4 &&
314 git clone --reference=src-3 --reference=src-4 src target-9 &&
315 grep /src-3/ target-9/.git/objects/info/alternates &&
316 grep /src-4/ target-9/.git/objects/info/alternates
319 test_expect_success 'clone from original with relative alternate' '
320 mkdir nest &&
321 git clone --bare src nest/src-5 &&
322 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
323 git clone --bare nest/src-5 target-10 &&
324 grep /src/\\.git/objects target-10/objects/info/alternates
327 test_expect_success 'clone checking out a tag' '
328 git clone --branch=some-tag src dst.tag &&
329 GIT_DIR=src/.git git rev-parse some-tag >expected &&
330 GIT_DIR=dst.tag/.git git rev-parse HEAD >actual &&
331 test_cmp expected actual &&
332 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
333 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
334 test_cmp fetch.expected fetch.actual
337 test_expect_success 'set up ssh wrapper' '
338 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \
339 "$TRASH_DIRECTORY/ssh$X" &&
340 GIT_SSH="$TRASH_DIRECTORY/ssh$X" &&
341 export GIT_SSH &&
342 export TRASH_DIRECTORY &&
343 >"$TRASH_DIRECTORY"/ssh-output
346 copy_ssh_wrapper_as () {
347 rm -f "${1%$X}$X" &&
348 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" &&
349 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" &&
350 GIT_SSH="${1%$X}$X" &&
351 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\""
354 expect_ssh () {
355 test_when_finished '
356 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
357 ' &&
359 case "$#" in
363 echo "ssh: $1 git-upload-pack '$2'"
366 echo "ssh: $1 $2 git-upload-pack '$3'"
369 echo "ssh: $1 $2 git-upload-pack '$3' $4"
370 esac
371 } >"$TRASH_DIRECTORY/ssh-expect" &&
372 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
375 test_expect_success 'clone myhost:src uses ssh' '
376 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone &&
377 expect_ssh myhost src
380 test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
381 cp -R src "foo:bar" &&
382 git clone "foo:bar" foobar &&
383 expect_ssh none
386 test_expect_success 'bracketed hostnames are still ssh' '
387 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone &&
388 expect_ssh "-p 123" myhost src
391 test_expect_success 'OpenSSH variant passes -4' '
392 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone &&
393 expect_ssh "-4 -p 123" myhost src
396 test_expect_success 'variant can be overridden' '
397 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
398 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
399 expect_ssh "-4 -P 123" myhost src
402 test_expect_success 'variant=auto picks based on basename' '
403 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
404 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
405 expect_ssh "-4 -P 123" myhost src
408 test_expect_success 'simple does not support -4/-6' '
409 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
410 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
413 test_expect_success 'simple does not support port' '
414 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
415 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
418 test_expect_success 'uplink is treated as simple' '
419 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
420 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
421 git clone "myhost:src" ssh-clone-uplink &&
422 expect_ssh myhost src
425 test_expect_success 'OpenSSH-like uplink is treated as ssh' '
426 write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
427 if test "\$1" = "-G"
428 then
429 exit 0
430 fi &&
431 exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
433 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" &&
434 GIT_SSH="$TRASH_DIRECTORY/uplink" &&
435 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" &&
436 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
437 expect_ssh "-p 123" myhost src
440 test_expect_success 'plink is treated specially (as putty)' '
441 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
442 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
443 expect_ssh "-P 123" myhost src
446 test_expect_success 'plink.exe is treated specially (as putty)' '
447 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
448 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
449 expect_ssh "-P 123" myhost src
452 test_expect_success 'tortoiseplink is like putty, with extra arguments' '
453 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
454 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
455 expect_ssh "-batch -P 123" myhost src
458 test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' '
459 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
460 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \
461 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 &&
462 expect_ssh "-v -P 123" myhost src
465 test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
466 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
467 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \
468 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 &&
469 expect_ssh "-v -P 123" myhost src
472 test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
473 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
474 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \
475 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
476 expect_ssh "-p 123" myhost src
479 test_expect_success 'ssh.variant overrides plink detection' '
480 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
481 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \
482 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
483 expect_ssh "-p 123" myhost src
486 test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
487 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
488 GIT_SSH_VARIANT=plink \
489 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
490 expect_ssh "-P 123" myhost src
493 test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
494 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
495 GIT_SSH_VARIANT=tortoiseplink \
496 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
497 expect_ssh "-batch -P 123" myhost src
500 test_expect_success 'clean failure on broken quoting' '
501 test_must_fail \
502 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
503 git clone "[myhost:123]:src" sq-failure
506 counter=0
507 # $1 url
508 # $2 none|host
509 # $3 path
510 test_clone_url () {
511 counter=$(($counter + 1))
512 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter &&
513 shift &&
514 expect_ssh "$@"
517 test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
518 test_clone_url c:temp c temp
521 test_expect_success MINGW 'clone c:temp is dos drive' '
522 test_clone_url c:temp none
525 #ip v4
526 for repo in rep rep/home/project 123
528 test_expect_success "clone host:$repo" '
529 test_clone_url host:$repo host $repo
531 done
533 #ipv6
534 for repo in rep rep/home/project 123
536 test_expect_success "clone [::1]:$repo" '
537 test_clone_url [::1]:$repo ::1 "$repo"
539 done
540 #home directory
541 test_expect_success "clone host:/~repo" '
542 test_clone_url host:/~repo host "~repo"
545 test_expect_success "clone [::1]:/~repo" '
546 test_clone_url [::1]:/~repo ::1 "~repo"
549 # Corner cases
550 for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
552 test_expect_success "clone $url is not ssh" '
553 test_clone_url $url none
555 done
557 #with ssh:// scheme
558 #ignore trailing colon
559 for tcol in "" :
561 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
562 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
564 # from home directory
565 test_expect_success "clone ssh://host.xz$tcol/~repo" '
566 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
568 done
570 # with port number
571 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
572 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
575 # from home directory with port number
576 test_expect_success 'clone ssh://host.xz:22/~repo' '
577 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
580 #IPv6
581 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
583 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]")
584 test_expect_success "clone ssh://$tuah/home/user/repo" "
585 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
587 done
589 #IPv6 from home directory
590 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
592 euah=$(echo $tuah | tr -d "[]")
593 test_expect_success "clone ssh://$tuah/~repo" "
594 test_clone_url ssh://$tuah/~repo $euah '~repo'
596 done
598 #IPv6 with port number
599 for tuah in [::1] user@[::1] [user@::1]
601 euah=$(echo $tuah | tr -d "[]")
602 test_expect_success "clone ssh://$tuah:22/home/user/repo" "
603 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
605 done
607 #IPv6 from home directory with port number
608 for tuah in [::1] user@[::1] [user@::1]
610 euah=$(echo $tuah | tr -d "[]")
611 test_expect_success "clone ssh://$tuah:22/~repo" "
612 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
614 done
616 test_expect_success 'clone from a repository with two identical branches' '
619 cd src &&
620 git checkout -b another main
621 ) &&
622 git clone src target-11 &&
623 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
627 test_expect_success 'shallow clone locally' '
628 git clone --depth=1 --no-local src ssrrcc &&
629 git clone ssrrcc ddsstt &&
630 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
631 ( cd ddsstt && git fsck )
634 test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
635 rm -rf dst.git &&
636 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
637 git init --bare replay.git &&
638 git -C replay.git index-pack -v --stdin <tmp.pack
641 test_expect_success 'clone on case-insensitive fs' '
642 git init icasefs &&
644 cd icasefs &&
645 o=$(git hash-object -w --stdin </dev/null | hex2oct) &&
646 t=$(printf "100644 X\0${o}100644 x\0${o}" |
647 git hash-object -w -t tree --stdin) &&
648 c=$(git commit-tree -m bogus $t) &&
649 git update-ref refs/heads/bogus $c &&
650 git clone -b bogus . bogus 2>warning
654 test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
655 grep X icasefs/warning &&
656 grep x icasefs/warning &&
657 test_grep "the following paths have collided" icasefs/warning
660 test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \
661 'colliding symlink/directory keeps directory' '
662 git init icasefs-colliding-symlink &&
664 cd icasefs-colliding-symlink &&
665 a=$(printf a | git hash-object -w --stdin) &&
666 printf "100644 %s 0\tA/dir/b\n120000 %s 0\ta\n" $a $a >idx &&
667 git update-index --index-info <idx &&
668 test_tick &&
669 git commit -m initial
670 ) &&
671 git clone icasefs-colliding-symlink icasefs-colliding-symlink-clone &&
672 test_file_not_empty icasefs-colliding-symlink-clone/A/dir/b
675 test_expect_success 'clone with GIT_DEFAULT_HASH' '
677 sane_unset GIT_DEFAULT_HASH &&
678 git init --object-format=sha1 test-sha1 &&
679 git init --object-format=sha256 test-sha256
680 ) &&
681 test_commit -C test-sha1 foo &&
682 test_commit -C test-sha256 foo &&
683 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
684 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
685 git -C test-clone-sha1 status &&
686 git -C test-clone-sha256 status
689 partial_clone_server () {
690 SERVER="$1" &&
692 rm -rf "$SERVER" client &&
693 test_create_repo "$SERVER" &&
694 test_commit -C "$SERVER" one &&
695 HASH1=$(git -C "$SERVER" hash-object one.t) &&
696 git -C "$SERVER" revert HEAD &&
697 test_commit -C "$SERVER" two &&
698 HASH2=$(git -C "$SERVER" hash-object two.t) &&
699 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
700 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1
703 partial_clone () {
704 SERVER="$1" &&
705 URL="$2" &&
707 partial_clone_server "${SERVER}" &&
708 git clone --filter=blob:limit=0 "$URL" client &&
710 git -C client fsck &&
712 # Ensure that unneeded blobs are not inadvertently fetched.
713 test_config -C client remote.origin.promisor "false" &&
714 git -C client config --unset remote.origin.partialclonefilter &&
715 test_must_fail git -C client cat-file -e "$HASH1" &&
717 # But this blob was fetched, because clone performs an initial checkout
718 git -C client cat-file -e "$HASH2"
721 test_expect_success 'partial clone' '
722 partial_clone server "file://$(pwd)/server"
725 test_expect_success 'partial clone with -o' '
726 partial_clone_server server &&
727 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
728 test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
731 test_expect_success 'partial clone: warn if server does not support object filtering' '
732 rm -rf server client &&
733 test_create_repo server &&
734 test_commit -C server one &&
736 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
738 test_grep "filtering not recognized by server" err
741 test_expect_success 'batch missing blob request during checkout' '
742 rm -rf server client &&
744 test_create_repo server &&
745 echo a >server/a &&
746 echo b >server/b &&
747 git -C server add a b &&
749 git -C server commit -m x &&
750 echo aa >server/a &&
751 echo bb >server/b &&
752 git -C server add a b &&
753 git -C server commit -m x &&
755 test_config -C server uploadpack.allowfilter 1 &&
756 test_config -C server uploadpack.allowanysha1inwant 1 &&
758 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
760 # Ensure that there is only one negotiation by checking that there is
761 # only "done" line sent. ("done" marks the end of negotiation.)
762 GIT_TRACE_PACKET="$(pwd)/trace" \
763 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
764 git -C client -c trace2.eventNesting=5 checkout HEAD^ &&
765 grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines &&
766 test_line_count = 1 trace_lines &&
767 grep "fetch> done" trace >done_lines &&
768 test_line_count = 1 done_lines
771 test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' '
772 rm -rf server client &&
774 test_create_repo repo_for_submodule &&
775 test_commit -C repo_for_submodule x &&
777 test_create_repo server &&
778 echo a >server/a &&
779 echo b >server/b &&
780 git -C server add a b &&
781 git -C server commit -m x &&
783 echo aa >server/a &&
784 echo bb >server/b &&
785 # Also add a gitlink pointing to an arbitrary repository
786 test_config_global protocol.file.allow always &&
787 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
788 git -C server add a b c &&
789 git -C server commit -m x &&
791 test_config -C server uploadpack.allowfilter 1 &&
792 test_config -C server uploadpack.allowanysha1inwant 1 &&
794 # Make sure that it succeeds
795 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
798 . "$TEST_DIRECTORY"/lib-httpd.sh
799 start_httpd
801 test_expect_success 'clone with includeIf' '
802 test_when_finished "rm -rf repo \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\"" &&
803 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
805 test_when_finished "rm \"$HOME\"/.gitconfig" &&
806 cat >"$HOME"/.gitconfig <<-EOF &&
807 [includeIf "onbranch:something"]
808 path = /does/not/exist.inc
810 git clone $HTTPD_URL/smart/repo.git repo
813 test_expect_success 'partial clone using HTTP' '
814 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
817 test_expect_success 'reject cloning shallow repository using HTTP' '
818 test_when_finished "rm -rf repo" &&
819 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
820 test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err &&
821 test_grep -e "source repository is shallow, reject to clone." err &&
823 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
826 test_expect_success 'auto-discover bundle URI from HTTP clone' '
827 test_when_finished rm -rf trace.txt repo2 "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
828 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/everything.bundle" --all &&
829 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
831 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
832 uploadpack.advertiseBundleURIs true &&
833 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
834 bundle.version 1 &&
835 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
836 bundle.mode all &&
837 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
838 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
840 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
841 git -c protocol.version=2 \
842 -c transfer.bundleURI=true clone \
843 $HTTPD_URL/smart/repo2.git repo2 &&
844 cat >pattern <<-EOF &&
845 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
847 grep -f pattern trace.txt
850 test_expect_success 'auto-discover multiple bundles from HTTP clone' '
851 test_when_finished rm -rf trace.txt repo3 "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
853 test_commit -C src new &&
854 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/new.bundle" HEAD~1..HEAD &&
855 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
857 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
858 uploadpack.advertiseBundleURIs true &&
859 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
860 bundle.version 1 &&
861 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
862 bundle.mode all &&
864 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
865 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
866 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
867 bundle.new.uri "$HTTPD_URL/new.bundle" &&
869 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
870 git -c protocol.version=2 \
871 -c transfer.bundleURI=true clone \
872 $HTTPD_URL/smart/repo3.git repo3 &&
874 # We should fetch _both_ bundles
875 cat >pattern <<-EOF &&
876 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
878 grep -f pattern trace.txt &&
879 cat >pattern <<-EOF &&
880 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/new.bundle"\]
882 grep -f pattern trace.txt
885 test_expect_success 'auto-discover multiple bundles from HTTP clone: creationToken heuristic' '
886 test_when_finished rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
887 test_when_finished rm -rf clone-heuristic trace*.txt &&
889 test_commit -C src newest &&
890 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/newest.bundle" HEAD~1..HEAD &&
891 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
893 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/repo4.git/config" <<-EOF &&
894 [uploadPack]
895 advertiseBundleURIs = true
897 [bundle]
898 version = 1
899 mode = all
900 heuristic = creationToken
902 [bundle "everything"]
903 uri = $HTTPD_URL/everything.bundle
904 creationtoken = 1
906 [bundle "new"]
907 uri = $HTTPD_URL/new.bundle
908 creationtoken = 2
910 [bundle "newest"]
911 uri = $HTTPD_URL/newest.bundle
912 creationtoken = 3
915 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
916 git -c protocol.version=2 \
917 -c transfer.bundleURI=true clone \
918 "$HTTPD_URL/smart/repo4.git" clone-heuristic &&
920 cat >expect <<-EOF &&
921 $HTTPD_URL/newest.bundle
922 $HTTPD_URL/new.bundle
923 $HTTPD_URL/everything.bundle
926 # We should fetch all bundles in the expected order.
927 test_remote_https_urls <trace-clone.txt >actual &&
928 test_cmp expect actual
931 # DO NOT add non-httpd-specific tests here, because the last part of this
932 # test script is only executed when httpd is available and enabled.
934 test_done