]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5601-clone.sh
The seventh batch
[thirdparty/git.git] / t / t5601-clone.sh
1 #!/bin/sh
2
3 test_description=clone
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 X=
11 test_have_prereq !MINGW || X=.exe
12
13 test_expect_success setup '
14
15 rm -fr .git &&
16 test_create_repo src &&
17 (
18 cd src &&
19 >file &&
20 git add file &&
21 git commit -m initial &&
22 echo 1 >file &&
23 git add file &&
24 git commit -m updated
25 )
26
27 '
28
29 test_expect_success 'clone with excess parameters (1)' '
30
31 rm -fr dst &&
32 test_must_fail git clone -n src dst junk
33
34 '
35
36 test_expect_success 'clone with excess parameters (2)' '
37
38 rm -fr dst &&
39 test_must_fail git clone -n "file://$(pwd)/src" dst junk
40
41 '
42
43 test_expect_success 'output from clone' '
44 rm -fr dst &&
45 git clone -n "file://$(pwd)/src" dst >output 2>&1 &&
46 test $(grep Clon output | wc -l) = 1
47 '
48
49 test_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
58 test_expect_success 'clone checks out files' '
59
60 rm -fr dst &&
61 git clone src dst &&
62 test -f dst/file
63
64 '
65
66 test_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
74 test_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 test_hook pre-commit <<-\EOF &&
83 git clone ../r0 ../r2
84 exit 1
85 EOF
86 : >file &&
87 git add file &&
88 test_must_fail git commit -m invoke-hook &&
89 cd .. &&
90 test_cmp r0/.git/HEAD r2/.git/HEAD &&
91 test_cmp r0/initial.t r2/initial.t
92
93 '
94
95 test_expect_success 'clone creates intermediate directories' '
96
97 git clone src long/path/to/dst &&
98 test -f long/path/to/dst/file
99
100 '
101
102 test_expect_success 'clone creates intermediate directories for bare repo' '
103
104 git clone --bare src long/path/to/bare/dst &&
105 test -f long/path/to/bare/dst/config
106
107 '
108
109 test_expect_success 'clone --mirror' '
110
111 git clone --mirror src mirror &&
112 test -f mirror/HEAD &&
113 test ! -f mirror/file &&
114 FETCH="$(cd mirror && git config remote.origin.fetch)" &&
115 test "+refs/*:refs/*" = "$FETCH" &&
116 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" &&
117 test "$MIRROR" = true
118
119 '
120
121 test_expect_success 'clone --mirror with detached HEAD' '
122
123 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
124 git clone --mirror src mirror.detached &&
125 ( cd src && git checkout - ) &&
126 GIT_DIR=mirror.detached git rev-parse HEAD >actual &&
127 test_cmp expected actual
128
129 '
130
131 test_expect_success 'clone --bare with detached HEAD' '
132
133 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) &&
134 git clone --bare src bare.detached &&
135 ( cd src && git checkout - ) &&
136 GIT_DIR=bare.detached git rev-parse HEAD >actual &&
137 test_cmp expected actual
138
139 '
140
141 test_expect_success 'clone --bare names the local repository <name>.git' '
142
143 git clone --bare src &&
144 test -d src.git
145
146 '
147
148 test_expect_success 'clone --mirror does not repeat tags' '
149
150 (cd src &&
151 git tag some-tag HEAD) &&
152 git clone --mirror src mirror2 &&
153 (cd mirror2 &&
154 git show-ref 2> clone.err > clone.out) &&
155 ! grep Duplicate mirror2/clone.err &&
156 grep some-tag mirror2/clone.out
157
158 '
159
160 test_expect_success 'clone with files ref format' '
161 test_when_finished "rm -rf ref-storage" &&
162 git clone --ref-format=files --mirror src ref-storage &&
163 echo files >expect &&
164 git -C ref-storage rev-parse --show-ref-format >actual &&
165 test_cmp expect actual
166 '
167
168 test_expect_success 'clone with garbage ref format' '
169 cat >expect <<-EOF &&
170 fatal: unknown ref storage format ${SQ}garbage${SQ}
171 EOF
172 test_must_fail git clone --ref-format=garbage --mirror src ref-storage 2>err &&
173 test_cmp expect err &&
174 test_path_is_missing ref-storage
175 '
176
177 test_expect_success 'clone to destination with trailing /' '
178
179 git clone src target-1/ &&
180 T=$( cd target-1 && git rev-parse HEAD ) &&
181 S=$( cd src && git rev-parse HEAD ) &&
182 test "$T" = "$S"
183
184 '
185
186 test_expect_success 'clone to destination with extra trailing /' '
187
188 git clone src target-2/// &&
189 T=$( cd target-2 && git rev-parse HEAD ) &&
190 S=$( cd src && git rev-parse HEAD ) &&
191 test "$T" = "$S"
192
193 '
194
195 test_expect_success 'clone to an existing empty directory' '
196 mkdir target-3 &&
197 git clone src target-3 &&
198 T=$( cd target-3 && git rev-parse HEAD ) &&
199 S=$( cd src && git rev-parse HEAD ) &&
200 test "$T" = "$S"
201 '
202
203 test_expect_success 'clone to an existing non-empty directory' '
204 mkdir target-4 &&
205 >target-4/Fakefile &&
206 test_must_fail git clone src target-4
207 '
208
209 test_expect_success 'clone to an existing path' '
210 >target-5 &&
211 test_must_fail git clone src target-5
212 '
213
214 test_expect_success 'clone a void' '
215 mkdir src-0 &&
216 (
217 cd src-0 && git init
218 ) &&
219 git clone "file://$(pwd)/src-0" target-6 2>err-6 &&
220 ! grep "fatal:" err-6 &&
221 (
222 cd src-0 && test_commit A
223 ) &&
224 git clone "file://$(pwd)/src-0" target-7 2>err-7 &&
225 ! grep "fatal:" err-7 &&
226 # There is no reason to insist they are bit-for-bit
227 # identical, but this test should suffice for now.
228 test_cmp target-6/.git/config target-7/.git/config
229 '
230
231 test_expect_success 'clone respects global branch.autosetuprebase' '
232 (
233 test_config="$HOME/.gitconfig" &&
234 git config -f "$test_config" branch.autosetuprebase remote &&
235 rm -fr dst &&
236 git clone src dst &&
237 cd dst &&
238 actual="z$(git config branch.main.rebase)" &&
239 test ztrue = $actual
240 )
241 '
242
243 test_expect_success 'respect url-encoding of file://' '
244 git init x+y &&
245 git clone "file://$PWD/x+y" xy-url-1 &&
246 git clone "file://$PWD/x%2By" xy-url-2
247 '
248
249 test_expect_success 'do not query-string-decode + in URLs' '
250 rm -rf x+y &&
251 git init "x y" &&
252 test_must_fail git clone "file://$PWD/x+y" xy-no-plus
253 '
254
255 test_expect_success 'do not respect url-encoding of non-url path' '
256 git init x+y &&
257 test_must_fail git clone x%2By xy-regular &&
258 git clone x+y xy-regular
259 '
260
261 test_expect_success 'clone separate gitdir' '
262 rm -rf dst &&
263 git clone --separate-git-dir realgitdir src dst &&
264 test -d realgitdir/refs
265 '
266
267 test_expect_success 'clone separate gitdir: output' '
268 echo "gitdir: $(pwd)/realgitdir" >expected &&
269 test_cmp expected dst/.git
270 '
271
272 test_expect_success 'clone from .git file' '
273 git clone dst/.git dst2
274 '
275
276 test_expect_success 'fetch from .git gitfile' '
277 (
278 cd dst2 &&
279 git fetch ../dst/.git
280 )
281 '
282
283 test_expect_success 'fetch from gitfile parent' '
284 (
285 cd dst2 &&
286 git fetch ../dst
287 )
288 '
289
290 test_expect_success 'clone separate gitdir where target already exists' '
291 rm -rf dst &&
292 echo foo=bar >>realgitdir/config &&
293 test_must_fail git clone --separate-git-dir realgitdir src dst &&
294 grep foo=bar realgitdir/config
295 '
296
297 test_expect_success 'clone --reference from original' '
298 git clone --shared --bare src src-1 &&
299 git clone --bare src src-2 &&
300 git clone --reference=src-2 --bare src-1 target-8 &&
301 grep /src-2/ target-8/objects/info/alternates
302 '
303
304 test_expect_success 'clone with more than one --reference' '
305 git clone --bare src src-3 &&
306 git clone --bare src src-4 &&
307 git clone --reference=src-3 --reference=src-4 src target-9 &&
308 grep /src-3/ target-9/.git/objects/info/alternates &&
309 grep /src-4/ target-9/.git/objects/info/alternates
310 '
311
312 test_expect_success 'clone from original with relative alternate' '
313 mkdir nest &&
314 git clone --bare src nest/src-5 &&
315 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
316 git clone --bare nest/src-5 target-10 &&
317 grep /src/\\.git/objects target-10/objects/info/alternates
318 '
319
320 test_expect_success 'clone checking out a tag' '
321 git clone --branch=some-tag src dst.tag &&
322 GIT_DIR=src/.git git rev-parse some-tag >expected &&
323 GIT_DIR=dst.tag/.git git rev-parse HEAD >actual &&
324 test_cmp expected actual &&
325 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
326 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
327 test_cmp fetch.expected fetch.actual
328 '
329
330 test_expect_success 'set up ssh wrapper' '
331 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \
332 "$TRASH_DIRECTORY/ssh$X" &&
333 GIT_SSH="$TRASH_DIRECTORY/ssh$X" &&
334 export GIT_SSH &&
335 export TRASH_DIRECTORY &&
336 >"$TRASH_DIRECTORY"/ssh-output
337 '
338
339 copy_ssh_wrapper_as () {
340 rm -f "${1%$X}$X" &&
341 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" &&
342 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" &&
343 GIT_SSH="${1%$X}$X" &&
344 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\""
345 }
346
347 expect_ssh () {
348 test_when_finished '
349 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
350 ' &&
351 {
352 case "$#" in
353 1)
354 ;;
355 2)
356 echo "ssh: $1 git-upload-pack '$2'"
357 ;;
358 3)
359 echo "ssh: $1 $2 git-upload-pack '$3'"
360 ;;
361 *)
362 echo "ssh: $1 $2 git-upload-pack '$3' $4"
363 esac
364 } >"$TRASH_DIRECTORY/ssh-expect" &&
365 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
366 }
367
368 test_expect_success 'clone myhost:src uses ssh' '
369 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone &&
370 expect_ssh myhost src
371 '
372
373 test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
374 cp -R src "foo:bar" &&
375 git clone "foo:bar" foobar &&
376 expect_ssh none
377 '
378
379 test_expect_success 'bracketed hostnames are still ssh' '
380 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone &&
381 expect_ssh "-p 123" myhost src
382 '
383
384 test_expect_success 'OpenSSH variant passes -4' '
385 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone &&
386 expect_ssh "-4 -p 123" myhost src
387 '
388
389 test_expect_success 'variant can be overridden' '
390 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" &&
391 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone &&
392 expect_ssh "-4 -P 123" myhost src
393 '
394
395 test_expect_success 'variant=auto picks based on basename' '
396 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
397 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone &&
398 expect_ssh "-4 -P 123" myhost src
399 '
400
401 test_expect_success 'simple does not support -4/-6' '
402 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
403 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple
404 '
405
406 test_expect_success 'simple does not support port' '
407 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" &&
408 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple
409 '
410
411 test_expect_success 'uplink is treated as simple' '
412 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" &&
413 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink &&
414 git clone "myhost:src" ssh-clone-uplink &&
415 expect_ssh myhost src
416 '
417
418 test_expect_success 'OpenSSH-like uplink is treated as ssh' '
419 write_script "$TRASH_DIRECTORY/uplink" <<-EOF &&
420 if test "\$1" = "-G"
421 then
422 exit 0
423 fi &&
424 exec "\$TRASH_DIRECTORY/ssh$X" "\$@"
425 EOF
426 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" &&
427 GIT_SSH="$TRASH_DIRECTORY/uplink" &&
428 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" &&
429 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink &&
430 expect_ssh "-p 123" myhost src
431 '
432
433 test_expect_success 'plink is treated specially (as putty)' '
434 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
435 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 &&
436 expect_ssh "-P 123" myhost src
437 '
438
439 test_expect_success 'plink.exe is treated specially (as putty)' '
440 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
441 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 &&
442 expect_ssh "-P 123" myhost src
443 '
444
445 test_expect_success 'tortoiseplink is like putty, with extra arguments' '
446 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" &&
447 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 &&
448 expect_ssh "-batch -P 123" myhost src
449 '
450
451 test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' '
452 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
453 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \
454 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 &&
455 expect_ssh "-v -P 123" myhost src
456 '
457
458 test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' '
459 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" &&
460 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \
461 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 &&
462 expect_ssh "-v -P 123" myhost src
463 '
464
465 test_expect_success 'GIT_SSH_VARIANT overrides plink detection' '
466 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
467 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \
468 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 &&
469 expect_ssh "-p 123" myhost src
470 '
471
472 test_expect_success 'ssh.variant overrides plink detection' '
473 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
474 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \
475 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 &&
476 expect_ssh "-p 123" myhost src
477 '
478
479 test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' '
480 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
481 GIT_SSH_VARIANT=plink \
482 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 &&
483 expect_ssh "-P 123" myhost src
484 '
485
486 test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' '
487 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" &&
488 GIT_SSH_VARIANT=tortoiseplink \
489 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 &&
490 expect_ssh "-batch -P 123" myhost src
491 '
492
493 test_expect_success 'clean failure on broken quoting' '
494 test_must_fail \
495 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \
496 git clone "[myhost:123]:src" sq-failure
497 '
498
499 counter=0
500 # $1 url
501 # $2 none|host
502 # $3 path
503 test_clone_url () {
504 counter=$(($counter + 1))
505 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter &&
506 shift &&
507 expect_ssh "$@"
508 }
509
510 test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' '
511 test_clone_url c:temp c temp
512 '
513
514 test_expect_success MINGW 'clone c:temp is dos drive' '
515 test_clone_url c:temp none
516 '
517
518 #ip v4
519 for repo in rep rep/home/project 123
520 do
521 test_expect_success "clone host:$repo" '
522 test_clone_url host:$repo host $repo
523 '
524 done
525
526 #ipv6
527 for repo in rep rep/home/project 123
528 do
529 test_expect_success "clone [::1]:$repo" '
530 test_clone_url [::1]:$repo ::1 "$repo"
531 '
532 done
533 #home directory
534 test_expect_success "clone host:/~repo" '
535 test_clone_url host:/~repo host "~repo"
536 '
537
538 test_expect_success "clone [::1]:/~repo" '
539 test_clone_url [::1]:/~repo ::1 "~repo"
540 '
541
542 # Corner cases
543 for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz
544 do
545 test_expect_success "clone $url is not ssh" '
546 test_clone_url $url none
547 '
548 done
549
550 #with ssh:// scheme
551 #ignore trailing colon
552 for tcol in "" :
553 do
554 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" '
555 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo
556 '
557 # from home directory
558 test_expect_success "clone ssh://host.xz$tcol/~repo" '
559 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo"
560 '
561 done
562
563 # with port number
564 test_expect_success 'clone ssh://host.xz:22/home/user/repo' '
565 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo"
566 '
567
568 # from home directory with port number
569 test_expect_success 'clone ssh://host.xz:22/~repo' '
570 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo"
571 '
572
573 #IPv6
574 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]:
575 do
576 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]")
577 test_expect_success "clone ssh://$tuah/home/user/repo" "
578 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
579 "
580 done
581
582 #IPv6 from home directory
583 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
584 do
585 euah=$(echo $tuah | tr -d "[]")
586 test_expect_success "clone ssh://$tuah/~repo" "
587 test_clone_url ssh://$tuah/~repo $euah '~repo'
588 "
589 done
590
591 #IPv6 with port number
592 for tuah in [::1] user@[::1] [user@::1]
593 do
594 euah=$(echo $tuah | tr -d "[]")
595 test_expect_success "clone ssh://$tuah:22/home/user/repo" "
596 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
597 "
598 done
599
600 #IPv6 from home directory with port number
601 for tuah in [::1] user@[::1] [user@::1]
602 do
603 euah=$(echo $tuah | tr -d "[]")
604 test_expect_success "clone ssh://$tuah:22/~repo" "
605 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
606 "
607 done
608
609 test_expect_success 'clone from a repository with two identical branches' '
610
611 (
612 cd src &&
613 git checkout -b another main
614 ) &&
615 git clone src target-11 &&
616 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another
617
618 '
619
620 test_expect_success 'shallow clone locally' '
621 git clone --depth=1 --no-local src ssrrcc &&
622 git clone ssrrcc ddsstt &&
623 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow &&
624 ( cd ddsstt && git fsck )
625 '
626
627 test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
628 rm -rf dst.git &&
629 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git &&
630 git init --bare replay.git &&
631 git -C replay.git index-pack -v --stdin <tmp.pack
632 '
633
634 test_expect_success 'clone on case-insensitive fs' '
635 git init icasefs &&
636 (
637 cd icasefs &&
638 o=$(git hash-object -w --stdin </dev/null | hex2oct) &&
639 t=$(printf "100644 X\0${o}100644 x\0${o}" |
640 git hash-object -w -t tree --stdin) &&
641 c=$(git commit-tree -m bogus $t) &&
642 git update-ref refs/heads/bogus $c &&
643 git clone -b bogus . bogus 2>warning
644 )
645 '
646
647 test_expect_success CASE_INSENSITIVE_FS 'colliding file detection' '
648 grep X icasefs/warning &&
649 grep x icasefs/warning &&
650 test_grep "the following paths have collided" icasefs/warning
651 '
652
653 test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \
654 'colliding symlink/directory keeps directory' '
655 git init icasefs-colliding-symlink &&
656 (
657 cd icasefs-colliding-symlink &&
658 a=$(printf a | git hash-object -w --stdin) &&
659 printf "100644 %s 0\tA/dir/b\n120000 %s 0\ta\n" $a $a >idx &&
660 git update-index --index-info <idx &&
661 test_tick &&
662 git commit -m initial
663 ) &&
664 git clone icasefs-colliding-symlink icasefs-colliding-symlink-clone &&
665 test_file_not_empty icasefs-colliding-symlink-clone/A/dir/b
666 '
667
668 test_expect_success 'clone with GIT_DEFAULT_HASH' '
669 (
670 sane_unset GIT_DEFAULT_HASH &&
671 git init --object-format=sha1 test-sha1 &&
672 git init --object-format=sha256 test-sha256
673 ) &&
674 test_commit -C test-sha1 foo &&
675 test_commit -C test-sha256 foo &&
676 GIT_DEFAULT_HASH=sha1 git clone test-sha256 test-clone-sha256 &&
677 GIT_DEFAULT_HASH=sha256 git clone test-sha1 test-clone-sha1 &&
678 git -C test-clone-sha1 status &&
679 git -C test-clone-sha256 status
680 '
681
682 partial_clone_server () {
683 SERVER="$1" &&
684
685 rm -rf "$SERVER" client &&
686 test_create_repo "$SERVER" &&
687 test_commit -C "$SERVER" one &&
688 HASH1=$(git -C "$SERVER" hash-object one.t) &&
689 git -C "$SERVER" revert HEAD &&
690 test_commit -C "$SERVER" two &&
691 HASH2=$(git -C "$SERVER" hash-object two.t) &&
692 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
693 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1
694 }
695
696 partial_clone () {
697 SERVER="$1" &&
698 URL="$2" &&
699
700 partial_clone_server "${SERVER}" &&
701 git clone --filter=blob:limit=0 "$URL" client &&
702
703 git -C client fsck &&
704
705 # Ensure that unneeded blobs are not inadvertently fetched.
706 test_config -C client remote.origin.promisor "false" &&
707 git -C client config --unset remote.origin.partialclonefilter &&
708 test_must_fail git -C client cat-file -e "$HASH1" &&
709
710 # But this blob was fetched, because clone performs an initial checkout
711 git -C client cat-file -e "$HASH2"
712 }
713
714 test_expect_success 'partial clone' '
715 partial_clone server "file://$(pwd)/server"
716 '
717
718 test_expect_success 'partial clone with -o' '
719 partial_clone_server server &&
720 git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
721 test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
722 '
723
724 test_expect_success 'partial clone: warn if server does not support object filtering' '
725 rm -rf server client &&
726 test_create_repo server &&
727 test_commit -C server one &&
728
729 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 2> err &&
730
731 test_grep "filtering not recognized by server" err
732 '
733
734 test_expect_success 'batch missing blob request during checkout' '
735 rm -rf server client &&
736
737 test_create_repo server &&
738 echo a >server/a &&
739 echo b >server/b &&
740 git -C server add a b &&
741
742 git -C server commit -m x &&
743 echo aa >server/a &&
744 echo bb >server/b &&
745 git -C server add a b &&
746 git -C server commit -m x &&
747
748 test_config -C server uploadpack.allowfilter 1 &&
749 test_config -C server uploadpack.allowanysha1inwant 1 &&
750
751 git clone --filter=blob:limit=0 "file://$(pwd)/server" client &&
752
753 # Ensure that there is only one negotiation by checking that there is
754 # only "done" line sent. ("done" marks the end of negotiation.)
755 GIT_TRACE_PACKET="$(pwd)/trace" \
756 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
757 git -C client -c trace2.eventNesting=5 checkout HEAD^ &&
758 grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines &&
759 test_line_count = 1 trace_lines &&
760 grep "fetch> done" trace >done_lines &&
761 test_line_count = 1 done_lines
762 '
763
764 test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' '
765 rm -rf server client &&
766
767 test_create_repo repo_for_submodule &&
768 test_commit -C repo_for_submodule x &&
769
770 test_create_repo server &&
771 echo a >server/a &&
772 echo b >server/b &&
773 git -C server add a b &&
774 git -C server commit -m x &&
775
776 echo aa >server/a &&
777 echo bb >server/b &&
778 # Also add a gitlink pointing to an arbitrary repository
779 test_config_global protocol.file.allow always &&
780 git -C server submodule add "$(pwd)/repo_for_submodule" c &&
781 git -C server add a b c &&
782 git -C server commit -m x &&
783
784 test_config -C server uploadpack.allowfilter 1 &&
785 test_config -C server uploadpack.allowanysha1inwant 1 &&
786
787 # Make sure that it succeeds
788 git clone --filter=blob:limit=0 "file://$(pwd)/server" client
789 '
790
791 test_expect_success 'clone with init.templatedir runs hooks' '
792 git init tmpl/hooks &&
793 write_script tmpl/hooks/post-checkout <<-EOF &&
794 echo HOOK-RUN >&2
795 echo I was here >hook.run
796 EOF
797 git -C tmpl/hooks add . &&
798 test_tick &&
799 git -C tmpl/hooks commit -m post-checkout &&
800
801 test_when_finished "git config --global --unset init.templateDir || :" &&
802 test_when_finished "git config --unset init.templateDir || :" &&
803 (
804 sane_unset GIT_TEMPLATE_DIR &&
805 NO_SET_GIT_TEMPLATE_DIR=t &&
806 export NO_SET_GIT_TEMPLATE_DIR &&
807
808 git -c core.hooksPath="$(pwd)/tmpl/hooks" \
809 clone tmpl/hooks hook-run-hookspath 2>err &&
810 test_grep ! "active .* hook found" err &&
811 test_path_is_file hook-run-hookspath/hook.run &&
812
813 git -c init.templateDir="$(pwd)/tmpl" \
814 clone tmpl/hooks hook-run-config 2>err &&
815 test_grep ! "active .* hook found" err &&
816 test_path_is_file hook-run-config/hook.run &&
817
818 git clone --template=tmpl tmpl/hooks hook-run-option 2>err &&
819 test_grep ! "active .* hook found" err &&
820 test_path_is_file hook-run-option/hook.run &&
821
822 git config --global init.templateDir "$(pwd)/tmpl" &&
823 git clone tmpl/hooks hook-run-global-config 2>err &&
824 git config --global --unset init.templateDir &&
825 test_grep ! "active .* hook found" err &&
826 test_path_is_file hook-run-global-config/hook.run &&
827
828 # clone ignores local `init.templateDir`; need to create
829 # a new repository because we deleted `.git/` in the
830 # `setup` test case above
831 git init local-clone &&
832 cd local-clone &&
833
834 git config init.templateDir "$(pwd)/../tmpl" &&
835 git clone ../tmpl/hooks hook-run-local-config 2>err &&
836 git config --unset init.templateDir &&
837 test_grep ! "active .* hook found" err &&
838 test_path_is_missing hook-run-local-config/hook.run
839 )
840 '
841
842 . "$TEST_DIRECTORY"/lib-httpd.sh
843 start_httpd
844
845 test_expect_success 'clone with includeIf' '
846 test_when_finished "rm -rf repo \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\"" &&
847 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
848
849 test_when_finished "rm \"$HOME\"/.gitconfig" &&
850 cat >"$HOME"/.gitconfig <<-EOF &&
851 [includeIf "onbranch:something"]
852 path = /does/not/exist.inc
853 EOF
854 git clone $HTTPD_URL/smart/repo.git repo
855 '
856
857 test_expect_success 'partial clone using HTTP' '
858 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
859 '
860
861 test_expect_success 'reject cloning shallow repository using HTTP' '
862 test_when_finished "rm -rf repo" &&
863 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
864 test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err &&
865 test_grep -e "source repository is shallow, reject to clone." err &&
866
867 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo
868 '
869
870 test_expect_success 'auto-discover bundle URI from HTTP clone' '
871 test_when_finished rm -rf trace.txt repo2 "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
872 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/everything.bundle" --all &&
873 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" &&
874
875 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
876 uploadpack.advertiseBundleURIs true &&
877 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
878 bundle.version 1 &&
879 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
880 bundle.mode all &&
881 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \
882 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
883
884 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
885 git -c protocol.version=2 \
886 -c transfer.bundleURI=true clone \
887 $HTTPD_URL/smart/repo2.git repo2 &&
888 cat >pattern <<-EOF &&
889 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
890 EOF
891 grep -f pattern trace.txt
892 '
893
894 test_expect_success 'auto-discover multiple bundles from HTTP clone' '
895 test_when_finished rm -rf trace.txt repo3 "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
896
897 test_commit -C src new &&
898 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/new.bundle" HEAD~1..HEAD &&
899 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" &&
900
901 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
902 uploadpack.advertiseBundleURIs true &&
903 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
904 bundle.version 1 &&
905 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
906 bundle.mode all &&
907
908 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
909 bundle.everything.uri "$HTTPD_URL/everything.bundle" &&
910 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \
911 bundle.new.uri "$HTTPD_URL/new.bundle" &&
912
913 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
914 git -c protocol.version=2 \
915 -c transfer.bundleURI=true clone \
916 $HTTPD_URL/smart/repo3.git repo3 &&
917
918 # We should fetch _both_ bundles
919 cat >pattern <<-EOF &&
920 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\]
921 EOF
922 grep -f pattern trace.txt &&
923 cat >pattern <<-EOF &&
924 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/new.bundle"\]
925 EOF
926 grep -f pattern trace.txt
927 '
928
929 test_expect_success 'auto-discover multiple bundles from HTTP clone: creationToken heuristic' '
930 test_when_finished rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
931 test_when_finished rm -rf clone-heuristic trace*.txt &&
932
933 test_commit -C src newest &&
934 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/newest.bundle" HEAD~1..HEAD &&
935 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" &&
936
937 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/repo4.git/config" <<-EOF &&
938 [uploadPack]
939 advertiseBundleURIs = true
940
941 [bundle]
942 version = 1
943 mode = all
944 heuristic = creationToken
945
946 [bundle "everything"]
947 uri = $HTTPD_URL/everything.bundle
948 creationtoken = 1
949
950 [bundle "new"]
951 uri = $HTTPD_URL/new.bundle
952 creationtoken = 2
953
954 [bundle "newest"]
955 uri = $HTTPD_URL/newest.bundle
956 creationtoken = 3
957 EOF
958
959 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
960 git -c protocol.version=2 \
961 -c transfer.bundleURI=true clone \
962 "$HTTPD_URL/smart/repo4.git" clone-heuristic &&
963
964 cat >expect <<-EOF &&
965 $HTTPD_URL/newest.bundle
966 $HTTPD_URL/new.bundle
967 $HTTPD_URL/everything.bundle
968 EOF
969
970 # We should fetch all bundles in the expected order.
971 test_remote_https_urls <trace-clone.txt >actual &&
972 test_cmp expect actual
973 '
974
975 # DO NOT add non-httpd-specific tests here, because the last part of this
976 # test script is only executed when httpd is available and enabled.
977
978 test_done