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/t5526-fetch-submodules.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 / t5526-fetch-submodules.sh` 1262 lines ยท 37127 bytes Raw Blame History 1 #!/bin/sh 2 # Copyright (c) 2010, Jens Lehmann 3 4 test_description='Recursive "git fetch" for submodules' 5 6 . ./test-lib.sh 7 8 pwd=$(pwd) 9 10 write_expected_sub () { 11 NEW_HEAD=$1 && 12 SUPER_HEAD=$2 && 13 cat >"$pwd/expect.err.sub" <<-EOF 14 Fetching submodule submodule${SUPER_HEAD:+ at commit $SUPER_HEAD} 15 From $pwd/submodule 16 OLD_HEAD..$NEW_HEAD sub -> origin/sub 17 EOF 18 } 19 20 write_expected_sub2 () { 21 NEW_HEAD=$1 && 22 SUPER_HEAD=$2 && 23 cat >"$pwd/expect.err.sub2" <<-EOF 24 Fetching submodule submodule2${SUPER_HEAD:+ at commit $SUPER_HEAD} 25 From $pwd/submodule2 26 OLD_HEAD..$NEW_HEAD sub2 -> origin/sub2 27 EOF 28 } 29 30 write_expected_deep () { 31 NEW_HEAD=$1 && 32 SUB_HEAD=$2 && 33 cat >"$pwd/expect.err.deep" <<-EOF 34 Fetching submodule submodule/subdir/deepsubmodule${SUB_HEAD:+ at commit $SUB_HEAD} 35 From $pwd/deepsubmodule 36 OLD_HEAD..$NEW_HEAD deep -> origin/deep 37 EOF 38 } 39 40 write_expected_super () { 41 NEW_HEAD=$1 && 42 cat >"$pwd/expect.err.super" <<-EOF 43 From $pwd/. 44 OLD_HEAD..$NEW_HEAD super -> origin/super 45 EOF 46 } 47 48 # For each submodule in the test setup, this creates a commit and writes 49 # a file that contains the expected err if that new commit were fetched. 50 # These output files get concatenated in the right order by 51 # verify_fetch_result(). 52 add_submodule_commits () { 53 ( 54 cd submodule && 55 echo new >> subfile && 56 test_tick && 57 git add subfile && 58 git commit -m new subfile && 59 new_head=$(git rev-parse --short HEAD) && 60 write_expected_sub $new_head 61 ) && 62 ( 63 cd deepsubmodule && 64 echo new >> deepsubfile && 65 test_tick && 66 git add deepsubfile && 67 git commit -m new deepsubfile && 68 new_head=$(git rev-parse --short HEAD) && 69 write_expected_deep $new_head 70 ) 71 } 72 73 # For each superproject in the test setup, update its submodule, add the 74 # submodule and create a new commit with the submodule change. 75 # 76 # This requires add_submodule_commits() to be called first, otherwise 77 # the submodules will not have changed and cannot be "git add"-ed. 78 add_superproject_commits () { 79 ( 80 cd submodule && 81 ( 82 cd subdir/deepsubmodule && 83 git fetch && 84 git checkout -q FETCH_HEAD 85 ) && 86 git add subdir/deepsubmodule && 87 git commit -m "new deep submodule" 88 ) && 89 git add submodule && 90 git commit -m "new submodule" && 91 super_head=$(git rev-parse --short HEAD) && 92 sub_head=$(git -C submodule rev-parse --short HEAD) && 93 write_expected_super $super_head && 94 write_expected_sub $sub_head 95 } 96 97 # Verifies that the expected repositories were fetched. This is done by 98 # concatenating the files expect.err.[super|sub|deep] in the correct 99 # order and comparing it to the actual stderr. 100 # 101 # If a repo should not be fetched in the test, its corresponding 102 # expect.err file should be rm-ed. 103 verify_fetch_result () { 104 ACTUAL_ERR=$1 && 105 rm -f expect.err.combined && 106 if test -f expect.err.super 107 then 108 cat expect.err.super >>expect.err.combined 109 fi && 110 if test -f expect.err.sub 111 then 112 cat expect.err.sub >>expect.err.combined 113 fi && 114 if test -f expect.err.deep 115 then 116 cat expect.err.deep >>expect.err.combined 117 fi && 118 if test -f expect.err.sub2 119 then 120 cat expect.err.sub2 >>expect.err.combined 121 fi && 122 sed -e 's/[0-9a-f][0-9a-f]*\.\./OLD_HEAD\.\./' "$ACTUAL_ERR" >actual.err.cmp && 123 test_cmp expect.err.combined actual.err.cmp 124 } 125 126 test_expect_success setup ' 127 git config --global protocol.file.allow always && 128 mkdir deepsubmodule && 129 ( 130 cd deepsubmodule && 131 git init && 132 echo deepsubcontent > deepsubfile && 133 git add deepsubfile && 134 git commit -m new deepsubfile && 135 git branch -M deep 136 ) && 137 mkdir submodule && 138 ( 139 cd submodule && 140 git init && 141 echo subcontent > subfile && 142 git add subfile && 143 git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule && 144 git commit -a -m new && 145 git branch -M sub 146 ) && 147 git submodule add "$pwd/submodule" submodule && 148 git commit -am initial && 149 git branch -M super && 150 git clone . downstream && 151 ( 152 cd downstream && 153 git submodule update --init --recursive 154 ) 155 ' 156 157 test_expect_success "fetch --recurse-submodules recurses into submodules" ' 158 add_submodule_commits && 159 ( 160 cd downstream && 161 git fetch --recurse-submodules >../actual.out 2>../actual.err 162 ) && 163 test_must_be_empty actual.out && 164 verify_fetch_result actual.err 165 ' 166 167 test_expect_success "fetch --recurse-submodules honors --no-write-fetch-head" ' 168 ( 169 cd downstream && 170 git submodule foreach --recursive \ 171 sh -c "cd \"\$(git rev-parse --git-dir)\" && rm -f FETCH_HEAD" && 172 173 git fetch --recurse-submodules --no-write-fetch-head && 174 175 git submodule foreach --recursive \ 176 sh -c "cd \"\$(git rev-parse --git-dir)\" && ! test -f FETCH_HEAD" 177 ) 178 ' 179 180 test_expect_success "submodule.recurse option triggers recursive fetch" ' 181 add_submodule_commits && 182 ( 183 cd downstream && 184 git -c submodule.recurse fetch >../actual.out 2>../actual.err 185 ) && 186 test_must_be_empty actual.out && 187 verify_fetch_result actual.err 188 ' 189 190 test_expect_success "fetch --recurse-submodules -j2 has the same output behaviour" ' 191 test_when_finished "rm -f trace.out" && 192 add_submodule_commits && 193 ( 194 cd downstream && 195 GIT_TRACE="$TRASH_DIRECTORY/trace.out" git fetch --recurse-submodules -j2 2>../actual.err 196 ) && 197 test_must_be_empty actual.out && 198 verify_fetch_result actual.err && 199 test_grep "2 tasks" trace.out 200 ' 201 202 test_expect_success "fetch alone only fetches superproject" ' 203 add_submodule_commits && 204 ( 205 cd downstream && 206 git fetch >../actual.out 2>../actual.err 207 ) && 208 test_must_be_empty actual.out && 209 test_must_be_empty actual.err 210 ' 211 212 test_expect_success "fetch --no-recurse-submodules only fetches superproject" ' 213 ( 214 cd downstream && 215 git fetch --no-recurse-submodules >../actual.out 2>../actual.err 216 ) && 217 test_must_be_empty actual.out && 218 test_must_be_empty actual.err 219 ' 220 221 test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" ' 222 ( 223 cd downstream && 224 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true && 225 git fetch >../actual.out 2>../actual.err 226 ) && 227 test_must_be_empty actual.out && 228 verify_fetch_result actual.err 229 ' 230 231 test_expect_success "--no-recurse-submodules overrides .gitmodules config" ' 232 add_submodule_commits && 233 ( 234 cd downstream && 235 git fetch --no-recurse-submodules >../actual.out 2>../actual.err 236 ) && 237 test_must_be_empty actual.out && 238 test_must_be_empty actual.err 239 ' 240 241 test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" ' 242 ( 243 cd downstream && 244 git config submodule.submodule.fetchRecurseSubmodules false && 245 git fetch >../actual.out 2>../actual.err 246 ) && 247 test_must_be_empty actual.out && 248 test_must_be_empty actual.err 249 ' 250 251 test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" ' 252 ( 253 cd downstream && 254 git fetch --recurse-submodules >../actual.out 2>../actual.err && 255 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules && 256 git config --unset submodule.submodule.fetchRecurseSubmodules 257 ) && 258 test_must_be_empty actual.out && 259 verify_fetch_result actual.err 260 ' 261 262 test_expect_success "--quiet propagates to submodules" ' 263 ( 264 cd downstream && 265 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err 266 ) && 267 test_must_be_empty actual.out && 268 test_must_be_empty actual.err 269 ' 270 271 test_expect_success "--quiet propagates to parallel submodules" ' 272 ( 273 cd downstream && 274 git fetch --recurse-submodules -j 2 --quiet >../actual.out 2>../actual.err 275 ) && 276 test_must_be_empty actual.out && 277 test_must_be_empty actual.err 278 ' 279 280 test_expect_success "--dry-run propagates to submodules" ' 281 add_submodule_commits && 282 ( 283 cd downstream && 284 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err 285 ) && 286 test_must_be_empty actual.out && 287 verify_fetch_result actual.err 288 ' 289 290 test_expect_success "Without --dry-run propagates to submodules" ' 291 ( 292 cd downstream && 293 git fetch --recurse-submodules >../actual.out 2>../actual.err 294 ) && 295 test_must_be_empty actual.out && 296 verify_fetch_result actual.err 297 ' 298 299 test_expect_success "recurseSubmodules=true propagates into submodules" ' 300 add_submodule_commits && 301 ( 302 cd downstream && 303 git config fetch.recurseSubmodules true && 304 git fetch >../actual.out 2>../actual.err 305 ) && 306 test_must_be_empty actual.out && 307 verify_fetch_result actual.err 308 ' 309 310 test_expect_success "--recurse-submodules overrides config in submodule" ' 311 add_submodule_commits && 312 ( 313 cd downstream && 314 ( 315 cd submodule && 316 git config fetch.recurseSubmodules false 317 ) && 318 git fetch --recurse-submodules >../actual.out 2>../actual.err 319 ) && 320 test_must_be_empty actual.out && 321 verify_fetch_result actual.err 322 ' 323 324 test_expect_success "--no-recurse-submodules overrides config setting" ' 325 add_submodule_commits && 326 ( 327 cd downstream && 328 git config fetch.recurseSubmodules true && 329 git fetch --no-recurse-submodules >../actual.out 2>../actual.err 330 ) && 331 test_must_be_empty actual.out && 332 test_must_be_empty actual.err 333 ' 334 335 test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" ' 336 ( 337 cd downstream && 338 ( 339 cd submodule && 340 git config --unset fetch.recurseSubmodules 341 ) && 342 git config --unset fetch.recurseSubmodules && 343 git fetch >../actual.out 2>../actual.err 344 ) && 345 test_must_be_empty actual.out && 346 test_must_be_empty actual.err 347 ' 348 349 test_expect_success "Recursion stops when no new submodule commits are fetched" ' 350 git add submodule && 351 git commit -m "new submodule" && 352 new_head=$(git rev-parse --short HEAD) && 353 write_expected_super $new_head && 354 rm expect.err.deep && 355 ( 356 cd downstream && 357 git fetch >../actual.out 2>../actual.err 358 ) && 359 verify_fetch_result actual.err && 360 test_must_be_empty actual.out 361 ' 362 363 test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" ' 364 add_submodule_commits && 365 echo a > file && 366 git add file && 367 git commit -m "new file" && 368 new_head=$(git rev-parse --short HEAD) && 369 write_expected_super $new_head && 370 rm expect.err.sub && 371 rm expect.err.deep && 372 ( 373 cd downstream && 374 git fetch >../actual.out 2>../actual.err 375 ) && 376 test_must_be_empty actual.out && 377 verify_fetch_result actual.err 378 ' 379 380 test_expect_success "Recursion picks up config in submodule" ' 381 ( 382 cd downstream && 383 git fetch --recurse-submodules && 384 ( 385 cd submodule && 386 git config fetch.recurseSubmodules true 387 ) 388 ) && 389 add_submodule_commits && 390 git add submodule && 391 git commit -m "new submodule" && 392 new_head=$(git rev-parse --short HEAD) && 393 write_expected_super $new_head && 394 ( 395 cd downstream && 396 git fetch >../actual.out 2>../actual.err && 397 ( 398 cd submodule && 399 git config --unset fetch.recurseSubmodules 400 ) 401 ) && 402 verify_fetch_result actual.err && 403 test_must_be_empty actual.out 404 ' 405 406 test_expect_success "Recursion picks up all submodules when necessary" ' 407 add_submodule_commits && 408 add_superproject_commits && 409 ( 410 cd downstream && 411 git fetch >../actual.out 2>../actual.err 412 ) && 413 verify_fetch_result actual.err && 414 test_must_be_empty actual.out 415 ' 416 417 test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" ' 418 add_submodule_commits && 419 ( 420 cd downstream && 421 git config fetch.recurseSubmodules true && 422 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err && 423 git config --unset fetch.recurseSubmodules 424 ) && 425 test_must_be_empty actual.out && 426 test_must_be_empty actual.err 427 ' 428 429 test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" ' 430 add_submodule_commits && 431 add_superproject_commits && 432 ( 433 cd downstream && 434 git config fetch.recurseSubmodules false && 435 ( 436 cd submodule && 437 git config -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive false 438 ) && 439 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err && 440 git config --unset fetch.recurseSubmodules && 441 ( 442 cd submodule && 443 git config --unset -f .gitmodules submodule.subdir/deepsubmodule.fetchRecursive 444 ) 445 ) && 446 test_must_be_empty actual.out && 447 verify_fetch_result actual.err 448 ' 449 450 # These tests verify that we can fetch submodules that aren't in the 451 # index. 452 # 453 # First, test the simple case where the index is empty and we only fetch 454 # submodules that are not in the index. 455 test_expect_success 'setup downstream branch without submodules' ' 456 ( 457 cd downstream && 458 git checkout --recurse-submodules -b no-submodules && 459 git rm .gitmodules && 460 git rm submodule && 461 git commit -m "no submodules" && 462 git checkout --recurse-submodules super 463 ) 464 ' 465 466 test_expect_success "'--recurse-submodules=on-demand' should fetch submodule commits if the submodule is changed but the index has no submodules" ' 467 add_submodule_commits && 468 add_superproject_commits && 469 # Fetch the new superproject commit 470 ( 471 cd downstream && 472 git switch --recurse-submodules no-submodules && 473 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err 474 ) && 475 super_head=$(git rev-parse --short HEAD) && 476 sub_head=$(git -C submodule rev-parse --short HEAD) && 477 deep_head=$(git -C submodule/subdir/deepsubmodule rev-parse --short HEAD) && 478 479 # assert that these are fetched from commits, not the index 480 write_expected_sub $sub_head $super_head && 481 write_expected_deep $deep_head $sub_head && 482 483 test_must_be_empty actual.out && 484 verify_fetch_result actual.err 485 ' 486 487 test_expect_success "'--recurse-submodules' should fetch submodule commits if the submodule is changed but the index has no submodules" ' 488 add_submodule_commits && 489 add_superproject_commits && 490 # Fetch the new superproject commit 491 ( 492 cd downstream && 493 git switch --recurse-submodules no-submodules && 494 git fetch --recurse-submodules >../actual.out 2>../actual.err 495 ) && 496 super_head=$(git rev-parse --short HEAD) && 497 sub_head=$(git -C submodule rev-parse --short HEAD) && 498 deep_head=$(git -C submodule/subdir/deepsubmodule rev-parse --short HEAD) && 499 500 # assert that these are fetched from commits, not the index 501 write_expected_sub $sub_head $super_head && 502 write_expected_deep $deep_head $sub_head && 503 504 test_must_be_empty actual.out && 505 verify_fetch_result actual.err 506 ' 507 508 test_expect_success "'--recurse-submodules' should ignore changed, inactive submodules" ' 509 add_submodule_commits && 510 add_superproject_commits && 511 512 # Fetch the new superproject commit 513 ( 514 cd downstream && 515 git switch --recurse-submodules no-submodules && 516 git -c submodule.submodule.active=false fetch --recurse-submodules >../actual.out 2>../actual.err 517 ) && 518 test_must_be_empty actual.out && 519 super_head=$(git rev-parse --short HEAD) && 520 write_expected_super $super_head && 521 # Neither should be fetched because the submodule is inactive 522 rm expect.err.sub && 523 rm expect.err.deep && 524 verify_fetch_result actual.err 525 ' 526 527 # Now that we know we can fetch submodules that are not in the index, 528 # test that we can fetch index and non-index submodules in the same 529 # operation. 530 test_expect_success 'setup downstream branch with other submodule' ' 531 mkdir submodule2 && 532 ( 533 cd submodule2 && 534 git init && 535 echo sub2content >sub2file && 536 git add sub2file && 537 git commit -a -m new && 538 git branch -M sub2 539 ) && 540 git checkout -b super-sub2-only && 541 git submodule add "$pwd/submodule2" submodule2 && 542 git commit -m "add sub2" && 543 git checkout super && 544 ( 545 cd downstream && 546 git fetch --recurse-submodules origin && 547 git checkout super-sub2-only && 548 # Explicitly run "git submodule update" because sub2 is new 549 # and has not been cloned. 550 git submodule update --init && 551 git checkout --recurse-submodules super 552 ) 553 ' 554 555 test_expect_success "'--recurse-submodules' should fetch submodule commits in changed submodules and the index" ' 556 test_when_finished "rm expect.err.sub2" && 557 # Create new commit in origin/super 558 add_submodule_commits && 559 add_superproject_commits && 560 561 # Create new commit in origin/super-sub2-only 562 git checkout super-sub2-only && 563 ( 564 cd submodule2 && 565 test_commit --no-tag foo 566 ) && 567 git add submodule2 && 568 git commit -m "new submodule2" && 569 570 git checkout super && 571 ( 572 cd downstream && 573 git fetch --recurse-submodules >../actual.out 2>../actual.err 574 ) && 575 test_must_be_empty actual.out && 576 sub2_head=$(git -C submodule2 rev-parse --short HEAD) && 577 super_head=$(git rev-parse --short super) && 578 super_sub2_only_head=$(git rev-parse --short super-sub2-only) && 579 write_expected_sub2 $sub2_head $super_sub2_only_head && 580 581 # write_expected_super cannot handle >1 branch. Since this is a 582 # one-off, construct expect.err.super manually. 583 cat >"$pwd/expect.err.super" <<-EOF && 584 From $pwd/. 585 OLD_HEAD..$super_head super -> origin/super 586 OLD_HEAD..$super_sub2_only_head super-sub2-only -> origin/super-sub2-only 587 EOF 588 verify_fetch_result actual.err 589 ' 590 591 test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" ' 592 add_submodule_commits && 593 echo a >> file && 594 git add file && 595 git commit -m "new file" && 596 new_head=$(git rev-parse --short HEAD) && 597 write_expected_super $new_head && 598 rm expect.err.sub && 599 rm expect.err.deep && 600 ( 601 cd downstream && 602 git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err 603 ) && 604 test_must_be_empty actual.out && 605 verify_fetch_result actual.err 606 ' 607 608 test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" ' 609 ( 610 cd downstream && 611 git fetch --recurse-submodules 612 ) && 613 add_submodule_commits && 614 git config --global fetch.recurseSubmodules false && 615 git add submodule && 616 git commit -m "new submodule" && 617 new_head=$(git rev-parse --short HEAD) && 618 write_expected_super $new_head && 619 rm expect.err.deep && 620 ( 621 cd downstream && 622 git config fetch.recurseSubmodules on-demand && 623 git fetch >../actual.out 2>../actual.err 624 ) && 625 git config --global --unset fetch.recurseSubmodules && 626 ( 627 cd downstream && 628 git config --unset fetch.recurseSubmodules 629 ) && 630 test_must_be_empty actual.out && 631 verify_fetch_result actual.err 632 ' 633 634 test_expect_success "'submodule..fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" ' 635 ( 636 cd downstream && 637 git fetch --recurse-submodules 638 ) && 639 add_submodule_commits && 640 git config fetch.recurseSubmodules false && 641 git add submodule && 642 git commit -m "new submodule" && 643 new_head=$(git rev-parse --short HEAD) && 644 write_expected_super $new_head && 645 rm expect.err.deep && 646 ( 647 cd downstream && 648 git config submodule.submodule.fetchRecurseSubmodules on-demand && 649 git fetch >../actual.out 2>../actual.err 650 ) && 651 git config --unset fetch.recurseSubmodules && 652 ( 653 cd downstream && 654 git config --unset submodule.submodule.fetchRecurseSubmodules 655 ) && 656 test_must_be_empty actual.out && 657 verify_fetch_result actual.err 658 ' 659 660 test_expect_success "don't fetch submodule when newly recorded commits are already present" ' 661 ( 662 cd submodule && 663 git checkout -q HEAD^^ 664 ) && 665 git add submodule && 666 git commit -m "submodule rewound" && 667 new_head=$(git rev-parse --short HEAD) && 668 write_expected_super $new_head && 669 rm expect.err.sub && 670 # This file does not exist, but rm -f for readability 671 rm -f expect.err.deep && 672 ( 673 cd downstream && 674 git fetch >../actual.out 2>../actual.err 675 ) && 676 test_must_be_empty actual.out && 677 verify_fetch_result actual.err && 678 ( 679 cd submodule && 680 git checkout -q sub 681 ) 682 ' 683 684 test_expect_success "'fetch.recurseSubmodules=on-demand' works also without .gitmodules entry" ' 685 ( 686 cd downstream && 687 git fetch --recurse-submodules 688 ) && 689 add_submodule_commits && 690 git add submodule && 691 git rm .gitmodules && 692 git commit -m "new submodule without .gitmodules" && 693 new_head=$(git rev-parse --short HEAD) && 694 write_expected_super $new_head && 695 rm expect.err.deep && 696 ( 697 cd downstream && 698 rm .gitmodules && 699 git config fetch.recurseSubmodules on-demand && 700 # fake submodule configuration to avoid skipping submodule handling 701 git config -f .gitmodules submodule.fake.path fake && 702 git config -f .gitmodules submodule.fake.url fakeurl && 703 git add .gitmodules && 704 git config --unset submodule.submodule.url && 705 git fetch >../actual.out 2>../actual.err && 706 # cleanup 707 git config --unset fetch.recurseSubmodules && 708 git reset --hard 709 ) && 710 test_must_be_empty actual.out && 711 verify_fetch_result actual.err && 712 git checkout HEAD^ -- .gitmodules && 713 git add .gitmodules && 714 git commit -m "new submodule restored .gitmodules" 715 ' 716 717 test_expect_success 'fetching submodules respects parallel settings' ' 718 git config fetch.recurseSubmodules true && 719 test_when_finished "rm -f downstream/trace.out" && 720 ( 721 cd downstream && 722 GIT_TRACE=$(pwd)/trace.out git fetch && 723 test_grep "1 tasks" trace.out && 724 >trace.out && 725 726 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 && 727 test_grep "7 tasks" trace.out && 728 >trace.out && 729 730 git config submodule.fetchJobs 8 && 731 GIT_TRACE=$(pwd)/trace.out git fetch && 732 test_grep "8 tasks" trace.out && 733 >trace.out && 734 735 GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 && 736 test_grep "9 tasks" trace.out && 737 >trace.out && 738 739 GIT_TRACE=$(pwd)/trace.out git -c submodule.fetchJobs=0 fetch && 740 test_grep "preparing to run up to [0-9]* tasks" trace.out && 741 test_grep ! "up to 0 tasks" trace.out && 742 >trace.out 743 ) 744 ' 745 746 test_expect_success 'fetching submodule into a broken repository' ' 747 # Prepare src and src/sub nested in it 748 git init src && 749 ( 750 cd src && 751 git init sub && 752 git -C sub commit --allow-empty -m "initial in sub" && 753 git submodule add -- ./sub sub && 754 git commit -m "initial in top" 755 ) && 756 757 # Clone the old-fashoned way 758 git clone src dst && 759 git -C dst clone ../src/sub sub && 760 761 # Make sure that old-fashoned layout is still supported 762 git -C dst status && 763 764 # "diff" would find no change 765 git -C dst diff --exit-code && 766 767 # Recursive-fetch works fine 768 git -C dst fetch --recurse-submodules && 769 770 # Break the receiving submodule 771 rm -r dst/sub/.git/objects && 772 773 # NOTE: without the fix the following tests will recurse forever! 774 # They should terminate with an error. 775 776 test_must_fail git -C dst status && 777 test_must_fail git -C dst diff && 778 test_must_fail git -C dst fetch --recurse-submodules 779 ' 780 781 test_expect_success "fetch new commits when submodule got renamed" ' 782 git clone . downstream_rename && 783 ( 784 cd downstream_rename && 785 git submodule update --init --recursive && 786 git checkout -b rename && 787 git mv submodule submodule_renamed && 788 ( 789 cd submodule_renamed && 790 git checkout -b rename_sub && 791 echo a >a && 792 git add a && 793 git commit -ma && 794 git push origin rename_sub && 795 git rev-parse HEAD >../../expect 796 ) && 797 git add submodule_renamed && 798 git commit -m "update renamed submodule" && 799 git push origin rename 800 ) && 801 ( 802 cd downstream && 803 git fetch --recurse-submodules=on-demand && 804 ( 805 cd submodule && 806 git rev-parse origin/rename_sub >../../actual 807 ) 808 ) && 809 test_cmp expect actual 810 ' 811 812 test_expect_success "fetch new submodule commits on-demand outside standard refspec" ' 813 # add a second submodule and ensure it is around in downstream first 814 git clone submodule sub1 && 815 git submodule add ./sub1 && 816 git commit -m "adding a second submodule" && 817 git -C downstream pull && 818 git -C downstream submodule update --init --recursive && 819 820 git checkout --detach && 821 822 C=$(git -C submodule commit-tree -m "new change outside refs/heads" HEAD^{tree}) && 823 git -C submodule update-ref refs/changes/1 $C && 824 git update-index --cacheinfo 160000 $C submodule && 825 test_tick && 826 827 D=$(git -C sub1 commit-tree -m "new change outside refs/heads" HEAD^{tree}) && 828 git -C sub1 update-ref refs/changes/2 $D && 829 git update-index --cacheinfo 160000 $D sub1 && 830 831 git commit -m "updated submodules outside of refs/heads" && 832 E=$(git rev-parse HEAD) && 833 git update-ref refs/changes/3 $E && 834 FETCH_TRACE="$(pwd)/trace.out" && 835 test_when_finished "rm -f \"$FETCH_TRACE\"" && 836 ( 837 cd downstream && 838 GIT_TRACE="$FETCH_TRACE" git fetch --recurse-submodules origin \ 839 refs/changes/3:refs/heads/my_branch && 840 git -C submodule cat-file -t $C && 841 git -C sub1 cat-file -t $D && 842 test_grep "trace: built-in: git submodule--helper get-default-remote sub1" \ 843 "$FETCH_TRACE" && 844 test_grep "trace: built-in: git fetch .* --submodule-prefix=sub1/ origin" \ 845 "$FETCH_TRACE" && 846 git checkout --recurse-submodules FETCH_HEAD 847 ) 848 ' 849 850 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD' ' 851 # depends on the previous test for setup 852 853 C=$(git -C submodule commit-tree -m "another change outside refs/heads" HEAD^{tree}) && 854 git -C submodule update-ref refs/changes/4 $C && 855 git update-index --cacheinfo 160000 $C submodule && 856 test_tick && 857 858 D=$(git -C sub1 commit-tree -m "another change outside refs/heads" HEAD^{tree}) && 859 git -C sub1 update-ref refs/changes/5 $D && 860 git update-index --cacheinfo 160000 $D sub1 && 861 862 git commit -m "updated submodules outside of refs/heads" && 863 E=$(git rev-parse HEAD) && 864 git update-ref refs/changes/6 $E && 865 ( 866 cd downstream && 867 git fetch --recurse-submodules origin refs/changes/6 && 868 git -C submodule cat-file -t $C && 869 git -C sub1 cat-file -t $D && 870 git checkout --recurse-submodules FETCH_HEAD 871 ) 872 ' 873 874 test_expect_success 'fetch new submodule commits on-demand without .gitmodules entry' ' 875 # depends on the previous test for setup 876 877 git config -f .gitmodules --remove-section submodule.sub1 && 878 git add .gitmodules && 879 git commit -m "delete gitmodules file" && 880 git checkout -B super && 881 git -C downstream fetch && 882 git -C downstream checkout origin/super && 883 884 C=$(git -C submodule commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) && 885 git -C submodule update-ref refs/changes/7 $C && 886 git update-index --cacheinfo 160000 $C submodule && 887 test_tick && 888 889 D=$(git -C sub1 commit-tree -m "yet another change outside refs/heads" HEAD^{tree}) && 890 git -C sub1 update-ref refs/changes/8 $D && 891 git update-index --cacheinfo 160000 $D sub1 && 892 893 git commit -m "updated submodules outside of refs/heads" && 894 E=$(git rev-parse HEAD) && 895 git update-ref refs/changes/9 $E && 896 ( 897 cd downstream && 898 git fetch --recurse-submodules origin refs/changes/9 && 899 git -C submodule cat-file -t $C && 900 git -C sub1 cat-file -t $D && 901 git checkout --recurse-submodules FETCH_HEAD 902 ) 903 ' 904 905 test_expect_success 'fetch new submodule commit intermittently referenced by superproject' ' 906 # depends on the previous test for setup 907 908 D=$(git -C sub1 commit-tree -m "change 10 outside refs/heads" HEAD^{tree}) && 909 E=$(git -C sub1 commit-tree -m "change 11 outside refs/heads" HEAD^{tree}) && 910 F=$(git -C sub1 commit-tree -m "change 12 outside refs/heads" HEAD^{tree}) && 911 912 git -C sub1 update-ref refs/changes/10 $D && 913 git update-index --cacheinfo 160000 $D sub1 && 914 git commit -m "updated submodules outside of refs/heads" && 915 916 git -C sub1 update-ref refs/changes/11 $E && 917 git update-index --cacheinfo 160000 $E sub1 && 918 git commit -m "updated submodules outside of refs/heads" && 919 920 git -C sub1 update-ref refs/changes/12 $F && 921 git update-index --cacheinfo 160000 $F sub1 && 922 git commit -m "updated submodules outside of refs/heads" && 923 924 G=$(git rev-parse HEAD) && 925 git update-ref refs/changes/13 $G && 926 ( 927 cd downstream && 928 git fetch --recurse-submodules origin refs/changes/13 && 929 930 git -C sub1 cat-file -t $D && 931 git -C sub1 cat-file -t $E && 932 git -C sub1 cat-file -t $F 933 ) 934 ' 935 936 test_expect_success 'fetch new submodule commits on-demand outside standard refspec with custom remote name' ' 937 # depends on the previous test for setup 938 939 # Rename the remote in sub1 from "origin" to "custom_remote" 940 git -C downstream/sub1 remote rename origin custom_remote && 941 942 # Create new commits in the original submodules 943 C=$(git -C submodule commit-tree \ 944 -m "change outside refs/heads for custom remote" HEAD^{tree}) && 945 git -C submodule update-ref refs/changes/custom1 $C && 946 git update-index --cacheinfo 160000 $C submodule && 947 test_tick && 948 949 D=$(git -C sub1 commit-tree \ 950 -m "change outside refs/heads for custom remote" HEAD^{tree}) && 951 git -C sub1 update-ref refs/changes/custom2 $D && 952 git update-index --cacheinfo 160000 $D sub1 && 953 954 git commit \ 955 -m "updated submodules outside of refs/heads for custom remote" && 956 E=$(git rev-parse HEAD) && 957 git update-ref refs/changes/custom3 $E && 958 FETCH_TRACE="$(pwd)/trace.out" && 959 test_when_finished "rm -f \"$FETCH_TRACE\"" && 960 ( 961 cd downstream && 962 GIT_TRACE="$FETCH_TRACE" git fetch --recurse-submodules origin \ 963 refs/changes/custom3:refs/heads/my_other_branch && 964 git -C submodule cat-file -t $C && 965 git -C sub1 cat-file -t $D && 966 test_grep "trace: built-in: git submodule--helper get-default-remote sub1" \ 967 "$FETCH_TRACE" && 968 test_grep "trace: built-in: git fetch .* --submodule-prefix=sub1/ custom_remote $D" \ 969 "$FETCH_TRACE" && 970 git checkout --recurse-submodules FETCH_HEAD 971 ) 972 ' 973 974 test_expect_success 'fetch new submodule commit on-demand in FETCH_HEAD from custom remote' ' 975 # depends on the previous test for setup 976 977 C=$(git -C submodule commit-tree -m "another change outside refs/heads for custom remote" HEAD^{tree}) && 978 git -C submodule update-ref refs/changes/custom4 $C && 979 git update-index --cacheinfo 160000 $C submodule && 980 test_tick && 981 982 D=$(git -C sub1 commit-tree -m "another change outside refs/heads for custom remote" HEAD^{tree}) && 983 git -C sub1 update-ref refs/changes/custom5 $D && 984 git update-index --cacheinfo 160000 $D sub1 && 985 986 git commit -m "updated submodules outside of refs/heads" && 987 E=$(git rev-parse HEAD) && 988 git update-ref refs/changes/custom6 $E && 989 ( 990 cd downstream && 991 git fetch --recurse-submodules origin refs/changes/custom6 && 992 git -C submodule cat-file -t $C && 993 git -C sub1 cat-file -t $D && 994 git checkout --recurse-submodules FETCH_HEAD 995 ) 996 ' 997 998 add_commit_push () { 999 dir="$1" && 1000 msg="$2" && 1001 shift 2 && 1002 git -C "$dir" add "$@" && 1003 git -C "$dir" commit -a -m "$msg" && 1004 git -C "$dir" push 1005 } 1006 1007 compare_refs_in_dir () { 1008 fail= && 1009 if test "x$1" = 'x!' 1010 then 1011 fail='!' && 1012 shift 1013 fi && 1014 git -C "$1" rev-parse --verify "$2" >expect && 1015 git -C "$3" rev-parse --verify "$4" >actual && 1016 eval $fail test_cmp expect actual 1017 } 1018 1019 1020 test_expect_success 'setup nested submodule fetch test' ' 1021 # does not depend on any previous test setups 1022 1023 for repo in outer middle inner 1024 do 1025 git init --bare $repo && 1026 git clone $repo ${repo}_content && 1027 echo "$repo" >"${repo}_content/file" && 1028 add_commit_push ${repo}_content "initial" file || 1029 return 1 1030 done && 1031 1032 git clone outer A && 1033 git -C A submodule add "$pwd/middle" && 1034 git -C A/middle/ submodule add "$pwd/inner" && 1035 add_commit_push A/middle/ "adding inner sub" .gitmodules inner && 1036 add_commit_push A/ "adding middle sub" .gitmodules middle && 1037 1038 git clone outer B && 1039 git -C B/ submodule update --init middle && 1040 1041 compare_refs_in_dir A HEAD B HEAD && 1042 compare_refs_in_dir A/middle HEAD B/middle HEAD && 1043 test_path_is_file B/file && 1044 test_path_is_file B/middle/file && 1045 test_path_is_missing B/middle/inner/file && 1046 1047 echo "change on inner repo of A" >"A/middle/inner/file" && 1048 add_commit_push A/middle/inner "change on inner" file && 1049 add_commit_push A/middle "change on inner" inner && 1050 add_commit_push A "change on inner" middle 1051 ' 1052 1053 test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' ' 1054 # depends on previous test for setup 1055 1056 git -C B/ fetch && 1057 compare_refs_in_dir A origin/HEAD B origin/HEAD 1058 ' 1059 1060 fetch_with_recursion_abort () { 1061 # In a regression the following git call will run into infinite recursion. 1062 # To handle that, we connect the sed command to the git call by a pipe 1063 # so that sed can kill the infinite recursion when detected. 1064 # The recursion creates git output like: 1065 # Fetching submodule sub 1066 # Fetching submodule sub/sub <-- [1] 1067 # Fetching submodule sub/sub/sub 1068 # ... 1069 # [1] sed will stop reading and cause git to eventually stop and die 1070 1071 git -C "$1" fetch --recurse-submodules 2>&1 | 1072 sed "/Fetching submodule $2[^$]/q" >out && 1073 ! grep "Fetching submodule $2[^$]" out 1074 } 1075 1076 test_expect_success 'setup recursive fetch with uninit submodule' ' 1077 # does not depend on any previous test setups 1078 1079 test_create_repo super && 1080 test_commit -C super initial && 1081 test_create_repo sub && 1082 test_commit -C sub initial && 1083 git -C sub rev-parse HEAD >expect && 1084 1085 git -C super submodule add ../sub && 1086 git -C super commit -m "add sub" && 1087 1088 git clone super superclone && 1089 git -C superclone submodule status >out && 1090 sed -e "s/^-//" -e "s/ sub.*$//" out >actual && 1091 test_cmp expect actual 1092 ' 1093 1094 test_expect_success 'recursive fetch with uninit submodule' ' 1095 # depends on previous test for setup 1096 1097 fetch_with_recursion_abort superclone sub && 1098 git -C superclone submodule status >out && 1099 sed -e "s/^-//" -e "s/ sub$//" out >actual && 1100 test_cmp expect actual 1101 ' 1102 1103 test_expect_success 'recursive fetch after deinit a submodule' ' 1104 # depends on previous test for setup 1105 1106 git -C superclone submodule update --init sub && 1107 git -C superclone submodule deinit -f sub && 1108 1109 fetch_with_recursion_abort superclone sub && 1110 git -C superclone submodule status >out && 1111 sed -e "s/^-//" -e "s/ sub$//" out >actual && 1112 test_cmp expect actual 1113 ' 1114 1115 test_expect_success 'setup repo with upstreams that share a submodule name' ' 1116 mkdir same-name-1 && 1117 ( 1118 cd same-name-1 && 1119 git init -b main && 1120 test_commit --no-tag a 1121 ) && 1122 git clone same-name-1 same-name-2 && 1123 # same-name-1 and same-name-2 both add a submodule with the 1124 # name "submodule" 1125 ( 1126 cd same-name-1 && 1127 mkdir submodule && 1128 git -C submodule init -b main && 1129 test_commit -C submodule --no-tag a1 && 1130 git submodule add "$pwd/same-name-1/submodule" && 1131 git add submodule && 1132 git commit -m "super-a1" 1133 ) && 1134 ( 1135 cd same-name-2 && 1136 mkdir submodule && 1137 git -C submodule init -b main && 1138 test_commit -C submodule --no-tag a2 && 1139 git submodule add "$pwd/same-name-2/submodule" && 1140 git add submodule && 1141 git commit -m "super-a2" 1142 ) && 1143 git clone same-name-1 -o same-name-1 same-name-downstream && 1144 ( 1145 cd same-name-downstream && 1146 git remote add same-name-2 ../same-name-2 && 1147 git fetch --all && 1148 # init downstream with same-name-1 1149 git submodule update --init 1150 ) 1151 ' 1152 1153 test_expect_success 'fetch --recurse-submodules updates name-conflicted, populated submodule' ' 1154 test_when_finished "git -C same-name-downstream checkout main" && 1155 ( 1156 cd same-name-1 && 1157 test_commit -C submodule --no-tag b1 && 1158 git add submodule && 1159 git commit -m "super-b1" 1160 ) && 1161 ( 1162 cd same-name-2 && 1163 test_commit -C submodule --no-tag b2 && 1164 git add submodule && 1165 git commit -m "super-b2" 1166 ) && 1167 ( 1168 cd same-name-downstream && 1169 # even though the .gitmodules is correct, we cannot 1170 # fetch from same-name-2 1171 git checkout same-name-2/main && 1172 git fetch --recurse-submodules same-name-1 && 1173 test_must_fail git fetch --recurse-submodules same-name-2 1174 ) && 1175 super_head1=$(git -C same-name-1 rev-parse HEAD) && 1176 git -C same-name-downstream cat-file -e $super_head1 && 1177 1178 super_head2=$(git -C same-name-2 rev-parse HEAD) && 1179 git -C same-name-downstream cat-file -e $super_head2 && 1180 1181 sub_head1=$(git -C same-name-1/submodule rev-parse HEAD) && 1182 git -C same-name-downstream/submodule cat-file -e $sub_head1 && 1183 1184 sub_head2=$(git -C same-name-2/submodule rev-parse HEAD) && 1185 test_must_fail git -C same-name-downstream/submodule cat-file -e $sub_head2 1186 ' 1187 1188 test_expect_success 'fetch --recurse-submodules updates name-conflicted, unpopulated submodule' ' 1189 ( 1190 cd same-name-1 && 1191 test_commit -C submodule --no-tag c1 && 1192 git add submodule && 1193 git commit -m "super-c1" 1194 ) && 1195 ( 1196 cd same-name-2 && 1197 test_commit -C submodule --no-tag c2 && 1198 git add submodule && 1199 git commit -m "super-c2" 1200 ) && 1201 ( 1202 cd same-name-downstream && 1203 git checkout main && 1204 git rm .gitmodules && 1205 git rm submodule && 1206 git commit -m "no submodules" && 1207 git fetch --recurse-submodules same-name-1 1208 ) && 1209 head1=$(git -C same-name-1/submodule rev-parse HEAD) && 1210 head2=$(git -C same-name-2/submodule rev-parse HEAD) && 1211 ( 1212 cd same-name-downstream/.git/modules/submodule && 1213 # The submodule has core.worktree pointing to the "git 1214 # rm"-ed directory, overwrite the invalid value. See 1215 # comment in get_fetch_task_from_changed() for more 1216 # information. 1217 git --work-tree=. cat-file -e $head1 && 1218 test_must_fail git --work-tree=. cat-file -e $head2 1219 ) 1220 ' 1221 1222 test_expect_success 'fetch --all with --recurse-submodules' ' 1223 test_when_finished "rm -fr src_clone" && 1224 git clone --recurse-submodules src src_clone && 1225 ( 1226 cd src_clone && 1227 git config submodule.recurse true && 1228 git config fetch.parallel 0 && 1229 git fetch --all 2>../fetch-log 1230 ) && 1231 grep "^Fetching submodule sub$" fetch-log >fetch-subs && 1232 test_line_count = 1 fetch-subs 1233 ' 1234 1235 test_expect_success 'fetch --all with --recurse-submodules with multiple' ' 1236 test_when_finished "rm -fr src_clone" && 1237 git clone --recurse-submodules src src_clone && 1238 ( 1239 cd src_clone && 1240 git remote add secondary ../src && 1241 git config submodule.recurse true && 1242 git config fetch.parallel 0 && 1243 git fetch --all 2>../fetch-log 1244 ) && 1245 grep "Fetching submodule sub" fetch-log >fetch-subs && 1246 test_line_count = 2 fetch-subs 1247 ' 1248 1249 test_expect_success "fetch --all with --no-recurse-submodules only fetches superproject" ' 1250 test_when_finished "rm -rf src_clone" && 1251 1252 git clone --recurse-submodules src src_clone && 1253 ( 1254 cd src_clone && 1255 git remote add secondary ../src && 1256 git config submodule.recurse true && 1257 git fetch --all --no-recurse-submodules 2>../fetch-log 1258 ) && 1259 test_grep ! "Fetching submodule" fetch-log 1260 ' 1261 1262 test_done