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