Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5601-clone.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5601-clone.sh` 1015 lines ยท 30086 bytes Raw Blame History 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 'output from clone with core.abbrev does not crash' ' 50 rm -fr dst && 51 echo "Cloning into ${SQ}dst${SQ}..." >expect && 52 git -c core.abbrev=12 clone -n "file://$(pwd)/src" dst >actual 2>&1 && 53 test_cmp expect actual 54 ' 55 56 test_expect_success 'clone does not keep pack' ' 57 58 rm -fr dst && 59 git clone -n "file://$(pwd)/src" dst && 60 ! test -f dst/file && 61 ! (echo dst/.git/objects/pack/pack-* | grep "\.keep") 62 63 ' 64 65 test_expect_success 'clone checks out files' ' 66 67 rm -fr dst && 68 git clone src dst && 69 test -f dst/file 70 71 ' 72 73 test_expect_success 'clone respects GIT_WORK_TREE' ' 74 75 GIT_WORK_TREE=worktree git clone src bare && 76 test -f bare/config && 77 test -f worktree/file 78 79 ' 80 81 test_expect_success 'clone from hooks' ' 82 83 test_create_repo r0 && 84 cd r0 && 85 test_commit initial && 86 cd .. && 87 git init r1 && 88 cd r1 && 89 test_hook pre-commit <<-\EOF && 90 git clone ../r0 ../r2 91 exit 1 92 EOF 93 : >file && 94 git add file && 95 test_must_fail git commit -m invoke-hook && 96 cd .. && 97 test_cmp r0/.git/HEAD r2/.git/HEAD && 98 test_cmp r0/initial.t r2/initial.t 99 100 ' 101 102 test_expect_success 'clone creates intermediate directories' ' 103 104 git clone src long/path/to/dst && 105 test -f long/path/to/dst/file 106 107 ' 108 109 test_expect_success 'clone creates intermediate directories for bare repo' ' 110 111 git clone --bare src long/path/to/bare/dst && 112 test -f long/path/to/bare/dst/config 113 114 ' 115 116 test_expect_success 'clone --mirror' ' 117 118 git clone --mirror src mirror && 119 test -f mirror/HEAD && 120 test ! -f mirror/file && 121 FETCH="$(cd mirror && git config remote.origin.fetch)" && 122 test "+refs/*:refs/*" = "$FETCH" && 123 MIRROR="$(cd mirror && git config --bool remote.origin.mirror)" && 124 test "$MIRROR" = true 125 126 ' 127 128 test_expect_success 'clone --mirror with detached HEAD' ' 129 130 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) && 131 git clone --mirror src mirror.detached && 132 ( cd src && git checkout - ) && 133 GIT_DIR=mirror.detached git rev-parse HEAD >actual && 134 test_cmp expected actual 135 136 ' 137 138 test_expect_success 'clone --bare with detached HEAD' ' 139 140 ( cd src && git checkout HEAD^ && git rev-parse HEAD >../expected ) && 141 git clone --bare src bare.detached && 142 ( cd src && git checkout - ) && 143 GIT_DIR=bare.detached git rev-parse HEAD >actual && 144 test_cmp expected actual 145 146 ' 147 148 test_expect_success 'clone --bare names the local repository .git' ' 149 150 git clone --bare src && 151 test -d src.git 152 153 ' 154 155 test_expect_success 'clone --mirror does not repeat tags' ' 156 157 (cd src && 158 git tag some-tag HEAD) && 159 git clone --mirror src mirror2 && 160 (cd mirror2 && 161 git show-ref 2> clone.err > clone.out) && 162 test_grep ! Duplicate mirror2/clone.err && 163 test_grep some-tag mirror2/clone.out 164 165 ' 166 167 test_expect_success 'clone with files ref format' ' 168 test_when_finished "rm -rf ref-storage" && 169 git clone --ref-storage-format=files --mirror src ref-storage && 170 echo files >expect && 171 git -C ref-storage rev-parse --show-ref-storage-format >actual && 172 test_cmp expect actual 173 ' 174 175 test_expect_success 'clone with garbage ref format' ' 176 cat >expect <<-EOF && 177 fatal: unknown ref storage format ${SQ}garbage${SQ} 178 EOF 179 test_must_fail git clone --ref-storage-format=garbage --mirror src ref-storage 2>err && 180 test_cmp expect err && 181 test_path_is_missing ref-storage 182 ' 183 184 test_expect_success 'clone with files object storage format' ' 185 test_when_finished "rm -rf object-storage" && 186 git clone --object-storage-format=files --bare src object-storage && 187 test_must_fail git -C object-storage config get extensions.objectstorage && 188 git -C object-storage rev-parse --show-object-storage-format >actual && 189 echo files >expect && 190 test_cmp expect actual 191 ' 192 193 test_expect_success 'clone with object storage payload' ' 194 test_when_finished "rm -rf object-storage" && 195 git clone --object-storage-format=files://objs --bare src object-storage && 196 git -C object-storage config get extensions.objectstorage >actual && 197 echo files://objs >expect && 198 test_cmp expect actual && 199 git -C object-storage rev-parse --show-object-storage-format >actual && 200 test_cmp expect actual && 201 test_path_is_dir object-storage/objs/pack && 202 test_path_is_missing object-storage/objects/pack 203 ' 204 205 test_expect_success 'clone with object storage payload and bundle URI' ' 206 test_when_finished "rm -rf object-storage src.bundle" && 207 git -C src bundle create ../src.bundle --all && 208 git clone --object-storage-format=files://objs --bundle-uri="$PWD/src.bundle" \ 209 src object-storage && 210 git -C object-storage rev-parse --show-object-storage-format >actual && 211 echo files://objs >expect && 212 test_cmp expect actual 213 ' 214 215 test_expect_success 'clone with garbage object storage format' ' 216 cat >expect <<-EOF && 217 fatal: unknown object storage format ${SQ}garbage${SQ} 218 EOF 219 test_must_fail git clone --object-storage-format=garbage --bare src object-storage 2>err && 220 test_cmp expect err && 221 test_path_is_missing object-storage 222 ' 223 224 test_expect_success 'local clone into non-default object storage bails' ' 225 test_when_finished "rm -rf object-storage" && 226 test_must_fail git clone --local --object-storage-format=files://objs src object-storage 2>err && 227 test_grep "cannot perform local clone with non-default object storage format" err 228 ' 229 230 test_expect_success 'local clone from explicit files object storage succeeds' ' 231 test_when_finished "rm -rf object-storage object-storage-dest" && 232 git clone src object-storage && 233 git -C object-storage config set core.repositoryformatversion 1 && 234 git -C object-storage config set extensions.objectstorage files && 235 git clone --local object-storage object-storage-dest 236 ' 237 238 test_expect_success 'local clone from non-default object storage bails' ' 239 test_when_finished "rm -rf object-storage object-storage-dest" && 240 git clone --object-storage-format=files://objs src object-storage && 241 test_must_fail git clone --local object-storage object-storage-dest 2>err && 242 test_grep "cannot perform local clone with non-default object storage format" err 243 ' 244 245 test_expect_success 'local clone from non-default object storage without --local warns' ' 246 test_when_finished "rm -rf object-storage object-storage-dest" && 247 git clone --object-storage-format=files://objs src object-storage && 248 git clone object-storage object-storage-dest 2>err && 249 test_grep "falling back to non-local clone" err 250 ' 251 252 test_expect_success 'clone to destination with trailing /' ' 253 254 git clone src target-1/ && 255 T=$( cd target-1 && git rev-parse HEAD ) && 256 S=$( cd src && git rev-parse HEAD ) && 257 test "$T" = "$S" 258 259 ' 260 261 test_expect_success 'clone to destination with extra trailing /' ' 262 263 git clone src target-2/// && 264 T=$( cd target-2 && git rev-parse HEAD ) && 265 S=$( cd src && git rev-parse HEAD ) && 266 test "$T" = "$S" 267 268 ' 269 270 test_expect_success 'clone to an existing empty directory' ' 271 mkdir target-3 && 272 git clone src target-3 && 273 T=$( cd target-3 && git rev-parse HEAD ) && 274 S=$( cd src && git rev-parse HEAD ) && 275 test "$T" = "$S" 276 ' 277 278 test_expect_success 'clone to an existing non-empty directory' ' 279 mkdir target-4 && 280 >target-4/Fakefile && 281 test_must_fail git clone src target-4 282 ' 283 284 test_expect_success 'clone to an existing path' ' 285 >target-5 && 286 test_must_fail git clone src target-5 287 ' 288 289 test_expect_success 'clone a void' ' 290 mkdir src-0 && 291 ( 292 cd src-0 && git init 293 ) && 294 git clone "file://$(pwd)/src-0" target-6 2>err-6 && 295 test_grep ! "fatal:" err-6 && 296 ( 297 cd src-0 && test_commit A 298 ) && 299 git clone "file://$(pwd)/src-0" target-7 2>err-7 && 300 test_grep ! "fatal:" err-7 && 301 # There is no reason to insist they are bit-for-bit 302 # identical, but this test should suffice for now. 303 test_cmp target-6/.git/config target-7/.git/config 304 ' 305 306 test_expect_success 'clone respects global branch.autosetuprebase' ' 307 ( 308 test_config="$HOME/.gitconfig" && 309 git config -f "$test_config" branch.autosetuprebase remote && 310 rm -fr dst && 311 git clone src dst && 312 cd dst && 313 actual="z$(git config branch.main.rebase)" && 314 test ztrue = $actual 315 ) 316 ' 317 318 test_expect_success 'respect url-encoding of file://' ' 319 git init x+y && 320 git clone "file://$PWD/x+y" xy-url-1 && 321 git clone "file://$PWD/x%2By" xy-url-2 322 ' 323 324 test_expect_success 'do not query-string-decode + in URLs' ' 325 rm -rf x+y && 326 git init "x y" && 327 test_must_fail git clone "file://$PWD/x+y" xy-no-plus 328 ' 329 330 test_expect_success 'do not respect url-encoding of non-url path' ' 331 git init x+y && 332 test_must_fail git clone x%2By xy-regular && 333 git clone x+y xy-regular 334 ' 335 336 test_expect_success 'clone separate gitdir' ' 337 rm -rf dst && 338 git clone --separate-git-dir realgitdir src dst && 339 test -d realgitdir/refs 340 ' 341 342 test_expect_success 'clone separate gitdir: output' ' 343 echo "gitdir: $(pwd)/realgitdir" >expected && 344 test_cmp expected dst/.git 345 ' 346 347 test_expect_success 'clone from .git file' ' 348 git clone dst/.git dst2 349 ' 350 351 test_expect_success 'fetch from .git gitfile' ' 352 ( 353 cd dst2 && 354 git fetch ../dst/.git 355 ) 356 ' 357 358 test_expect_success 'fetch from gitfile parent' ' 359 ( 360 cd dst2 && 361 git fetch ../dst 362 ) 363 ' 364 365 test_expect_success 'clone separate gitdir where target already exists' ' 366 rm -rf dst && 367 echo foo=bar >>realgitdir/config && 368 test_must_fail git clone --separate-git-dir realgitdir src dst && 369 test_grep foo=bar realgitdir/config 370 ' 371 372 test_expect_success 'clone --reference from original' ' 373 git clone --shared --bare src src-1 && 374 git clone --bare src src-2 && 375 git clone --reference=src-2 --bare src-1 target-8 && 376 test_grep /src-2/ target-8/objects/info/alternates 377 ' 378 379 test_expect_success 'clone with more than one --reference' ' 380 git clone --bare src src-3 && 381 git clone --bare src src-4 && 382 git clone --reference=src-3 --reference=src-4 src target-9 && 383 test_grep /src-3/ target-9/.git/objects/info/alternates && 384 test_grep /src-4/ target-9/.git/objects/info/alternates 385 ' 386 387 test_expect_success 'clone from original with relative alternate' ' 388 mkdir nest && 389 git clone --bare src nest/src-5 && 390 echo ../../../src/.git/objects >nest/src-5/objects/info/alternates && 391 git clone --bare nest/src-5 target-10 && 392 test_grep /src/\\.git/objects target-10/objects/info/alternates 393 ' 394 395 test_expect_success 'clone checking out a tag' ' 396 git clone --branch=some-tag src dst.tag && 397 GIT_DIR=src/.git git rev-parse some-tag >expected && 398 GIT_DIR=dst.tag/.git git rev-parse HEAD >actual && 399 test_cmp expected actual && 400 GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual && 401 echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected && 402 test_cmp fetch.expected fetch.actual 403 ' 404 405 test_expect_success 'set up ssh wrapper' ' 406 cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" \ 407 "$TRASH_DIRECTORY/ssh$X" && 408 GIT_SSH="$TRASH_DIRECTORY/ssh$X" && 409 export GIT_SSH && 410 export TRASH_DIRECTORY && 411 >"$TRASH_DIRECTORY"/ssh-output 412 ' 413 414 copy_ssh_wrapper_as () { 415 rm -f "${1%$X}$X" && 416 cp "$TRASH_DIRECTORY/ssh$X" "${1%$X}$X" && 417 test_when_finished "rm $(git rev-parse --sq-quote "${1%$X}$X")" && 418 GIT_SSH="${1%$X}$X" && 419 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" 420 } 421 422 expect_ssh () { 423 test_when_finished ' 424 (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output) 425 ' && 426 { 427 case "$#" in 428 1) 429 ;; 430 2) 431 echo "ssh: $1 git-upload-pack '$2'" 432 ;; 433 3) 434 echo "ssh: $1 $2 git-upload-pack '$3'" 435 ;; 436 *) 437 echo "ssh: $1 $2 git-upload-pack '$3' $4" 438 esac 439 } >"$TRASH_DIRECTORY/ssh-expect" && 440 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output) 441 } 442 443 test_expect_success 'clone myhost:src uses ssh' ' 444 GIT_TEST_PROTOCOL_VERSION=0 git clone myhost:src ssh-clone && 445 expect_ssh myhost src 446 ' 447 448 test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' ' 449 cp -R src "foo:bar" && 450 git clone "foo:bar" foobar && 451 expect_ssh none 452 ' 453 454 test_expect_success 'bracketed hostnames are still ssh' ' 455 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone && 456 expect_ssh "-p 123" myhost src 457 ' 458 459 test_expect_success 'OpenSSH variant passes -4' ' 460 GIT_TEST_PROTOCOL_VERSION=0 git clone -4 "[myhost:123]:src" ssh-ipv4-clone && 461 expect_ssh "-4 -p 123" myhost src 462 ' 463 464 test_expect_success 'variant can be overridden' ' 465 copy_ssh_wrapper_as "$TRASH_DIRECTORY/putty" && 466 git -c ssh.variant=putty clone -4 "[myhost:123]:src" ssh-putty-clone && 467 expect_ssh "-4 -P 123" myhost src 468 ' 469 470 test_expect_success 'variant=auto picks based on basename' ' 471 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 472 git -c ssh.variant=auto clone -4 "[myhost:123]:src" ssh-auto-clone && 473 expect_ssh "-4 -P 123" myhost src 474 ' 475 476 test_expect_success 'simple does not support -4/-6' ' 477 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && 478 test_must_fail git clone -4 "myhost:src" ssh-4-clone-simple 479 ' 480 481 test_expect_success 'simple does not support port' ' 482 copy_ssh_wrapper_as "$TRASH_DIRECTORY/simple" && 483 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-simple 484 ' 485 486 test_expect_success 'uplink is treated as simple' ' 487 copy_ssh_wrapper_as "$TRASH_DIRECTORY/uplink" && 488 test_must_fail git clone "[myhost:123]:src" ssh-bracket-clone-uplink && 489 git clone "myhost:src" ssh-clone-uplink && 490 expect_ssh myhost src 491 ' 492 493 test_expect_success 'OpenSSH-like uplink is treated as ssh' ' 494 write_script "$TRASH_DIRECTORY/uplink" <<-EOF && 495 if test "\$1" = "-G" 496 then 497 exit 0 498 fi && 499 exec "\$TRASH_DIRECTORY/ssh$X" "\$@" 500 EOF 501 test_when_finished "rm -f \"\$TRASH_DIRECTORY/uplink\"" && 502 GIT_SSH="$TRASH_DIRECTORY/uplink" && 503 test_when_finished "GIT_SSH=\"\$TRASH_DIRECTORY/ssh\$X\"" && 504 GIT_TEST_PROTOCOL_VERSION=0 git clone "[myhost:123]:src" ssh-bracket-clone-sshlike-uplink && 505 expect_ssh "-p 123" myhost src 506 ' 507 508 test_expect_success 'plink is treated specially (as putty)' ' 509 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 510 git clone "[myhost:123]:src" ssh-bracket-clone-plink-0 && 511 expect_ssh "-P 123" myhost src 512 ' 513 514 test_expect_success 'plink.exe is treated specially (as putty)' ' 515 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && 516 git clone "[myhost:123]:src" ssh-bracket-clone-plink-1 && 517 expect_ssh "-P 123" myhost src 518 ' 519 520 test_expect_success 'tortoiseplink is like putty, with extra arguments' ' 521 copy_ssh_wrapper_as "$TRASH_DIRECTORY/tortoiseplink" && 522 git clone "[myhost:123]:src" ssh-bracket-clone-plink-2 && 523 expect_ssh "-batch -P 123" myhost src 524 ' 525 526 test_expect_success 'double quoted plink.exe in GIT_SSH_COMMAND' ' 527 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && 528 GIT_SSH_COMMAND="\"$TRASH_DIRECTORY/plink.exe\" -v" \ 529 git clone "[myhost:123]:src" ssh-bracket-clone-plink-3 && 530 expect_ssh "-v -P 123" myhost src 531 ' 532 533 test_expect_success 'single quoted plink.exe in GIT_SSH_COMMAND' ' 534 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink.exe" && 535 GIT_SSH_COMMAND="$SQ$TRASH_DIRECTORY/plink.exe$SQ -v" \ 536 git clone "[myhost:123]:src" ssh-bracket-clone-plink-4 && 537 expect_ssh "-v -P 123" myhost src 538 ' 539 540 test_expect_success 'GIT_SSH_VARIANT overrides plink detection' ' 541 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 542 GIT_TEST_PROTOCOL_VERSION=0 GIT_SSH_VARIANT=ssh \ 543 git clone "[myhost:123]:src" ssh-bracket-clone-variant-1 && 544 expect_ssh "-p 123" myhost src 545 ' 546 547 test_expect_success 'ssh.variant overrides plink detection' ' 548 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 549 GIT_TEST_PROTOCOL_VERSION=0 git -c ssh.variant=ssh \ 550 clone "[myhost:123]:src" ssh-bracket-clone-variant-2 && 551 expect_ssh "-p 123" myhost src 552 ' 553 554 test_expect_success 'GIT_SSH_VARIANT overrides plink detection to plink' ' 555 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 556 GIT_SSH_VARIANT=plink \ 557 git clone "[myhost:123]:src" ssh-bracket-clone-variant-3 && 558 expect_ssh "-P 123" myhost src 559 ' 560 561 test_expect_success 'GIT_SSH_VARIANT overrides plink to tortoiseplink' ' 562 copy_ssh_wrapper_as "$TRASH_DIRECTORY/plink" && 563 GIT_SSH_VARIANT=tortoiseplink \ 564 git clone "[myhost:123]:src" ssh-bracket-clone-variant-4 && 565 expect_ssh "-batch -P 123" myhost src 566 ' 567 568 test_expect_success 'clean failure on broken quoting' ' 569 test_must_fail \ 570 env GIT_SSH_COMMAND="${SQ}plink.exe -v" \ 571 git clone "[myhost:123]:src" sq-failure 572 ' 573 574 counter=0 575 # $1 url 576 # $2 none|host 577 # $3 path 578 test_clone_url () { 579 counter=$(($counter + 1)) 580 test_might_fail env GIT_TEST_PROTOCOL_VERSION=0 git clone "$1" tmp$counter && 581 shift && 582 expect_ssh "$@" 583 } 584 585 test_expect_success !MINGW,!CYGWIN 'clone c:temp is ssl' ' 586 test_clone_url c:temp c temp 587 ' 588 589 test_expect_success MINGW 'clone c:temp is dos drive' ' 590 test_clone_url c:temp none 591 ' 592 593 #ip v4 594 for repo in rep rep/home/project 123 595 do 596 test_expect_success "clone host:$repo" ' 597 test_clone_url host:$repo host $repo 598 ' 599 done 600 601 # Parsing of paths that look like IPv6 addresses is broken on Cygwin. 602 expectation_for_ipv6_tests=success 603 if test_have_prereq CYGWIN 604 then 605 expectation_for_ipv6_tests=failure 606 fi 607 608 #ipv6 609 for repo in rep rep/home/project 123 610 do 611 test_expect_$expectation_for_ipv6_tests "clone [::1]:$repo" ' 612 test_clone_url [::1]:$repo ::1 "$repo" 613 ' 614 done 615 616 # Home directory. All tests that use "~repo" are broken in our CI job when the 617 # leak sanitizer is enabled. It seems like either a bug in the sanitizer or in 618 # glibc, but when executing getpwnam(3p) with an invalid username we eventually 619 # start recursing in a call to free(3p), until bust the stack and segfault. 620 test_expect_success !SANITIZE_LEAK "clone host:/~repo" ' 621 test_clone_url host:/~repo host "~repo" 622 ' 623 624 test_expect_$expectation_for_ipv6_tests !SANITIZE_LEAK "clone [::1]:/~repo" ' 625 test_clone_url [::1]:/~repo ::1 "~repo" 626 ' 627 628 # Corner cases 629 for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz 630 do 631 test_expect_success "clone $url is not ssh" ' 632 test_clone_url $url none 633 ' 634 done 635 636 #with ssh:// scheme 637 #ignore trailing colon 638 for tcol in "" : 639 do 640 test_expect_success "clone ssh://host.xz$tcol/home/user/repo" ' 641 test_clone_url "ssh://host.xz$tcol/home/user/repo" host.xz /home/user/repo 642 ' 643 # from home directory 644 test_expect_success !SANITIZE_LEAK "clone ssh://host.xz$tcol/~repo" ' 645 test_clone_url "ssh://host.xz$tcol/~repo" host.xz "~repo" 646 ' 647 done 648 649 # with port number 650 test_expect_success 'clone ssh://host.xz:22/home/user/repo' ' 651 test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo" 652 ' 653 654 # from home directory with port number 655 test_expect_success !SANITIZE_LEAK 'clone ssh://host.xz:22/~repo' ' 656 test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo" 657 ' 658 659 #IPv6 660 for tuah in ::1 [::1] [::1]: user@::1 user@[::1] user@[::1]: [user@::1] [user@::1]: 661 do 662 ehost=$(echo $tuah | sed -e "s/1]:/1]/" | tr -d "[]") 663 test_expect_success "clone ssh://$tuah/home/user/repo" " 664 test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo 665 " 666 done 667 668 #IPv6 from home directory 669 for tuah in ::1 [::1] user@::1 user@[::1] [user@::1] 670 do 671 euah=$(echo $tuah | tr -d "[]") 672 test_expect_success !SANITIZE_LEAK "clone ssh://$tuah/~repo" " 673 test_clone_url ssh://$tuah/~repo $euah '~repo' 674 " 675 done 676 677 #IPv6 with port number 678 for tuah in [::1] user@[::1] [user@::1] 679 do 680 euah=$(echo $tuah | tr -d "[]") 681 test_expect_success "clone ssh://$tuah:22/home/user/repo" " 682 test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo 683 " 684 done 685 686 #IPv6 from home directory with port number 687 for tuah in [::1] user@[::1] [user@::1] 688 do 689 euah=$(echo $tuah | tr -d "[]") 690 test_expect_success !SANITIZE_LEAK "clone ssh://$tuah:22/~repo" " 691 test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo' 692 " 693 done 694 695 test_expect_success 'clone from a repository with two identical branches' ' 696 697 ( 698 cd src && 699 git checkout -b another main 700 ) && 701 git clone src target-11 && 702 test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another 703 704 ' 705 706 test_expect_success 'shallow clone locally' ' 707 git clone --depth=1 --no-local src ssrrcc && 708 git clone ssrrcc ddsstt && 709 test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow && 710 ( cd ddsstt && git fsck ) 711 ' 712 713 test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' ' 714 rm -rf dst.git && 715 GIT_TRACE_PACKFILE=$PWD/tmp.pack git clone --no-local --bare src dst.git && 716 git init --bare replay.git && 717 git -C replay.git index-pack -v --stdin warning 730 ) 731 ' 732 733 test_expect_success PERL_TEST_HELPERS,CASE_INSENSITIVE_FS 'colliding file detection' ' 734 test_grep X icasefs/warning && 735 test_grep x icasefs/warning && 736 test_grep "the following paths have collided" icasefs/warning 737 ' 738 739 test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \ 740 'colliding symlink/directory keeps directory' ' 741 git init icasefs-colliding-symlink && 742 ( 743 cd icasefs-colliding-symlink && 744 a=$(printf a | git hash-object -w --stdin) && 745 printf "100644 %s 0\tA/dir/b\n120000 %s 0\ta\n" $a $a >idx && 746 git update-index --index-info err && 816 817 test_grep "filtering not recognized by server" err 818 ' 819 820 test_expect_success 'batch missing blob request during checkout' ' 821 rm -rf server client && 822 823 test_create_repo server && 824 echo a >server/a && 825 echo b >server/b && 826 git -C server add a b && 827 828 git -C server commit -m x && 829 echo aa >server/a && 830 echo bb >server/b && 831 git -C server add a b && 832 git -C server commit -m x && 833 834 test_config -C server uploadpack.allowfilter 1 && 835 test_config -C server uploadpack.allowanysha1inwant 1 && 836 837 git clone --filter=blob:limit=0 "file://$(pwd)/server" client && 838 839 # Ensure that there is only one negotiation by checking that there is 840 # only "done" line sent. ("done" marks the end of negotiation.) 841 GIT_TRACE_PACKET="$(pwd)/trace" \ 842 GIT_TRACE2_EVENT="$(pwd)/trace2_event" \ 843 git -C client -c trace2.eventNesting=5 checkout HEAD^ && 844 grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines && 845 test_line_count = 1 trace_lines && 846 grep "fetch> done" trace >done_lines && 847 test_line_count = 1 done_lines 848 ' 849 850 test_expect_success 'batch missing blob request does not inadvertently try to fetch gitlinks' ' 851 rm -rf server client && 852 853 test_create_repo repo_for_submodule && 854 test_commit -C repo_for_submodule x && 855 856 test_create_repo server && 857 echo a >server/a && 858 echo b >server/b && 859 git -C server add a b && 860 git -C server commit -m x && 861 862 echo aa >server/a && 863 echo bb >server/b && 864 # Also add a gitlink pointing to an arbitrary repository 865 test_config_global protocol.file.allow always && 866 git -C server submodule add "$(pwd)/repo_for_submodule" c && 867 git -C server add a b c && 868 git -C server commit -m x && 869 870 test_config -C server uploadpack.allowfilter 1 && 871 test_config -C server uploadpack.allowanysha1inwant 1 && 872 873 # Make sure that it succeeds 874 git clone --filter=blob:limit=0 "file://$(pwd)/server" client 875 ' 876 877 . "$TEST_DIRECTORY"/lib-httpd.sh 878 start_httpd 879 880 test_expect_success 'clone with includeIf' ' 881 test_when_finished "rm -rf repo \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\"" && 882 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && 883 884 test_when_finished "cp \"$HOME\"/.gitconfig.bak \ 885 \"$HOME\"/.gitconfig 2>/dev/null || rm -f \"$HOME\"/.gitconfig" && 886 cp "$HOME"/.gitconfig "$HOME"/.gitconfig.bak 2>/dev/null && 887 cat >"$HOME"/.gitconfig <<-EOF && 888 [includeIf "onbranch:something"] 889 path = /does/not/exist.inc 890 EOF 891 git clone $HTTPD_URL/smart/repo.git repo 892 ' 893 894 test_expect_success 'partial clone using HTTP' ' 895 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server" 896 ' 897 898 test_expect_success 'reject cloning shallow repository using HTTP' ' 899 test_when_finished "rm -rf repo" && 900 git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && 901 test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err && 902 test_grep -e "source repository is shallow, reject to clone." err && 903 904 git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo 905 ' 906 907 test_expect_success 'auto-discover bundle URI from HTTP clone' ' 908 test_when_finished rm -rf trace.txt repo2 "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" && 909 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/everything.bundle" --all && 910 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" && 911 912 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \ 913 uploadpack.advertiseBundleURIs true && 914 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \ 915 bundle.version 1 && 916 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \ 917 bundle.mode all && 918 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo2.git" config \ 919 bundle.everything.uri "$HTTPD_URL/everything.bundle" && 920 921 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ 922 git -c protocol.version=2 \ 923 -c transfer.bundleURI=true clone \ 924 $HTTPD_URL/smart/repo2.git repo2 && 925 cat >pattern <<-EOF && 926 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\] 927 EOF 928 test_grep -f pattern trace.txt 929 ' 930 931 test_expect_success 'auto-discover multiple bundles from HTTP clone' ' 932 test_when_finished rm -rf trace.txt repo3 "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" && 933 934 test_commit -C src new && 935 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/new.bundle" HEAD~1..HEAD && 936 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" && 937 938 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \ 939 uploadpack.advertiseBundleURIs true && 940 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \ 941 bundle.version 1 && 942 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \ 943 bundle.mode all && 944 945 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \ 946 bundle.everything.uri "$HTTPD_URL/everything.bundle" && 947 git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo3.git" config \ 948 bundle.new.uri "$HTTPD_URL/new.bundle" && 949 950 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ 951 git -c protocol.version=2 \ 952 -c transfer.bundleURI=true clone \ 953 $HTTPD_URL/smart/repo3.git repo3 && 954 955 # We should fetch _both_ bundles 956 cat >pattern <<-EOF && 957 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/everything.bundle"\] 958 EOF 959 test_grep -f pattern trace.txt && 960 cat >pattern <<-EOF && 961 "event":"child_start".*"argv":\["git-remote-https","$HTTPD_URL/new.bundle"\] 962 EOF 963 test_grep -f pattern trace.txt 964 ' 965 966 test_expect_success 'auto-discover multiple bundles from HTTP clone: creationToken heuristic' ' 967 test_when_finished rm -rf "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" && 968 test_when_finished rm -rf clone-heuristic trace*.txt && 969 970 test_commit -C src newest && 971 git -C src bundle create "$HTTPD_DOCUMENT_ROOT_PATH/newest.bundle" HEAD~1..HEAD && 972 git clone --bare --no-local src "$HTTPD_DOCUMENT_ROOT_PATH/repo4.git" && 973 974 cat >>"$HTTPD_DOCUMENT_ROOT_PATH/repo4.git/config" <<-EOF && 975 [uploadPack] 976 advertiseBundleURIs = true 977 978 [bundle] 979 version = 1 980 mode = all 981 heuristic = creationToken 982 983 [bundle "everything"] 984 uri = $HTTPD_URL/everything.bundle 985 creationtoken = 1 986 987 [bundle "new"] 988 uri = $HTTPD_URL/new.bundle 989 creationtoken = 2 990 991 [bundle "newest"] 992 uri = $HTTPD_URL/newest.bundle 993 creationtoken = 3 994 EOF 995 996 GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \ 997 git -c protocol.version=2 \ 998 -c transfer.bundleURI=true clone \ 999 "$HTTPD_URL/smart/repo4.git" clone-heuristic && 1000 1001 cat >expect <<-EOF && 1002 $HTTPD_URL/newest.bundle 1003 $HTTPD_URL/new.bundle 1004 $HTTPD_URL/everything.bundle 1005 EOF 1006 1007 # We should fetch all bundles in the expected order. 1008 test_remote_https_urls actual && 1009 test_cmp expect actual 1010 ' 1011 1012 # DO NOT add non-httpd-specific tests here, because the last part of this 1013 # test script is only executed when httpd is available and enabled. 1014 1015 test_done