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 creates intermediate directories' '
70 git clone src long/path/to/dst &&
71 test -f long/path/to/dst/file
75 test_expect_success
'clone creates intermediate directories for bare repo' '
77 git clone --bare src long/path/to/bare/dst &&
78 test -f long/path/to/bare/dst/config
82 test_expect_success
'clone --mirror' '
84 git clone --mirror src mirror &&
85 test -f mirror/HEAD &&
86 test ! -f mirror/file &&
87 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
88 test "+refs/*:refs/*" = "$FETCH" &&
89 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
94 test_expect_success
'clone --mirror with detached HEAD' '
96 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
97 git clone --mirror src mirror.detached &&
98 ( cd src && git checkout - ) &&
99 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
100 test_cmp expected actual
104 test_expect_success
'clone --bare with detached HEAD' '
106 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
107 git clone --bare src bare.detached &&
108 ( cd src && git checkout - ) &&
109 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
110 test_cmp expected actual
114 test_expect_success
'clone --bare names the local repository <name>.git' '
116 git clone --bare src &&
121 test_expect_success
'clone --mirror does not repeat tags' '
124 git tag some-tag HEAD) &&
125 git clone --mirror src mirror2 &&
127 git show-ref 2> clone.err > clone.out) &&
128 test_must_fail grep Duplicate mirror2/clone.err &&
129 grep some-tag mirror2/clone.out
133 test_expect_success
'clone to destination with trailing /' '
135 git clone src target-1/ &&
136 T=$( cd target-1 && git rev-parse HEAD ) &&
137 S=$( cd src && git rev-parse HEAD ) &&
142 test_expect_success
'clone to destination with extra trailing /' '
144 git clone src target-2/// &&
145 T=$( cd target-2 && git rev-parse HEAD ) &&
146 S=$( cd src && git rev-parse HEAD ) &&
151 test_expect_success
'clone to an existing empty directory' '
153 git clone src target-3 &&
154 T=$( cd target-3 && git rev-parse HEAD ) &&
155 S=$( cd src && git rev-parse HEAD ) &&
159 test_expect_success
'clone to an existing non-empty directory' '
161 >target-4/Fakefile &&
162 test_must_fail git clone src target-4
165 test_expect_success
'clone to an existing path' '
167 test_must_fail git clone src target-5
170 test_expect_success
'clone a void' '
175 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
176 ! grep "fatal:" err-6 &&
178 cd src-0 && test_commit A
180 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
181 ! grep "fatal:" err-7 &&
182 # There is no reason to insist they are bit-for-bit
183 # identical, but this test should suffice for now.
184 test_cmp target-6/.git/config target-7/.git/config
187 test_expect_success
'clone respects global branch.autosetuprebase' '
189 test_config="$HOME/.gitconfig" &&
190 git config -f "$test_config" branch.autosetuprebase remote &&
194 actual="z$(git config branch.master.rebase)" &&
199 test_expect_success
'respect url-encoding of file://' '
201 git clone "file://$PWD/x+y" xy-url-1 &&
202 git clone "file://$PWD/x%2By" xy-url-2
205 test_expect_success
'do not query-string-decode + in URLs' '
208 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
211 test_expect_success
'do not respect url-encoding of non-url path' '
213 test_must_fail git clone x%2By xy-regular &&
214 git clone x+y xy-regular
217 test_expect_success
'clone separate gitdir' '
219 git clone --separate-git-dir realgitdir src dst &&
220 test -d realgitdir/refs
223 test_expect_success
'clone separate gitdir: output' '
224 echo "gitdir: `pwd`/realgitdir" >expected &&
225 test_cmp expected dst/.git
228 test_expect_success
'clone from .git file' '
229 git clone dst/.git dst2
232 test_expect_success
'fetch from .git gitfile' '
235 git fetch ../dst/.git
239 test_expect_success
'fetch from gitfile parent' '
246 test_expect_success
'clone separate gitdir where target already exists' '
248 test_must_fail git clone --separate-git-dir realgitdir src dst
251 test_expect_success
'clone --reference from original' '
252 git clone --shared --bare src src-1 &&
253 git clone --bare src src-2 &&
254 git clone --reference=src-2 --bare src-1 target-8 &&
255 grep /src-2/ target-8/objects/info/alternates
258 test_expect_success
'clone with more than one --reference' '
259 git clone --bare src src-3 &&
260 git clone --bare src src-4 &&
261 git clone --reference=src-3 --reference=src-4 src target-9 &&
262 grep /src-3/ target-9/.git/objects/info/alternates &&
263 grep /src-4/ target-9/.git/objects/info/alternates
266 test_expect_success
'clone from original with relative alternate' '
268 git clone --bare src nest/src-5 &&
269 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
270 git clone --bare nest/src-5 target-10 &&
271 grep /src/\\.git/objects target-10/objects/info/alternates
274 test_expect_success
'clone checking out a tag' '
275 git clone --branch=some-tag src dst.tag &&
276 GIT_DIR=src/.git git rev-parse some-tag >expected &&
277 test_cmp expected dst.tag/.git/HEAD &&
278 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
279 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
280 test_cmp fetch.expected fetch.actual
283 setup_ssh_wrapper
() {
284 test_expect_success
'setup ssh wrapper' '
285 write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
286 echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
287 # throw away all but the last argument, which should be the
289 while test $# -gt 1; do shift; done
292 GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
294 export TRASH_DIRECTORY &&
295 >"$TRASH_DIRECTORY"/ssh-output
301 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
308 echo "ssh: $1 git-upload-pack '$2'"
311 echo "ssh: $1 $2 git-upload-pack '$3'"
314 echo "ssh: $1 $2 git-upload-pack '$3' $4"
316 } >"$TRASH_DIRECTORY/ssh-expect" &&
317 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output
)
322 test_expect_success
'clone myhost:src uses ssh' '
323 git clone myhost:src ssh-clone &&
324 expect_ssh myhost src
327 test_expect_success
!MINGW
,!CYGWIN
'clone local path foo:bar' '
328 cp -R src "foo:bar" &&
329 git clone "foo:bar" foobar &&
333 test_expect_success
'bracketed hostnames are still ssh' '
334 git clone "[myhost:123]:src" ssh-bracket-clone &&
335 expect_ssh myhost '-p 123' src
343 counter
=$
(($counter + 1))
344 test_might_fail git clone
"$1" tmp
$counter &&
349 test_expect_success
!MINGW
'clone c:temp is ssl' '
350 test_clone_url c:temp c temp
353 test_expect_success MINGW
'clone c:temp is dos drive' '
354 test_clone_url c:temp none
358 for repo
in rep rep
/home
/project
123
360 test_expect_success
"clone host:$repo" '
361 test_clone_url host:$repo host $repo
366 for repo
in rep rep
/home
/project
123
368 test_expect_success
"clone [::1]:$repo" '
369 test_clone_url [::1]:$repo ::1 "$repo"
373 test_expect_success
"clone host:/~repo" '
374 test_clone_url host:/~repo host "~repo"
377 test_expect_success
"clone [::1]:/~repo" '
378 test_clone_url [::1]:/~repo ::1 "~repo"
382 for url
in foo
/bar
:baz
[foo
]bar
/baz
:qux
[foo
/bar
]:baz
384 test_expect_success
"clone $url is not ssh" '
385 test_clone_url $url none
390 test_expect_success
'clone ssh://host.xz/home/user/repo' '
391 test_clone_url "ssh://host.xz/home/user/repo" host.xz "/home/user/repo"
394 # from home directory
395 test_expect_success
'clone ssh://host.xz/~repo' '
396 test_clone_url "ssh://host.xz/~repo" host.xz "~repo"
400 test_expect_success
'clone ssh://host.xz:22/home/user/repo' '
401 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
404 # from home directory with port number
405 test_expect_success
'clone ssh://host.xz:22/~repo' '
406 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
410 for tuah
in ::1 [::1] user@
::1 user@
[::1] [user@
::1]
412 ehost
=$
(echo $tuah |
tr -d "[]")
413 test_expect_success
"clone ssh://$tuah/home/user/repo" "
414 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
418 #IPv6 from home directory
419 for tuah
in ::1 [::1] user@
::1 user@
[::1] [user@
::1]
421 euah
=$
(echo $tuah |
tr -d "[]")
422 test_expect_success
"clone ssh://$tuah/~repo" "
423 test_clone_url ssh://$tuah/~repo $euah '~repo'
427 #IPv6 with port number
428 for tuah
in [::1] user@
[::1] [user@
::1]
430 euah
=$
(echo $tuah |
tr -d "[]")
431 test_expect_success
"clone ssh://$tuah:22/home/user/repo" "
432 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
436 #IPv6 from home directory with port number
437 for tuah
in [::1] user@
[::1] [user@
::1]
439 euah
=$
(echo $tuah |
tr -d "[]")
440 test_expect_success
"clone ssh://$tuah:22/~repo" "
441 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
445 test_expect_success
'clone from a repository with two identical branches' '
449 git checkout -b another master
451 git clone src target-11 &&
452 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
456 test_expect_success
'shallow clone locally' '
457 git clone --depth=1 --no-local src ssrrcc &&
458 git clone ssrrcc ddsstt &&
459 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
460 ( cd ddsstt && git fsck )