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