5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 test_have_prereq
!MINGW || X
=.exe
13 test_expect_success setup
'
16 test_create_repo src &&
21 git commit -m initial &&
29 test_expect_success
'clone with excess parameters (1)' '
32 test_must_fail git clone -n src dst junk
36 test_expect_success
'clone with excess parameters (2)' '
39 test_must_fail git clone -n "file://$(pwd)/src" dst junk
43 test_expect_success
'output from clone' '
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' '
52 git clone -n "file://$(pwd)/src" dst &&
54 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
58 test_expect_success
'clone checks out files' '
66 test_expect_success
'clone respects GIT_WORK_TREE' '
68 GIT_WORK_TREE=worktree git clone src bare &&
69 test -f bare/config &&
74 test_expect_success
'clone from hooks' '
76 test_create_repo r0 &&
78 test_commit initial &&
82 test_hook pre-commit <<-\EOF &&
88 test_must_fail git commit -m invoke-hook &&
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 &&
148 test_expect_success
'clone --mirror does not repeat tags' '
151 git tag some-tag HEAD) &&
152 git clone --mirror src 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 ) &&
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 ) &&
178 test_expect_success
'clone to an existing empty directory' '
180 git clone src target-3 &&
181 T=$( cd target-3 && git rev-parse HEAD ) &&
182 S=$( cd src && git rev-parse HEAD ) &&
186 test_expect_success
'clone to an existing non-empty directory' '
188 >target-4/Fakefile &&
189 test_must_fail git clone src target-4
192 test_expect_success
'clone to an existing path' '
194 test_must_fail git clone src target-5
197 test_expect_success
'clone a void' '
202 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
203 ! grep "fatal:" err-6 &&
205 cd src-0 && test_commit A
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 &&
221 actual="z$(git config branch.main.rebase)" &&
226 test_expect_success
'respect url-encoding of file://' '
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' '
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' '
240 test_must_fail git clone x%2By xy-regular &&
241 git clone x+y xy-regular
244 test_expect_success
'clone separate gitdir' '
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' '
262 git fetch ../dst/.git
266 test_expect_success
'fetch from gitfile parent' '
273 test_expect_success
'clone separate gitdir where target already exists' '
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' '
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" &&
318 export TRASH_DIRECTORY &&
319 >"$TRASH_DIRECTORY"/ssh-output
322 copy_ssh_wrapper_as
() {
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\""
332 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
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"
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 &&
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 &&
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' '
478 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
479 git clone "[myhost:123]:src" sq-failure
487 counter
=$
(($counter + 1))
488 test_might_fail env GIT_TEST_PROTOCOL_VERSION
=0 git clone
"$1" tmp
$counter &&
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
502 for repo
in rep rep
/home
/project
123
504 test_expect_success
"clone host:$repo" '
505 test_clone_url host:$repo host $repo
510 for repo
in rep rep
/home
/project
123
512 test_expect_success
"clone [::1]:$repo" '
513 test_clone_url [::1]:$repo ::1 "$repo"
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"
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
534 #ignore trailing colon
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"
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"
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
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'
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
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'
592 test_expect_success
'clone from a repository with two identical branches' '
596 git checkout -b another main
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' '
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' '
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
'clone with GIT_DEFAULT_HASH' '
638 sane_unset GIT_DEFAULT_HASH &&
639 git init --object-format=sha1 test-sha1 &&
640 git init --object-format=sha256 test-sha256
642 test_commit -C test-sha1 foo &&
643 test_commit -C test-sha256 foo &&
644 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
645 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
646 git -C test-clone-sha1 status &&
647 git -C test-clone-sha256 status
650 partial_clone_server
() {
653 rm -rf "$SERVER" client
&&
654 test_create_repo
"$SERVER" &&
655 test_commit
-C "$SERVER" one
&&
656 HASH1
=$
(git
-C "$SERVER" hash-object one.t
) &&
657 git
-C "$SERVER" revert HEAD
&&
658 test_commit
-C "$SERVER" two
&&
659 HASH2
=$
(git
-C "$SERVER" hash-object two.t
) &&
660 test_config
-C "$SERVER" uploadpack.allowfilter
1 &&
661 test_config
-C "$SERVER" uploadpack.allowanysha1inwant
1
668 partial_clone_server
"${SERVER}" &&
669 git clone
--filter=blob
:limit
=0 "$URL" client
&&
671 git
-C client fsck
&&
673 # Ensure that unneeded blobs are not inadvertently fetched.
674 test_config
-C client remote.origin.promisor
"false" &&
675 git
-C client config
--unset remote.origin.partialclonefilter
&&
676 test_must_fail git
-C client cat-file
-e "$HASH1" &&
678 # But this blob was fetched, because clone performs an initial checkout
679 git
-C client cat-file
-e "$HASH2"
682 test_expect_success
'partial clone' '
683 partial_clone server "file://$(pwd)/server"
686 test_expect_success
'partial clone with -o' '
687 partial_clone_server server &&
688 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
689 test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
692 test_expect_success
'partial clone: warn if server does not support object filtering' '
693 rm -rf server client &&
694 test_create_repo server &&
695 test_commit -C server one &&
697 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
699 test_i18ngrep "filtering not recognized by server" err
702 test_expect_success
'batch missing blob request during checkout' '
703 rm -rf server client &&
705 test_create_repo server &&
708 git -C server add a b &&
710 git -C server commit -m x &&
713 git -C server add a b &&
714 git -C server commit -m x &&
716 test_config -C server uploadpack.allowfilter 1 &&
717 test_config -C server uploadpack.allowanysha1inwant 1 &&
719 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
721 # Ensure that there is only one negotiation by checking that there is
722 # only "done" line sent. ("done" marks the end of negotiation.)
723 GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ &&
724 grep "fetch> done" trace >done_lines &&
725 test_line_count = 1 done_lines
728 test_expect_success
'batch missing blob request does not inadvertently try to fetch gitlinks' '
729 rm -rf server client &&
731 test_create_repo repo_for_submodule &&
732 test_commit -C repo_for_submodule x &&
734 test_create_repo server &&
737 git -C server add a b &&
738 git -C server commit -m x &&
742 # Also add a gitlink pointing to an arbitrary repository
743 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
744 git -C server add a b c &&
745 git -C server commit -m x &&
747 test_config -C server uploadpack.allowfilter 1 &&
748 test_config -C server uploadpack.allowanysha1inwant 1 &&
750 # Make sure that it succeeds
751 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
754 .
"$TEST_DIRECTORY"/lib-httpd.sh
757 test_expect_success
'partial clone using HTTP' '
758 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
761 test_expect_success
'reject cloning shallow repository using HTTP' '
762 test_when_finished "rm -rf repo" &&
763 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
764 test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err &&
765 test_i18ngrep -e "source repository is shallow, reject to clone." err &&
767 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
770 # DO NOT add non-httpd-specific tests here, because the last part of this
771 # test script is only executed when httpd is available and enabled.