gitignore: document that unignoring a directory unignores everything in it
[git/gitster.git] / t / t5601-clone.sh
blob669ec9ba811fedeca820c4454b490e975b03bfca
1 #!/bin/sh
3 test_description=clone
5 . ./test-lib.sh
7 test_expect_success setup '
9 rm -fr .git &&
10 test_create_repo src &&
12 cd src &&
13 >file &&
14 git add file &&
15 git commit -m initial &&
16 echo 1 >file &&
17 git add file &&
18 git commit -m updated
23 test_expect_success 'clone with excess parameters (1)' '
25 rm -fr dst &&
26 test_must_fail git clone -n src dst junk
30 test_expect_success 'clone with excess parameters (2)' '
32 rm -fr dst &&
33 test_must_fail git clone -n "file://$(pwd)/src" dst junk
37 test_expect_success C_LOCALE_OUTPUT 'output from clone' '
38 rm -fr dst &&
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' '
45 rm -fr dst &&
46 git clone -n "file://$(pwd)/src" dst &&
47 ! test -f dst/file &&
48 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
52 test_expect_success 'clone checks out files' '
54 rm -fr dst &&
55 git clone src dst &&
56 test -f dst/file
60 test_expect_success 'clone respects GIT_WORK_TREE' '
62 GIT_WORK_TREE=worktree git clone src bare &&
63 test -f bare/config &&
64 test -f worktree/file
68 test_expect_success 'clone from hooks' '
70 test_create_repo r0 &&
71 cd r0 &&
72 test_commit initial &&
73 cd .. &&
74 git init r1 &&
75 cd r1 &&
76 cat >.git/hooks/pre-commit <<-\EOF &&
77 #!/bin/sh
78 git clone ../r0 ../r2
79 exit 1
80 EOF
81 chmod u+x .git/hooks/pre-commit &&
82 : >file &&
83 git add file &&
84 test_must_fail git commit -m invoke-hook &&
85 cd .. &&
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 &&
140 test -d src.git
144 test_expect_success 'clone --mirror does not repeat tags' '
146 (cd src &&
147 git tag some-tag HEAD) &&
148 git clone --mirror src mirror2 &&
149 (cd 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 ) &&
161 test "$T" = "$S"
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 ) &&
170 test "$T" = "$S"
174 test_expect_success 'clone to an existing empty directory' '
175 mkdir target-3 &&
176 git clone src target-3 &&
177 T=$( cd target-3 && git rev-parse HEAD ) &&
178 S=$( cd src && git rev-parse HEAD ) &&
179 test "$T" = "$S"
182 test_expect_success 'clone to an existing non-empty directory' '
183 mkdir target-4 &&
184 >target-4/Fakefile &&
185 test_must_fail git clone src target-4
188 test_expect_success 'clone to an existing path' '
189 >target-5 &&
190 test_must_fail git clone src target-5
193 test_expect_success 'clone a void' '
194 mkdir src-0 &&
196 cd src-0 && git init
197 ) &&
198 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
199 ! grep "fatal:" err-6 &&
201 cd src-0 && test_commit A
202 ) &&
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 &&
214 rm -fr dst &&
215 git clone src dst &&
216 cd dst &&
217 actual="z$(git config branch.master.rebase)" &&
218 test ztrue = $actual
222 test_expect_success 'respect url-encoding of file://' '
223 git init x+y &&
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' '
229 rm -rf x+y &&
230 git init "x y" &&
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' '
235 git init x+y &&
236 test_must_fail git clone x%2By xy-regular &&
237 git clone x+y xy-regular
240 test_expect_success 'clone separate gitdir' '
241 rm -rf dst &&
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' '
257 cd dst2 &&
258 git fetch ../dst/.git
262 test_expect_success 'fetch from gitfile parent' '
264 cd dst2 &&
265 git fetch ../dst
269 test_expect_success 'clone separate gitdir where target already exists' '
270 rm -rf dst &&
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' '
290 mkdir nest &&
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
311 # command
312 while test $# -gt 1; do shift; done
313 eval "$1"
315 GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
316 export GIT_SSH &&
317 export TRASH_DIRECTORY &&
318 >"$TRASH_DIRECTORY"/ssh-output
322 copy_ssh_wrapper_as () {
323 cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" &&
324 GIT_SSH="$1" &&
325 export GIT_SSH
328 expect_ssh () {
329 test_when_finished '
330 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
331 ' &&
333 case "$#" in
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"
344 esac
345 } >"$TRASH_DIRECTORY/ssh-expect" &&
346 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
349 setup_ssh_wrapper
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 &&
359 expect_ssh none
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.
392 setup_ssh_wrapper
394 counter=0
395 # $1 url
396 # $2 none|host
397 # $3 path
398 test_clone_url () {
399 counter=$(($counter + 1))
400 test_might_fail git clone "$1" tmp$counter &&
401 shift &&
402 expect_ssh "$@"
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
413 #ip v4
414 for repo in rep rep/home/project 123
416 test_expect_success "clone host:$repo" '
417 test_clone_url host:$repo host $repo
419 done
421 #ipv6
422 for repo in rep rep/home/project 123
424 test_expect_success "clone [::1]:$repo" '
425 test_clone_url [::1]:$repo ::1 "$repo"
427 done
428 #home directory
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"
437 # Corner cases
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
443 done
445 #with ssh:// scheme
446 #ignore trailing colon
447 for tcol in "" :
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"
456 done
458 # with port number
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"
468 #IPv6
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
475 done
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'
484 done
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
493 done
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'
502 done
504 test_expect_success 'clone from a repository with two identical branches' '
507 cd src &&
508 git checkout -b another master
509 ) &&
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' '
523 rm -rf dst.git &&
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
529 test_done