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 creates intermediate directories' '
73 git clone src long/path/to/dst &&
74 test -f long/path/to/dst/file
78 test_expect_success
'clone creates intermediate directories for bare repo' '
80 git clone --bare src long/path/to/bare/dst &&
81 test -f long/path/to/bare/dst/config
85 test_expect_success
'clone --mirror' '
87 git clone --mirror src mirror &&
88 test -f mirror/HEAD &&
89 test ! -f mirror/file &&
90 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
91 test "+refs/*:refs/*" = "$FETCH" &&
92 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
97 test_expect_success
'clone --mirror with detached HEAD' '
99 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
100 git clone --mirror src mirror.detached &&
101 ( cd src && git checkout - ) &&
102 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
103 test_cmp expected actual
107 test_expect_success
'clone --bare with detached HEAD' '
109 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
110 git clone --bare src bare.detached &&
111 ( cd src && git checkout - ) &&
112 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
113 test_cmp expected actual
117 test_expect_success
'clone --bare names the local repository <name>.git' '
119 git clone --bare src &&
124 test_expect_success
'clone --mirror does not repeat tags' '
127 git tag some-tag HEAD) &&
128 git clone --mirror src mirror2 &&
130 git show-ref 2> clone.err > clone.out) &&
131 test_must_fail grep Duplicate mirror2/clone.err &&
132 grep some-tag mirror2/clone.out
136 test_expect_success
'clone to destination with trailing /' '
138 git clone src target-1/ &&
139 T=$( cd target-1 && git rev-parse HEAD ) &&
140 S=$( cd src && git rev-parse HEAD ) &&
145 test_expect_success
'clone to destination with extra trailing /' '
147 git clone src target-2/// &&
148 T=$( cd target-2 && git rev-parse HEAD ) &&
149 S=$( cd src && git rev-parse HEAD ) &&
154 test_expect_success
'clone to an existing empty directory' '
156 git clone src target-3 &&
157 T=$( cd target-3 && git rev-parse HEAD ) &&
158 S=$( cd src && git rev-parse HEAD ) &&
162 test_expect_success
'clone to an existing non-empty directory' '
164 >target-4/Fakefile &&
165 test_must_fail git clone src target-4
168 test_expect_success
'clone to an existing path' '
170 test_must_fail git clone src target-5
173 test_expect_success
'clone a void' '
178 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
179 ! grep "fatal:" err-6 &&
181 cd src-0 && test_commit A
183 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
184 ! grep "fatal:" err-7 &&
185 # There is no reason to insist they are bit-for-bit
186 # identical, but this test should suffice for now.
187 test_cmp target-6/.git/config target-7/.git/config
190 test_expect_success
'clone respects global branch.autosetuprebase' '
192 test_config="$HOME/.gitconfig" &&
193 git config -f "$test_config" branch.autosetuprebase remote &&
197 actual="z$(git config branch.master.rebase)" &&
202 test_expect_success
'respect url-encoding of file://' '
204 git clone "file://$PWD/x+y" xy-url-1 &&
205 git clone "file://$PWD/x%2By" xy-url-2
208 test_expect_success
'do not query-string-decode + in URLs' '
211 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
214 test_expect_success
'do not respect url-encoding of non-url path' '
216 test_must_fail git clone x%2By xy-regular &&
217 git clone x+y xy-regular
220 test_expect_success
'clone separate gitdir' '
222 git clone --separate-git-dir realgitdir src dst &&
223 test -d realgitdir/refs
226 test_expect_success
'clone separate gitdir: output' '
227 echo "gitdir: `pwd`/realgitdir" >expected &&
228 test_cmp expected dst/.git
231 test_expect_success
'clone from .git file' '
232 git clone dst/.git dst2
235 test_expect_success
'fetch from .git gitfile' '
238 git fetch ../dst/.git
242 test_expect_success
'fetch from gitfile parent' '
249 test_expect_success
'clone separate gitdir where target already exists' '
251 test_must_fail git clone --separate-git-dir realgitdir src dst
254 test_expect_success
'clone --reference from original' '
255 git clone --shared --bare src src-1 &&
256 git clone --bare src src-2 &&
257 git clone --reference=src-2 --bare src-1 target-8 &&
258 grep /src-2/ target-8/objects/info/alternates
261 test_expect_success
'clone with more than one --reference' '
262 git clone --bare src src-3 &&
263 git clone --bare src src-4 &&
264 git clone --reference=src-3 --reference=src-4 src target-9 &&
265 grep /src-3/ target-9/.git/objects/info/alternates &&
266 grep /src-4/ target-9/.git/objects/info/alternates
269 test_expect_success
'clone from original with relative alternate' '
271 git clone --bare src nest/src-5 &&
272 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
273 git clone --bare nest/src-5 target-10 &&
274 grep /src/\\.git/objects target-10/objects/info/alternates
277 test_expect_success
'clone checking out a tag' '
278 git clone --branch=some-tag src dst.tag &&
279 GIT_DIR=src/.git git rev-parse some-tag >expected &&
280 test_cmp expected dst.tag/.git/HEAD &&
281 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
282 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
283 test_cmp fetch.expected fetch.actual
286 setup_ssh_wrapper
() {
287 test_expect_success
'setup ssh wrapper' '
288 cp "$GIT_BUILD_DIR/test-fake-ssh$X" \
289 "$TRASH_DIRECTORY/ssh-wrapper$X" &&
290 GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper$X" &&
292 export TRASH_DIRECTORY &&
293 >"$TRASH_DIRECTORY"/ssh-output
297 copy_ssh_wrapper_as
() {
298 cp "$TRASH_DIRECTORY/ssh-wrapper$X" "${1%$X}$X" &&
299 GIT_SSH
="${1%$X}$X" &&
305 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
312 echo "ssh: $1 git-upload-pack '$2'"
315 echo "ssh: $1 $2 git-upload-pack '$3'"
318 echo "ssh: $1 $2 git-upload-pack '$3' $4"
320 } >"$TRASH_DIRECTORY/ssh-expect" &&
321 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output
)
326 test_expect_success
'clone myhost:src uses ssh' '
327 git clone myhost:src ssh-clone &&
328 expect_ssh myhost src
331 test_expect_success
!MINGW
,!CYGWIN
'clone local path foo:bar' '
332 cp -R src "foo:bar" &&
333 git clone "foo:bar" foobar &&
337 test_expect_success
'bracketed hostnames are still ssh' '
338 git clone "[myhost:123]:src" ssh-bracket-clone &&
339 expect_ssh "-p 123" myhost src
342 test_expect_success
'uplink is not treated as putty' '
343 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
344 git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
345 expect_ssh "-p 123" myhost src
348 test_expect_success
'plink is treated specially (as putty)' '
349 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
350 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
351 expect_ssh "-P 123" myhost src
354 test_expect_success
'plink.exe is treated specially (as putty)' '
355 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
356 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
357 expect_ssh "-P 123" myhost src
360 test_expect_success
'tortoiseplink is like putty, with extra arguments' '
361 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
362 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
363 expect_ssh "-batch -P 123" myhost src
366 # Reset the GIT_SSH environment variable for clone tests.
374 counter
=$
(($counter + 1))
375 test_might_fail git clone
"$1" tmp
$counter &&
380 test_expect_success
!MINGW
'clone c:temp is ssl' '
381 test_clone_url c:temp c temp
384 test_expect_success MINGW
'clone c:temp is dos drive' '
385 test_clone_url c:temp none
389 for repo
in rep rep
/home
/project
123
391 test_expect_success
"clone host:$repo" '
392 test_clone_url host:$repo host $repo
397 for repo
in rep rep
/home
/project
123
399 test_expect_success
"clone [::1]:$repo" '
400 test_clone_url [::1]:$repo ::1 "$repo"
404 test_expect_success
"clone host:/~repo" '
405 test_clone_url host:/~repo host "~repo"
408 test_expect_success
"clone [::1]:/~repo" '
409 test_clone_url [::1]:/~repo ::1 "~repo"
413 for url
in foo
/bar
:baz
[foo
]bar
/baz
:qux
[foo
/bar
]:baz
415 test_expect_success
"clone $url is not ssh" '
416 test_clone_url $url none
421 #ignore trailing colon
424 test_expect_success
"clone ssh://host.xz$tcol/home/user/repo" '
425 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
427 # from home directory
428 test_expect_success
"clone ssh://host.xz$tcol/~repo" '
429 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
434 test_expect_success
'clone ssh://host.xz:22/home/user/repo' '
435 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
438 # from home directory with port number
439 test_expect_success
'clone ssh://host.xz:22/~repo' '
440 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
444 for tuah
in ::1 [::1] [::1]: user@
::1 user@
[::1] user@
[::1]: [user@
::1] [user@
::1]:
446 ehost
=$
(echo $tuah |
sed -e "s/1]:/1]/ "|
tr -d "[]")
447 test_expect_success
"clone ssh://$tuah/home/user/repo" "
448 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
452 #IPv6 from home directory
453 for tuah
in ::1 [::1] user@
::1 user@
[::1] [user@
::1]
455 euah
=$
(echo $tuah |
tr -d "[]")
456 test_expect_success
"clone ssh://$tuah/~repo" "
457 test_clone_url ssh://$tuah/~repo $euah '~repo'
461 #IPv6 with port number
462 for tuah
in [::1] user@
[::1] [user@
::1]
464 euah
=$
(echo $tuah |
tr -d "[]")
465 test_expect_success
"clone ssh://$tuah:22/home/user/repo" "
466 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
470 #IPv6 from home directory with port number
471 for tuah
in [::1] user@
[::1] [user@
::1]
473 euah
=$
(echo $tuah |
tr -d "[]")
474 test_expect_success
"clone ssh://$tuah:22/~repo" "
475 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
479 test_expect_success
'clone from a repository with two identical branches' '
483 git checkout -b another master
485 git clone src target-11 &&
486 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
490 test_expect_success
'shallow clone locally' '
491 git clone --depth=1 --no-local src ssrrcc &&
492 git clone ssrrcc ddsstt &&
493 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
494 ( cd ddsstt && git fsck )
497 test_expect_success
'GIT_TRACE_PACKFILE produces a usable pack' '
499 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
500 git init --bare replay.git &&
501 git -C replay.git index-pack -v --stdin <tmp.pack