7 test_expect_success setup
'
10 test_create_repo src &&
15 git commit -m initial &&
23 test_expect_success
'clone with excess parameters (1)' '
26 test_must_fail git clone -n src dst junk
30 test_expect_success
'clone with excess parameters (2)' '
33 test_must_fail git clone -n "file://$(pwd)/src" dst junk
37 test_expect_success C_LOCALE_OUTPUT
'output from clone' '
39 git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
40 test $(grep Clon output | wc -l) = 1
43 test_expect_success
'clone does not keep pack' '
46 git clone -n "file://$(pwd)/src" dst &&
48 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
52 test_expect_success
'clone checks out files' '
60 test_expect_success
'clone respects GIT_WORK_TREE' '
62 GIT_WORK_TREE=worktree git clone src bare &&
63 test -f bare/config &&
68 test_expect_success
'clone from hooks' '
70 test_create_repo r0 &&
72 test_commit initial &&
76 cat >.git/hooks/pre-commit <<-\EOF &&
81 chmod u+x .git/hooks/pre-commit &&
84 test_must_fail git commit -m invoke-hook &&
86 test_cmp r0/.git/HEAD r2/.git/HEAD &&
87 test_cmp r0/initial.t r2/initial.t
91 test_expect_success
'clone creates intermediate directories' '
93 git clone src long/path/to/dst &&
94 test -f long/path/to/dst/file
98 test_expect_success
'clone creates intermediate directories for bare repo' '
100 git clone --bare src long/path/to/bare/dst &&
101 test -f long/path/to/bare/dst/config
105 test_expect_success
'clone --mirror' '
107 git clone --mirror src mirror &&
108 test -f mirror/HEAD &&
109 test ! -f mirror/file &&
110 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
111 test "+refs/*:refs/*" = "$FETCH" &&
112 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
113 test "$MIRROR" = true
117 test_expect_success
'clone --mirror with detached HEAD' '
119 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
120 git clone --mirror src mirror.detached &&
121 ( cd src && git checkout - ) &&
122 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
123 test_cmp expected actual
127 test_expect_success
'clone --bare with detached HEAD' '
129 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
130 git clone --bare src bare.detached &&
131 ( cd src && git checkout - ) &&
132 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
133 test_cmp expected actual
137 test_expect_success
'clone --bare names the local repository <name>.git' '
139 git clone --bare src &&
144 test_expect_success
'clone --mirror does not repeat tags' '
147 git tag some-tag HEAD) &&
148 git clone --mirror src mirror2 &&
150 git show-ref 2> clone.err > clone.out) &&
151 test_must_fail grep Duplicate mirror2/clone.err &&
152 grep some-tag mirror2/clone.out
156 test_expect_success
'clone to destination with trailing /' '
158 git clone src target-1/ &&
159 T=$( cd target-1 && git rev-parse HEAD ) &&
160 S=$( cd src && git rev-parse HEAD ) &&
165 test_expect_success
'clone to destination with extra trailing /' '
167 git clone src target-2/// &&
168 T=$( cd target-2 && git rev-parse HEAD ) &&
169 S=$( cd src && git rev-parse HEAD ) &&
174 test_expect_success
'clone to an existing empty directory' '
176 git clone src target-3 &&
177 T=$( cd target-3 && git rev-parse HEAD ) &&
178 S=$( cd src && git rev-parse HEAD ) &&
182 test_expect_success
'clone to an existing non-empty directory' '
184 >target-4/Fakefile &&
185 test_must_fail git clone src target-4
188 test_expect_success
'clone to an existing path' '
190 test_must_fail git clone src target-5
193 test_expect_success
'clone a void' '
198 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
199 ! grep "fatal:" err-6 &&
201 cd src-0 && test_commit A
203 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
204 ! grep "fatal:" err-7 &&
205 # There is no reason to insist they are bit-for-bit
206 # identical, but this test should suffice for now.
207 test_cmp target-6/.git/config target-7/.git/config
210 test_expect_success
'clone respects global branch.autosetuprebase' '
212 test_config="$HOME/.gitconfig" &&
213 git config -f "$test_config" branch.autosetuprebase remote &&
217 actual="z$(git config branch.master.rebase)" &&
222 test_expect_success
'respect url-encoding of file://' '
224 git clone "file://$PWD/x+y" xy-url-1 &&
225 git clone "file://$PWD/x%2By" xy-url-2
228 test_expect_success
'do not query-string-decode + in URLs' '
231 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
234 test_expect_success
'do not respect url-encoding of non-url path' '
236 test_must_fail git clone x%2By xy-regular &&
237 git clone x+y xy-regular
240 test_expect_success
'clone separate gitdir' '
242 git clone --separate-git-dir realgitdir src dst &&
243 test -d realgitdir/refs
246 test_expect_success
'clone separate gitdir: output' '
247 echo "gitdir: `pwd`/realgitdir" >expected &&
248 test_cmp expected dst/.git
251 test_expect_success
'clone from .git file' '
252 git clone dst/.git dst2
255 test_expect_success
'fetch from .git gitfile' '
258 git fetch ../dst/.git
262 test_expect_success
'fetch from gitfile parent' '
269 test_expect_success
'clone separate gitdir where target already exists' '
271 test_must_fail git clone --separate-git-dir realgitdir src dst
274 test_expect_success
'clone --reference from original' '
275 git clone --shared --bare src src-1 &&
276 git clone --bare src src-2 &&
277 git clone --reference=src-2 --bare src-1 target-8 &&
278 grep /src-2/ target-8/objects/info/alternates
281 test_expect_success
'clone with more than one --reference' '
282 git clone --bare src src-3 &&
283 git clone --bare src src-4 &&
284 git clone --reference=src-3 --reference=src-4 src target-9 &&
285 grep /src-3/ target-9/.git/objects/info/alternates &&
286 grep /src-4/ target-9/.git/objects/info/alternates
289 test_expect_success
'clone from original with relative alternate' '
291 git clone --bare src nest/src-5 &&
292 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
293 git clone --bare nest/src-5 target-10 &&
294 grep /src/\\.git/objects target-10/objects/info/alternates
297 test_expect_success
'clone checking out a tag' '
298 git clone --branch=some-tag src dst.tag &&
299 GIT_DIR=src/.git git rev-parse some-tag >expected &&
300 test_cmp expected dst.tag/.git/HEAD &&
301 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
302 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
303 test_cmp fetch.expected fetch.actual
306 setup_ssh_wrapper
() {
307 test_expect_success
'setup ssh wrapper' '
308 write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
309 echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
310 # throw away all but the last argument, which should be the
312 while test $# -gt 1; do shift; done
315 GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
317 export TRASH_DIRECTORY &&
318 >"$TRASH_DIRECTORY"/ssh-output
322 copy_ssh_wrapper_as
() {
323 cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" &&
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
)
351 test_expect_success
'clone myhost:src uses ssh' '
352 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 clone "[myhost:123]:src" ssh-bracket-clone &&
364 expect_ssh "-p 123" myhost src
367 test_expect_success
'uplink is not treated as putty' '
368 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
369 git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
370 expect_ssh "-p 123" myhost src
373 test_expect_success
'plink is treated specially (as putty)' '
374 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
375 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
376 expect_ssh "-P 123" myhost src
379 test_expect_success
'plink.exe is treated specially (as putty)' '
380 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
381 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
382 expect_ssh "-P 123" myhost src
385 test_expect_success
'tortoiseplink is like putty, with extra arguments' '
386 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
387 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
388 expect_ssh "-batch -P 123" myhost src
391 # Reset the GIT_SSH environment variable for clone tests.
399 counter
=$
(($counter + 1))
400 test_might_fail git clone
"$1" tmp
$counter &&
405 test_expect_success
!MINGW
'clone c:temp is ssl' '
406 test_clone_url c:temp c temp
409 test_expect_success MINGW
'clone c:temp is dos drive' '
410 test_clone_url c:temp none
414 for repo
in rep rep
/home
/project
123
416 test_expect_success
"clone host:$repo" '
417 test_clone_url host:$repo host $repo
422 for repo
in rep rep
/home
/project
123
424 test_expect_success
"clone [::1]:$repo" '
425 test_clone_url [::1]:$repo ::1 "$repo"
429 test_expect_success
"clone host:/~repo" '
430 test_clone_url host:/~repo host "~repo"
433 test_expect_success
"clone [::1]:/~repo" '
434 test_clone_url [::1]:/~repo ::1 "~repo"
438 for url
in foo
/bar
:baz
[foo
]bar
/baz
:qux
[foo
/bar
]:baz
440 test_expect_success
"clone $url is not ssh" '
441 test_clone_url $url none
446 #ignore trailing colon
449 test_expect_success
"clone ssh://host.xz$tcol/home/user/repo" '
450 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
452 # from home directory
453 test_expect_success
"clone ssh://host.xz$tcol/~repo" '
454 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
459 test_expect_success
'clone ssh://host.xz:22/home/user/repo' '
460 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
463 # from home directory with port number
464 test_expect_success
'clone ssh://host.xz:22/~repo' '
465 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
469 for tuah
in ::1 [::1] [::1]: user@
::1 user@
[::1] user@
[::1]: [user@
::1] [user@
::1]:
471 ehost
=$
(echo $tuah |
sed -e "s/1]:/1]/ "|
tr -d "[]")
472 test_expect_success
"clone ssh://$tuah/home/user/repo" "
473 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
477 #IPv6 from home directory
478 for tuah
in ::1 [::1] user@
::1 user@
[::1] [user@
::1]
480 euah
=$
(echo $tuah |
tr -d "[]")
481 test_expect_success
"clone ssh://$tuah/~repo" "
482 test_clone_url ssh://$tuah/~repo $euah '~repo'
486 #IPv6 with port number
487 for tuah
in [::1] user@
[::1] [user@
::1]
489 euah
=$
(echo $tuah |
tr -d "[]")
490 test_expect_success
"clone ssh://$tuah:22/home/user/repo" "
491 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
495 #IPv6 from home directory with port number
496 for tuah
in [::1] user@
[::1] [user@
::1]
498 euah
=$
(echo $tuah |
tr -d "[]")
499 test_expect_success
"clone ssh://$tuah:22/~repo" "
500 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
504 test_expect_success
'clone from a repository with two identical branches' '
508 git checkout -b another master
510 git clone src target-11 &&
511 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
515 test_expect_success
'shallow clone locally' '
516 git clone --depth=1 --no-local src ssrrcc &&
517 git clone ssrrcc ddsstt &&
518 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
519 ( cd ddsstt && git fsck )
522 test_expect_success
'GIT_TRACE_PACKFILE produces a usable pack' '
524 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
525 git init --bare replay.git &&
526 git -C replay.git index-pack -v --stdin <tmp.pack