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