]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5601-clone.sh
t5601: read HEAD using rev-parse
[thirdparty/git.git] / t / t5601-clone.sh
CommitLineData
a2b26acd
JH
1#!/bin/sh
2
3test_description=clone
4
95cf2c01 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
a2b26acd
JH
8. ./test-lib.sh
9
3064d5a3
JS
10X=
11test_have_prereq !MINGW || X=.exe
12
a2b26acd
JH
13test_expect_success setup '
14
15 rm -fr .git &&
16 test_create_repo src &&
17 (
bafe7631
NTND
18 cd src &&
19 >file &&
20 git add file &&
7f08c685
NTND
21 git commit -m initial &&
22 echo 1 >file &&
23 git add file &&
24 git commit -m updated
a2b26acd
JH
25 )
26
27'
28
1db4a75c 29test_expect_success 'clone with excess parameters (1)' '
a2b26acd 30
1db4a75c
SP
31 rm -fr dst &&
32 test_must_fail git clone -n src dst junk
33
34'
35
36test_expect_success 'clone with excess parameters (2)' '
37
38 rm -fr dst &&
a2b26acd
JH
39 test_must_fail git clone -n "file://$(pwd)/src" dst junk
40
41'
42
a926c4b9 43test_expect_success 'output from clone' '
2c3766f0 44 rm -fr dst &&
68b939b2 45 git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
28ba96ab 46 test $(grep Clon output | wc -l) = 1
2c3766f0
AM
47'
48
1db4a75c
SP
49test_expect_success 'clone does not keep pack' '
50
51 rm -fr dst &&
52 git clone -n "file://$(pwd)/src" dst &&
53 ! test -f dst/file &&
54 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep")
55
56'
57
a73bc127
JS
58test_expect_success 'clone checks out files' '
59
1db4a75c 60 rm -fr dst &&
a73bc127
JS
61 git clone src dst &&
62 test -f dst/file
63
64'
65
2beebd22
JK
66test_expect_success 'clone respects GIT_WORK_TREE' '
67
68 GIT_WORK_TREE=worktree git clone src bare &&
69 test -f bare/config &&
70 test -f worktree/file
71
72'
73
86d26f24
NTND
74test_expect_success 'clone from hooks' '
75
76 test_create_repo r0 &&
77 cd r0 &&
78 test_commit initial &&
79 cd .. &&
80 git init r1 &&
81 cd r1 &&
82 cat >.git/hooks/pre-commit <<-\EOF &&
83 #!/bin/sh
84 git clone ../r0 ../r2
85 exit 1
86 EOF
87 chmod u+x .git/hooks/pre-commit &&
88 : >file &&
89 git add file &&
90 test_must_fail git commit -m invoke-hook &&
91 cd .. &&
92 test_cmp r0/.git/HEAD r2/.git/HEAD &&
93 test_cmp r0/initial.t r2/initial.t
94
95'
96
2beebd22
JK
97test_expect_success 'clone creates intermediate directories' '
98
99 git clone src long/path/to/dst &&
100 test -f long/path/to/dst/file
101
102'
103
104test_expect_success 'clone creates intermediate directories for bare repo' '
105
106 git clone --bare src long/path/to/bare/dst &&
107 test -f long/path/to/bare/dst/config
108
109'
110
bc699afc
JS
111test_expect_success 'clone --mirror' '
112
113 git clone --mirror src mirror &&
114 test -f mirror/HEAD &&
115 test ! -f mirror/file &&
116 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
117 test "+refs/*:refs/*" = "$FETCH" &&
118 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
119 test "$MIRROR" = true
120
121'
122
7f08c685
NTND
123test_expect_success 'clone --mirror with detached HEAD' '
124
125 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
126 git clone --mirror src mirror.detached &&
127 ( cd src && git checkout - ) &&
128 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
129 test_cmp expected actual
130
131'
132
133test_expect_success 'clone --bare with detached HEAD' '
134
135 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
136 git clone --bare src bare.detached &&
137 ( cd src && git checkout - ) &&
138 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
139 test_cmp expected actual
140
141'
142
6612f877
JS
143test_expect_success 'clone --bare names the local repository <name>.git' '
144
145 git clone --bare src &&
146 test -d src.git
147
148'
149
468386a9
JS
150test_expect_success 'clone --mirror does not repeat tags' '
151
152 (cd src &&
153 git tag some-tag HEAD) &&
154 git clone --mirror src mirror2 &&
155 (cd mirror2 &&
156 git show-ref 2> clone.err > clone.out) &&
c7cf9566 157 ! grep Duplicate mirror2/clone.err &&
468386a9
JS
158 grep some-tag mirror2/clone.out
159
160'
161
44a68fd5
CB
162test_expect_success 'clone to destination with trailing /' '
163
164 git clone src target-1/ &&
165 T=$( cd target-1 && git rev-parse HEAD ) &&
166 S=$( cd src && git rev-parse HEAD ) &&
167 test "$T" = "$S"
168
169'
170
171test_expect_success 'clone to destination with extra trailing /' '
172
173 git clone src target-2/// &&
174 T=$( cd target-2 && git rev-parse HEAD ) &&
175 S=$( cd src && git rev-parse HEAD ) &&
176 test "$T" = "$S"
177
178'
179
55892d23
AP
180test_expect_success 'clone to an existing empty directory' '
181 mkdir target-3 &&
182 git clone src target-3 &&
183 T=$( cd target-3 && git rev-parse HEAD ) &&
184 S=$( cd src && git rev-parse HEAD ) &&
185 test "$T" = "$S"
186'
187
188test_expect_success 'clone to an existing non-empty directory' '
189 mkdir target-4 &&
190 >target-4/Fakefile &&
191 test_must_fail git clone src target-4
192'
193
194test_expect_success 'clone to an existing path' '
195 >target-5 &&
196 test_must_fail git clone src target-5
197'
198
5cd12b85
JH
199test_expect_success 'clone a void' '
200 mkdir src-0 &&
201 (
202 cd src-0 && git init
203 ) &&
12d49966
JK
204 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
205 ! grep "fatal:" err-6 &&
5cd12b85
JH
206 (
207 cd src-0 && test_commit A
208 ) &&
12d49966
JK
209 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
210 ! grep "fatal:" err-7 &&
5cd12b85
JH
211 # There is no reason to insist they are bit-for-bit
212 # identical, but this test should suffice for now.
213 test_cmp target-6/.git/config target-7/.git/config
214'
215
a9f2c136
JH
216test_expect_success 'clone respects global branch.autosetuprebase' '
217 (
a9f2c136 218 test_config="$HOME/.gitconfig" &&
a9f2c136
JH
219 git config -f "$test_config" branch.autosetuprebase remote &&
220 rm -fr dst &&
221 git clone src dst &&
222 cd dst &&
95cf2c01 223 actual="z$(git config branch.main.rebase)" &&
a9f2c136
JH
224 test ztrue = $actual
225 )
226'
227
9d2e9420
JK
228test_expect_success 'respect url-encoding of file://' '
229 git init x+y &&
730220de
TR
230 git clone "file://$PWD/x+y" xy-url-1 &&
231 git clone "file://$PWD/x%2By" xy-url-2
232'
233
234test_expect_success 'do not query-string-decode + in URLs' '
235 rm -rf x+y &&
236 git init "x y" &&
237 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
9d2e9420
JK
238'
239
240test_expect_success 'do not respect url-encoding of non-url path' '
241 git init x+y &&
242 test_must_fail git clone x%2By xy-regular &&
243 git clone x+y xy-regular
244'
245
b57fb80a
NTND
246test_expect_success 'clone separate gitdir' '
247 rm -rf dst &&
248 git clone --separate-git-dir realgitdir src dst &&
b57fb80a
NTND
249 test -d realgitdir/refs
250'
251
33d56fa0 252test_expect_success 'clone separate gitdir: output' '
c723e50d 253 echo "gitdir: $(pwd)/realgitdir" >expected &&
2c050e01
ÆAB
254 test_cmp expected dst/.git
255'
256
9b0ebc72
NTND
257test_expect_success 'clone from .git file' '
258 git clone dst/.git dst2
259'
260
0c80fdb3
PH
261test_expect_success 'fetch from .git gitfile' '
262 (
263 cd dst2 &&
264 git fetch ../dst/.git
265 )
266'
267
268test_expect_success 'fetch from gitfile parent' '
269 (
270 cd dst2 &&
271 git fetch ../dst
272 )
273'
274
b57fb80a
NTND
275test_expect_success 'clone separate gitdir where target already exists' '
276 rm -rf dst &&
dfaa209a
BW
277 echo foo=bar >>realgitdir/config &&
278 test_must_fail git clone --separate-git-dir realgitdir src dst &&
279 grep foo=bar realgitdir/config
b57fb80a
NTND
280'
281
e6baf4a1 282test_expect_success 'clone --reference from original' '
dbc92b07
JH
283 git clone --shared --bare src src-1 &&
284 git clone --bare src src-2 &&
285 git clone --reference=src-2 --bare src-1 target-8 &&
286 grep /src-2/ target-8/objects/info/alternates
287'
288
289test_expect_success 'clone with more than one --reference' '
290 git clone --bare src src-3 &&
291 git clone --bare src src-4 &&
292 git clone --reference=src-3 --reference=src-4 src target-9 &&
293 grep /src-3/ target-9/.git/objects/info/alternates &&
294 grep /src-4/ target-9/.git/objects/info/alternates
295'
296
e6baf4a1
JH
297test_expect_success 'clone from original with relative alternate' '
298 mkdir nest &&
299 git clone --bare src nest/src-5 &&
300 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
301 git clone --bare nest/src-5 target-10 &&
302 grep /src/\\.git/objects target-10/objects/info/alternates
303'
304
5a7d5b68
NTND
305test_expect_success 'clone checking out a tag' '
306 git clone --branch=some-tag src dst.tag &&
307 GIT_DIR=src/.git git rev-parse some-tag >expected &&
dd8468ef
HWN
308 GIT_DIR=dst.tag/.git git rev-parse HEAD >actual &&
309 test_cmp expected actual &&
5a7d5b68
NTND
310 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
311 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
312 test_cmp fetch.expected fetch.actual
313'
314
8339805b
JN
315test_expect_success 'set up ssh wrapper' '
316 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \
317 "$TRASH_DIRECTORY/ssh$X" &&
318 GIT_SSH="$TRASH_DIRECTORY/ssh$X" &&
319 export GIT_SSH &&
320 export TRASH_DIRECTORY &&
321 >"$TRASH_DIRECTORY"/ssh-output
322'
8d3d28f5 323
baaf2337 324copy_ssh_wrapper_as () {
cff48ccf 325 rm -f "${1%$X}$X" &&
94b8ae5a 326 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" &&
8339805b 327 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" &&
3064d5a3 328 GIT_SSH="${1%$X}$X" &&
8339805b 329 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\""
baaf2337 330}
331
8d3d28f5 332expect_ssh () {
710eb3e2
TB
333 test_when_finished '
334 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
335 ' &&
8d3d28f5 336 {
9f697652
TB
337 case "$#" in
338 1)
8d3d28f5 339 ;;
9f697652 340 2)
8d3d28f5 341 echo "ssh: $1 git-upload-pack '$2'"
9f697652
TB
342 ;;
343 3)
344 echo "ssh: $1 $2 git-upload-pack '$3'"
345 ;;
346 *)
347 echo "ssh: $1 $2 git-upload-pack '$3' $4"
8d3d28f5
NTND
348 esac
349 } >"$TRASH_DIRECTORY/ssh-expect" &&
350 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
351}
352
2171f3d2 353test_expect_success 'clone myhost:src uses ssh' '
3a5728dc 354 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone &&
8d3d28f5
NTND
355 expect_ssh myhost src
356'
357
f57a8715 358test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
60003340 359 cp -R src "foo:bar" &&
710eb3e2 360 git clone "foo:bar" foobar &&
8d3d28f5
NTND
361 expect_ssh none
362'
363
364test_expect_success 'bracketed hostnames are still ssh' '
3a5728dc 365 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone &&
d1018c24 366 expect_ssh "-p 123" myhost src
60003340
NTND
367'
368
94b8ae5a 369test_expect_success 'OpenSSH variant passes -4' '
3a5728dc 370 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone &&
94b8ae5a
BW
371 expect_ssh "-4 -p 123" myhost src
372'
373
a3f5b66f
JN
374test_expect_success 'variant can be overridden' '
375 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
376 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
377 expect_ssh "-4 -P 123" myhost src
94b8ae5a
BW
378'
379
0da0e49b
JN
380test_expect_success 'variant=auto picks based on basename' '
381 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
382 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
383 expect_ssh "-4 -P 123" myhost src
384'
385
a3f5b66f 386test_expect_success 'simple does not support -4/-6' '
94b8ae5a 387 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
3fa5e0d0
JN
388 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
389'
390
391test_expect_success 'simple does not support port' '
392 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
393 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
94b8ae5a
BW
394'
395
396test_expect_success 'uplink is treated as simple' '
baaf2337 397 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
3fa5e0d0
JN
398 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
399 git clone "myhost:src" ssh-clone-uplink &&
94b8ae5a 400 expect_ssh myhost src
baaf2337 401'
402
0da0e49b
JN
403test_expect_success 'OpenSSH-like uplink is treated as ssh' '
404 write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
405 if test "\$1" = "-G"
406 then
407 exit 0
408 fi &&
409 exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
410 EOF
411 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" &&
412 GIT_SSH="$TRASH_DIRECTORY/uplink" &&
413 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" &&
3a5728dc 414 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
0da0e49b
JN
415 expect_ssh "-p 123" myhost src
416'
417
baaf2337 418test_expect_success 'plink is treated specially (as putty)' '
419 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
420 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
421 expect_ssh "-P 123" myhost src
60003340
NTND
422'
423
baaf2337 424test_expect_success 'plink.exe is treated specially (as putty)' '
425 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
426 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
427 expect_ssh "-P 123" myhost src
428'
429
430test_expect_success 'tortoiseplink is like putty, with extra arguments' '
431 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
432 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
433 expect_ssh "-batch -P 123" myhost src
434'
435
e9d9a8a4
SF
436test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' '
437 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
438 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \
439 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 &&
440 expect_ssh "-v -P 123" myhost src
441'
442
e9d9a8a4
SF
443test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
444 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
445 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \
446 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 &&
447 expect_ssh "-v -P 123" myhost src
448'
449
dd33e077
SF
450test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
451 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
3a5728dc
JT
452 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \
453 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
dd33e077
SF
454 expect_ssh "-p 123" myhost src
455'
456
457test_expect_success 'ssh.variant overrides plink detection' '
458 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
3a5728dc 459 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \
dd33e077
SF
460 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
461 expect_ssh "-p 123" myhost src
462'
463
464test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
8339805b 465 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
dd33e077
SF
466 GIT_SSH_VARIANT=plink \
467 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
468 expect_ssh "-P 123" myhost src
469'
470
471test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
8339805b 472 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
dd33e077
SF
473 GIT_SSH_VARIANT=tortoiseplink \
474 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
475 expect_ssh "-batch -P 123" myhost src
476'
477
22e5ae5c
JK
478test_expect_success 'clean failure on broken quoting' '
479 test_must_fail \
480 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
481 git clone "[myhost:123]:src" sq-failure
482'
483
2171f3d2
TB
484counter=0
485# $1 url
486# $2 none|host
487# $3 path
488test_clone_url () {
489 counter=$(($counter + 1))
3a5728dc 490 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter &&
9f697652
TB
491 shift &&
492 expect_ssh "$@"
2171f3d2
TB
493}
494
1cadad6f 495test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
2171f3d2
TB
496 test_clone_url c:temp c temp
497'
498
499test_expect_success MINGW 'clone c:temp is dos drive' '
500 test_clone_url c:temp none
501'
502
503#ip v4
6a599748 504for repo in rep rep/home/project 123
2171f3d2
TB
505do
506 test_expect_success "clone host:$repo" '
507 test_clone_url host:$repo host $repo
508 '
509done
510
511#ipv6
2171f3d2
TB
512for repo in rep rep/home/project 123
513do
514 test_expect_success "clone [::1]:$repo" '
9f697652 515 test_clone_url [::1]:$repo ::1 "$repo"
2171f3d2
TB
516 '
517done
c59ab2e5
TB
518#home directory
519test_expect_success "clone host:/~repo" '
520 test_clone_url host:/~repo host "~repo"
521'
522
523test_expect_success "clone [::1]:/~repo" '
524 test_clone_url [::1]:/~repo ::1 "~repo"
525'
2171f3d2
TB
526
527# Corner cases
83b05875 528for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
2171f3d2
TB
529do
530 test_expect_success "clone $url is not ssh" '
531 test_clone_url $url none
532 '
533done
534
535#with ssh:// scheme
6b6c5f7a
TB
536#ignore trailing colon
537for tcol in "" :
538do
539 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
540 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
541 '
542 # from home directory
543 test_expect_success "clone ssh://host.xz$tcol/~repo" '
544 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
2171f3d2 545'
6b6c5f7a 546done
2171f3d2
TB
547
548# with port number
549test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
550 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
551'
552
553# from home directory with port number
554test_expect_success 'clone ssh://host.xz:22/~repo' '
555 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
556'
557
558#IPv6
6b6c5f7a 559for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
9f697652 560do
a75a3081 561 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]")
9f697652
TB
562 test_expect_success "clone ssh://$tuah/home/user/repo" "
563 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
564 "
565done
2171f3d2
TB
566
567#IPv6 from home directory
9f697652
TB
568for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
569do
570 euah=$(echo $tuah | tr -d "[]")
571 test_expect_success "clone ssh://$tuah/~repo" "
572 test_clone_url ssh://$tuah/~repo $euah '~repo'
573 "
574done
2171f3d2
TB
575
576#IPv6 with port number
9f697652
TB
577for tuah in [::1] user@[::1] [user@::1]
578do
579 euah=$(echo $tuah | tr -d "[]")
580 test_expect_success "clone ssh://$tuah:22/home/user/repo" "
581 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
582 "
583done
2171f3d2
TB
584
585#IPv6 from home directory with port number
9f697652
TB
586for tuah in [::1] user@[::1] [user@::1]
587do
588 euah=$(echo $tuah | tr -d "[]")
589 test_expect_success "clone ssh://$tuah:22/~repo" "
590 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
591 "
592done
2171f3d2 593
8b277222
JH
594test_expect_success 'clone from a repository with two identical branches' '
595
596 (
597 cd src &&
95cf2c01 598 git checkout -b another main
8b277222
JH
599 ) &&
600 git clone src target-11 &&
601 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
602
603'
604
0d7d285f
NTND
605test_expect_success 'shallow clone locally' '
606 git clone --depth=1 --no-local src ssrrcc &&
607 git clone ssrrcc ddsstt &&
608 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
609 ( cd ddsstt && git fsck )
610'
611
32359838
JK
612test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
613 rm -rf dst.git &&
614 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
615 git init --bare replay.git &&
616 git -C replay.git index-pack -v --stdin <tmp.pack
617'
618
b6947af2
ES
619test_expect_success 'clone on case-insensitive fs' '
620 git init icasefs &&
621 (
51b85471 622 cd icasefs &&
b6947af2
ES
623 o=$(git hash-object -w --stdin </dev/null | hex2oct) &&
624 t=$(printf "100644 X\0${o}100644 x\0${o}" |
625 git hash-object -w -t tree --stdin) &&
626 c=$(git commit-tree -m bogus $t) &&
627 git update-ref refs/heads/bogus $c &&
b878579a 628 git clone -b bogus . bogus 2>warning
b6947af2
ES
629 )
630'
631
a7f609ec 632test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
b878579a
NTND
633 grep X icasefs/warning &&
634 grep x icasefs/warning &&
635 test_i18ngrep "the following paths have collided" icasefs/warning
636'
637
47ac9703 638test_expect_success 'clone with GIT_DEFAULT_HASH' '
639 (
640 sane_unset GIT_DEFAULT_HASH &&
641 git init --object-format=sha1 test-sha1 &&
642 git init --object-format=sha256 test-sha256
643 ) &&
644 test_commit -C test-sha1 foo &&
645 test_commit -C test-sha256 foo &&
646 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
647 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
648 git -C test-clone-sha1 status &&
649 git -C test-clone-sha256 status
650'
651
1c4a9f91 652partial_clone_server () {
548719fb 653 SERVER="$1" &&
548719fb
JT
654
655 rm -rf "$SERVER" client &&
656 test_create_repo "$SERVER" &&
657 test_commit -C "$SERVER" one &&
44b6c05b 658 HASH1=$(git -C "$SERVER" hash-object one.t) &&
548719fb
JT
659 git -C "$SERVER" revert HEAD &&
660 test_commit -C "$SERVER" two &&
44b6c05b 661 HASH2=$(git -C "$SERVER" hash-object two.t) &&
548719fb 662 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
1c4a9f91
XL
663 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1
664}
548719fb 665
1c4a9f91
XL
666partial_clone () {
667 SERVER="$1" &&
668 URL="$2" &&
669
670 partial_clone_server "${SERVER}" &&
548719fb
JT
671 git clone --filter=blob:limit=0 "$URL" client &&
672
673 git -C client fsck &&
674
675 # Ensure that unneeded blobs are not inadvertently fetched.
b14ed5ad 676 test_config -C client remote.origin.promisor "false" &&
fa3d1b63 677 git -C client config --unset remote.origin.partialclonefilter &&
548719fb
JT
678 test_must_fail git -C client cat-file -e "$HASH1" &&
679
680 # But this blob was fetched, because clone performs an initial checkout
681 git -C client cat-file -e "$HASH2"
682}
683
684test_expect_success 'partial clone' '
685 partial_clone server "file://$(pwd)/server"
686'
687
1c4a9f91
XL
688test_expect_success 'partial clone with -o' '
689 partial_clone_server server &&
23547c40
JT
690 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
691 test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
1c4a9f91
XL
692'
693
548719fb
JT
694test_expect_success 'partial clone: warn if server does not support object filtering' '
695 rm -rf server client &&
696 test_create_repo server &&
697 test_commit -C server one &&
698
699 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
700
701 test_i18ngrep "filtering not recognized by server" err
702'
703
c0c578b3
JT
704test_expect_success 'batch missing blob request during checkout' '
705 rm -rf server client &&
706
707 test_create_repo server &&
708 echo a >server/a &&
709 echo b >server/b &&
710 git -C server add a b &&
711
712 git -C server commit -m x &&
713 echo aa >server/a &&
714 echo bb >server/b &&
715 git -C server add a b &&
716 git -C server commit -m x &&
717
718 test_config -C server uploadpack.allowfilter 1 &&
719 test_config -C server uploadpack.allowanysha1inwant 1 &&
720
721 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
722
723 # Ensure that there is only one negotiation by checking that there is
724 # only "done" line sent. ("done" marks the end of negotiation.)
725 GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ &&
7ca3c0ac 726 grep "fetch> done" trace >done_lines &&
c0c578b3
JT
727 test_line_count = 1 done_lines
728'
729
730test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' '
731 rm -rf server client &&
732
733 test_create_repo repo_for_submodule &&
734 test_commit -C repo_for_submodule x &&
735
736 test_create_repo server &&
737 echo a >server/a &&
738 echo b >server/b &&
739 git -C server add a b &&
740 git -C server commit -m x &&
741
742 echo aa >server/a &&
743 echo bb >server/b &&
744 # Also add a gitlink pointing to an arbitrary repository
745 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
746 git -C server add a b c &&
747 git -C server commit -m x &&
748
749 test_config -C server uploadpack.allowfilter 1 &&
750 test_config -C server uploadpack.allowanysha1inwant 1 &&
751
752 # Make sure that it succeeds
753 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
754'
755
548719fb
JT
756. "$TEST_DIRECTORY"/lib-httpd.sh
757start_httpd
758
759test_expect_success 'partial clone using HTTP' '
760 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
761'
762
4fe788b1
LL
763test_expect_success 'reject cloning shallow repository using HTTP' '
764 test_when_finished "rm -rf repo" &&
765 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
766 test_must_fail git clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err &&
767 test_i18ngrep -e "source repository is shallow, reject to clone." err &&
768
769 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
770'
771
decfe05b
SG
772# DO NOT add non-httpd-specific tests here, because the last part of this
773# test script is only executed when httpd is available and enabled.
774
a2b26acd 775test_done