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