8 test_have_prereq !MINGW || X=.exe
10 test_expect_success setup '
13 test_create_repo src &&
18 git commit -m initial &&
26 test_expect_success 'clone with excess parameters (1)' '
29 test_must_fail git clone -n src dst junk
33 test_expect_success 'clone with excess parameters (2)' '
36 test_must_fail git clone -n "file://$(pwd)/src" dst junk
40 test_expect_success C_LOCALE_OUTPUT 'output from clone' '
42 git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
43 test $(grep Clon output | wc -l) = 1
46 test_expect_success 'clone does not keep pack' '
49 git clone -n "file://$(pwd)/src" dst &&
51 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
55 test_expect_success 'clone checks out files' '
63 test_expect_success 'clone respects GIT_WORK_TREE' '
65 GIT_WORK_TREE=worktree git clone src bare &&
66 test -f bare/config &&
71 test_expect_success 'clone from hooks' '
73 test_create_repo r0 &&
75 test_commit initial &&
79 cat >.git/hooks/pre-commit <<-\EOF &&
84 chmod u+x .git/hooks/pre-commit &&
87 test_must_fail git commit -m invoke-hook &&
89 test_cmp r0/.git/HEAD r2/.git/HEAD &&
90 test_cmp r0/initial.t r2/initial.t
94 test_expect_success 'clone creates intermediate directories' '
96 git clone src long/path/to/dst &&
97 test -f long/path/to/dst/file
101 test_expect_success 'clone creates intermediate directories for bare repo' '
103 git clone --bare src long/path/to/bare/dst &&
104 test -f long/path/to/bare/dst/config
108 test_expect_success 'clone --mirror' '
110 git clone --mirror src mirror &&
111 test -f mirror/HEAD &&
112 test ! -f mirror/file &&
113 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
114 test "+refs/*:refs/*" = "$FETCH" &&
115 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
116 test "$MIRROR" = true
120 test_expect_success 'clone --mirror with detached HEAD' '
122 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
123 git clone --mirror src mirror.detached &&
124 ( cd src && git checkout - ) &&
125 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
126 test_cmp expected actual
130 test_expect_success 'clone --bare with detached HEAD' '
132 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
133 git clone --bare src bare.detached &&
134 ( cd src && git checkout - ) &&
135 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
136 test_cmp expected actual
140 test_expect_success 'clone --bare names the local repository <name>.git' '
142 git clone --bare src &&
147 test_expect_success 'clone --mirror does not repeat tags' '
150 git tag some-tag HEAD) &&
151 git clone --mirror src mirror2 &&
153 git show-ref 2> clone.err > clone.out) &&
154 ! grep Duplicate mirror2/clone.err &&
155 grep some-tag mirror2/clone.out
159 test_expect_success 'clone to destination with trailing /' '
161 git clone src target-1/ &&
162 T=$( cd target-1 && git rev-parse HEAD ) &&
163 S=$( cd src && git rev-parse HEAD ) &&
168 test_expect_success 'clone to destination with extra trailing /' '
170 git clone src target-2/// &&
171 T=$( cd target-2 && git rev-parse HEAD ) &&
172 S=$( cd src && git rev-parse HEAD ) &&
177 test_expect_success 'clone to an existing empty directory' '
179 git clone src target-3 &&
180 T=$( cd target-3 && git rev-parse HEAD ) &&
181 S=$( cd src && git rev-parse HEAD ) &&
185 test_expect_success 'clone to an existing non-empty directory' '
187 >target-4/Fakefile &&
188 test_must_fail git clone src target-4
191 test_expect_success 'clone to an existing path' '
193 test_must_fail git clone src target-5
196 test_expect_success 'clone a void' '
201 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
202 ! grep "fatal:" err-6 &&
204 cd src-0 && test_commit A
206 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
207 ! grep "fatal:" err-7 &&
208 # There is no reason to insist they are bit-for-bit
209 # identical, but this test should suffice for now.
210 test_cmp target-6/.git/config target-7/.git/config
213 test_expect_success 'clone respects global branch.autosetuprebase' '
215 test_config="$HOME/.gitconfig" &&
216 git config -f "$test_config" branch.autosetuprebase remote &&
220 actual="z$(git config branch.master.rebase)" &&
225 test_expect_success 'respect url-encoding of file://' '
227 git clone "file://$PWD/x+y" xy-url-1 &&
228 git clone "file://$PWD/x%2By" xy-url-2
231 test_expect_success 'do not query-string-decode + in URLs' '
234 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
237 test_expect_success 'do not respect url-encoding of non-url path' '
239 test_must_fail git clone x%2By xy-regular &&
240 git clone x+y xy-regular
243 test_expect_success 'clone separate gitdir' '
245 git clone --separate-git-dir realgitdir src dst &&
246 test -d realgitdir/refs
249 test_expect_success 'clone separate gitdir: output' '
250 echo "gitdir: $(pwd)/realgitdir" >expected &&
251 test_cmp expected dst/.git
254 test_expect_success 'clone from .git file' '
255 git clone dst/.git dst2
258 test_expect_success 'fetch from .git gitfile' '
261 git fetch ../dst/.git
265 test_expect_success 'fetch from gitfile parent' '
272 test_expect_success 'clone separate gitdir where target already exists' '
274 echo foo=bar >>realgitdir/config &&
275 test_must_fail git clone --separate-git-dir realgitdir src dst &&
276 grep foo=bar realgitdir/config
279 test_expect_success 'clone --reference from original' '
280 git clone --shared --bare src src-1 &&
281 git clone --bare src src-2 &&
282 git clone --reference=src-2 --bare src-1 target-8 &&
283 grep /src-2/ target-8/objects/info/alternates
286 test_expect_success 'clone with more than one --reference' '
287 git clone --bare src src-3 &&
288 git clone --bare src src-4 &&
289 git clone --reference=src-3 --reference=src-4 src target-9 &&
290 grep /src-3/ target-9/.git/objects/info/alternates &&
291 grep /src-4/ target-9/.git/objects/info/alternates
294 test_expect_success 'clone from original with relative alternate' '
296 git clone --bare src nest/src-5 &&
297 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
298 git clone --bare nest/src-5 target-10 &&
299 grep /src/\\.git/objects target-10/objects/info/alternates
302 test_expect_success 'clone checking out a tag' '
303 git clone --branch=some-tag src dst.tag &&
304 GIT_DIR=src/.git git rev-parse some-tag >expected &&
305 test_cmp expected dst.tag/.git/HEAD &&
306 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
307 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
308 test_cmp fetch.expected fetch.actual
311 test_expect_success 'set up ssh wrapper' '
312 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \
313 "$TRASH_DIRECTORY/ssh$X" &&
314 GIT_SSH="$TRASH_DIRECTORY/ssh$X" &&
316 export TRASH_DIRECTORY &&
317 >"$TRASH_DIRECTORY"/ssh-output
320 copy_ssh_wrapper_as () {
322 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" &&
323 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" &&
324 GIT_SSH="${1%$X}$X" &&
325 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\""
330 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
337 echo "ssh: $1 git-upload-pack '$2'"
340 echo "ssh: $1 $2 git-upload-pack '$3'"
343 echo "ssh: $1 $2 git-upload-pack '$3' $4"
345 } >"$TRASH_DIRECTORY/ssh-expect" &&
346 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
349 test_expect_success 'clone myhost:src uses ssh' '
350 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone &&
351 expect_ssh myhost src
354 test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
355 cp -R src "foo:bar" &&
356 git clone "foo:bar" foobar &&
360 test_expect_success 'bracketed hostnames are still ssh' '
361 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone &&
362 expect_ssh "-p 123" myhost src
365 test_expect_success 'OpenSSH variant passes -4' '
366 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone &&
367 expect_ssh "-4 -p 123" myhost src
370 test_expect_success 'variant can be overridden' '
371 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
372 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
373 expect_ssh "-4 -P 123" myhost src
376 test_expect_success 'variant=auto picks based on basename' '
377 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
378 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
379 expect_ssh "-4 -P 123" myhost src
382 test_expect_success 'simple does not support -4/-6' '
383 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
384 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
387 test_expect_success 'simple does not support port' '
388 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
389 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
392 test_expect_success 'uplink is treated as simple' '
393 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
394 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
395 git clone "myhost:src" ssh-clone-uplink &&
396 expect_ssh myhost src
399 test_expect_success 'OpenSSH-like uplink is treated as ssh' '
400 write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
405 exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
407 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" &&
408 GIT_SSH="$TRASH_DIRECTORY/uplink" &&
409 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" &&
410 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
411 expect_ssh "-p 123" myhost src
414 test_expect_success 'plink is treated specially (as putty)' '
415 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
416 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
417 expect_ssh "-P 123" myhost src
420 test_expect_success 'plink.exe is treated specially (as putty)' '
421 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
422 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
423 expect_ssh "-P 123" myhost src
426 test_expect_success 'tortoiseplink is like putty, with extra arguments' '
427 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
428 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
429 expect_ssh "-batch -P 123" myhost src
432 test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' '
433 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
434 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \
435 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 &&
436 expect_ssh "-v -P 123" myhost src
439 test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
440 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
441 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \
442 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 &&
443 expect_ssh "-v -P 123" myhost src
446 test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
447 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
448 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \
449 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
450 expect_ssh "-p 123" myhost src
453 test_expect_success 'ssh.variant overrides plink detection' '
454 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
455 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \
456 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
457 expect_ssh "-p 123" myhost src
460 test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
461 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
462 GIT_SSH_VARIANT=plink \
463 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
464 expect_ssh "-P 123" myhost src
467 test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
468 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
469 GIT_SSH_VARIANT=tortoiseplink \
470 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
471 expect_ssh "-batch -P 123" myhost src
474 test_expect_success 'clean failure on broken quoting' '
476 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
477 git clone "[myhost:123]:src" sq-failure
485 counter=$(($counter + 1))
486 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter &&
491 test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
492 test_clone_url c:temp c temp
495 test_expect_success MINGW 'clone c:temp is dos drive' '
496 test_clone_url c:temp none
500 for repo in rep rep/home/project 123
502 test_expect_success "clone host:$repo" '
503 test_clone_url host:$repo host $repo
508 for repo in rep rep/home/project 123
510 test_expect_success "clone [::1]:$repo" '
511 test_clone_url [::1]:$repo ::1 "$repo"
515 test_expect_success "clone host:/~repo" '
516 test_clone_url host:/~repo host "~repo"
519 test_expect_success "clone [::1]:/~repo" '
520 test_clone_url [::1]:/~repo ::1 "~repo"
524 for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
526 test_expect_success "clone $url is not ssh" '
527 test_clone_url $url none
532 #ignore trailing colon
535 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
536 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
538 # from home directory
539 test_expect_success "clone ssh://host.xz$tcol/~repo" '
540 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
545 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
546 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
549 # from home directory with port number
550 test_expect_success 'clone ssh://host.xz:22/~repo' '
551 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
555 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
557 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]")
558 test_expect_success "clone ssh://$tuah/home/user/repo" "
559 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
563 #IPv6 from home directory
564 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
566 euah=$(echo $tuah | tr -d "[]")
567 test_expect_success "clone ssh://$tuah/~repo" "
568 test_clone_url ssh://$tuah/~repo $euah '~repo'
572 #IPv6 with port number
573 for tuah in [::1] user@[::1] [user@::1]
575 euah=$(echo $tuah | tr -d "[]")
576 test_expect_success "clone ssh://$tuah:22/home/user/repo" "
577 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
581 #IPv6 from home directory with port number
582 for tuah in [::1] user@[::1] [user@::1]
584 euah=$(echo $tuah | tr -d "[]")
585 test_expect_success "clone ssh://$tuah:22/~repo" "
586 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
590 test_expect_success 'clone from a repository with two identical branches' '
594 git checkout -b another master
596 git clone src target-11 &&
597 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
601 test_expect_success 'shallow clone locally' '
602 git clone --depth=1 --no-local src ssrrcc &&
603 git clone ssrrcc ddsstt &&
604 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
605 ( cd ddsstt && git fsck )
608 test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
610 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
611 git init --bare replay.git &&
612 git -C replay.git index-pack -v --stdin <tmp.pack
615 test_expect_success 'clone on case-insensitive fs' '
619 o=$(git hash-object -w --stdin </dev/null | hex2oct) &&
620 t=$(printf "100644 X\0${o}100644 x\0${o}" |
621 git hash-object -w -t tree --stdin) &&
622 c=$(git commit-tree -m bogus $t) &&
623 git update-ref refs/heads/bogus $c &&
624 git clone -b bogus . bogus 2>warning
628 test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
629 grep X icasefs/warning &&
630 grep x icasefs/warning &&
631 test_i18ngrep "the following paths have collided" icasefs/warning
634 test_expect_success 'clone with GIT_DEFAULT_HASH' '
636 sane_unset GIT_DEFAULT_HASH &&
637 git init --object-format=sha1 test-sha1 &&
638 git init --object-format=sha256 test-sha256
640 test_commit -C test-sha1 foo &&
641 test_commit -C test-sha256 foo &&
642 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
643 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
644 git -C test-clone-sha1 status &&
645 git -C test-clone-sha256 status
648 partial_clone_server () {
651 rm -rf "$SERVER" client &&
652 test_create_repo "$SERVER" &&
653 test_commit -C "$SERVER" one &&
654 HASH1=$(git -C "$SERVER" hash-object one.t) &&
655 git -C "$SERVER" revert HEAD &&
656 test_commit -C "$SERVER" two &&
657 HASH2=$(git -C "$SERVER" hash-object two.t) &&
658 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
659 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1
666 partial_clone_server "${SERVER}" &&
667 git clone --filter=blob:limit=0 "$URL" client &&
669 git -C client fsck &&
671 # Ensure that unneeded blobs are not inadvertently fetched.
672 test_config -C client remote.origin.promisor "false" &&
673 git -C client config --unset remote.origin.partialclonefilter &&
674 test_must_fail git -C client cat-file -e "$HASH1" &&
676 # But this blob was fetched, because clone performs an initial checkout
677 git -C client cat-file -e "$HASH2"
680 test_expect_success 'partial clone' '
681 partial_clone server "file://$(pwd)/server"
684 test_expect_success 'partial clone with -o' '
685 partial_clone_server server &&
686 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client
689 test_expect_success 'partial clone: warn if server does not support object filtering' '
690 rm -rf server client &&
691 test_create_repo server &&
692 test_commit -C server one &&
694 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
696 test_i18ngrep "filtering not recognized by server" err
699 test_expect_success 'batch missing blob request during checkout' '
700 rm -rf server client &&
702 test_create_repo server &&
705 git -C server add a b &&
707 git -C server commit -m x &&
710 git -C server add a b &&
711 git -C server commit -m x &&
713 test_config -C server uploadpack.allowfilter 1 &&
714 test_config -C server uploadpack.allowanysha1inwant 1 &&
716 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
718 # Ensure that there is only one negotiation by checking that there is
719 # only "done" line sent. ("done" marks the end of negotiation.)
720 GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ &&
721 grep "fetch> done" trace >done_lines &&
722 test_line_count = 1 done_lines
725 test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' '
726 rm -rf server client &&
728 test_create_repo repo_for_submodule &&
729 test_commit -C repo_for_submodule x &&
731 test_create_repo server &&
734 git -C server add a b &&
735 git -C server commit -m x &&
739 # Also add a gitlink pointing to an arbitrary repository
740 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
741 git -C server add a b c &&
742 git -C server commit -m x &&
744 test_config -C server uploadpack.allowfilter 1 &&
745 test_config -C server uploadpack.allowanysha1inwant 1 &&
747 # Make sure that it succeeds
748 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
751 . "$TEST_DIRECTORY"/lib-httpd.sh
754 test_expect_success 'partial clone using HTTP' '
755 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
758 # DO NOT add non-httpd-specific tests here, because the last part of this
759 # test script is only executed when httpd is available and enabled.