Git fork
at reftables-rust 1319 lines 37 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2009 Red Hat, Inc. 4# 5 6test_description='Test updating submodules 7 8This test verifies that "git submodule update" detaches the HEAD of the 9submodule and "git submodule update --rebase/--merge" does not detach the HEAD. 10' 11 12GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 13export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 14 15. ./test-lib.sh 16 17 18compare_head() 19{ 20 sha_main=$(git rev-list --max-count=1 main) 21 sha_head=$(git rev-list --max-count=1 HEAD) 22 23 test "$sha_main" = "$sha_head" 24} 25 26 27test_expect_success 'setup a submodule tree' ' 28 git config --global protocol.file.allow always && 29 echo file > file && 30 git add file && 31 test_tick && 32 git commit -m upstream && 33 git clone . super && 34 git clone super submodule && 35 git clone super rebasing && 36 git clone super merging && 37 git clone super none && 38 (cd super && 39 git submodule add ../submodule submodule && 40 test_tick && 41 git commit -m "submodule" && 42 git submodule init submodule 43 ) && 44 (cd submodule && 45 echo "line2" > file && 46 git add file && 47 git commit -m "Commit 2" 48 ) && 49 (cd super && 50 (cd submodule && 51 git pull --rebase origin 52 ) && 53 git add submodule && 54 git commit -m "submodule update" 55 ) && 56 (cd super && 57 git submodule add ../rebasing rebasing && 58 test_tick && 59 git commit -m "rebasing" 60 ) && 61 (cd super && 62 git submodule add ../merging merging && 63 test_tick && 64 git commit -m "rebasing" 65 ) && 66 (cd super && 67 git submodule add ../none none && 68 test_tick && 69 git commit -m "none" 70 ) && 71 git clone . recursivesuper && 72 ( cd recursivesuper && 73 git submodule add ../super super 74 ) 75' 76 77test_expect_success 'update --remote falls back to using HEAD' ' 78 test_create_repo main-branch-submodule && 79 test_commit -C main-branch-submodule initial && 80 81 test_create_repo main-branch && 82 git -C main-branch submodule add ../main-branch-submodule && 83 git -C main-branch commit -m add-submodule && 84 85 git -C main-branch-submodule switch -c hello && 86 test_commit -C main-branch-submodule world && 87 88 git clone --recursive main-branch main-branch-clone && 89 git -C main-branch-clone submodule update --remote main-branch-submodule && 90 test_path_exists main-branch-clone/main-branch-submodule/world.t 91' 92 93test_expect_success 'submodule update detaching the HEAD ' ' 94 (cd super/submodule && 95 git reset --hard HEAD~1 96 ) && 97 (cd super && 98 (cd submodule && 99 compare_head 100 ) && 101 git submodule update submodule && 102 cd submodule && 103 ! compare_head 104 ) 105' 106 107test_expect_success 'submodule update from subdirectory' ' 108 (cd super/submodule && 109 git reset --hard HEAD~1 110 ) && 111 mkdir super/sub && 112 (cd super/sub && 113 (cd ../submodule && 114 compare_head 115 ) && 116 git submodule update ../submodule && 117 cd ../submodule && 118 ! compare_head 119 ) 120' 121 122supersha1=$(git -C super rev-parse HEAD) 123mergingsha1=$(git -C super/merging rev-parse HEAD) 124nonesha1=$(git -C super/none rev-parse HEAD) 125rebasingsha1=$(git -C super/rebasing rev-parse HEAD) 126submodulesha1=$(git -C super/submodule rev-parse HEAD) 127pwd=$(pwd) 128 129cat <<EOF >expect 130Submodule path '../super': checked out '$supersha1' 131Submodule path '../super/merging': checked out '$mergingsha1' 132Submodule path '../super/none': checked out '$nonesha1' 133Submodule path '../super/rebasing': checked out '$rebasingsha1' 134Submodule path '../super/submodule': checked out '$submodulesha1' 135EOF 136 137cat <<EOF >expect2 138Cloning into '$pwd/recursivesuper/super/merging'... 139Cloning into '$pwd/recursivesuper/super/none'... 140Cloning into '$pwd/recursivesuper/super/rebasing'... 141Cloning into '$pwd/recursivesuper/super/submodule'... 142Submodule 'merging' ($pwd/merging) registered for path '../super/merging' 143Submodule 'none' ($pwd/none) registered for path '../super/none' 144Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing' 145Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule' 146done. 147done. 148done. 149done. 150EOF 151 152test_expect_success 'submodule update --init --recursive from subdirectory' ' 153 git -C recursivesuper/super reset --hard HEAD^ && 154 (cd recursivesuper && 155 mkdir tmp && 156 cd tmp && 157 git submodule update --init --recursive ../super >../../actual 2>../../actual2 158 ) && 159 test_cmp expect actual && 160 sort actual2 >actual2.sorted && 161 test_cmp expect2 actual2.sorted 162' 163 164cat <<EOF >expect2 165Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub' 166EOF 167 168test_expect_success 'submodule update --init from and of subdirectory' ' 169 git init withsubs && 170 (cd withsubs && 171 mkdir foo && 172 git submodule add "$(pwd)/../rebasing" foo/sub && 173 (cd foo && 174 git submodule deinit -f sub && 175 git submodule update --init sub 2>../../actual2 176 ) 177 ) && 178 test_cmp expect2 actual2 179' 180 181test_expect_success 'submodule update does not fetch already present commits' ' 182 (cd submodule && 183 echo line3 >> file && 184 git add file && 185 test_tick && 186 git commit -m "upstream line3" 187 ) && 188 (cd super/submodule && 189 head=$(git rev-parse --verify HEAD) && 190 echo "Submodule path ${SQ}submodule$SQ: checked out $SQ$head$SQ" > ../../expected && 191 git reset --hard HEAD~1 192 ) && 193 (cd super && 194 git submodule update > ../actual 2> ../actual.err 195 ) && 196 test_cmp expected actual && 197 test_must_be_empty actual.err 198' 199 200test_expect_success 'submodule update should fail due to local changes' ' 201 (cd super/submodule && 202 git reset --hard HEAD~1 && 203 echo "local change" > file 204 ) && 205 (cd super && 206 (cd submodule && 207 compare_head 208 ) && 209 test_must_fail git submodule update submodule 2>../actual.raw 210 ) && 211 sed "s/^> //" >expect <<-\EOF && 212 > error: Your local changes to the following files would be overwritten by checkout: 213 > file 214 > Please commit your changes or stash them before you switch branches. 215 > Aborting 216 > fatal: Unable to checkout OID in submodule path '\''submodule'\'' 217 EOF 218 sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" <actual.raw >actual && 219 test_cmp expect actual 220 221' 222test_expect_success 'submodule update should throw away changes with --force ' ' 223 (cd super && 224 (cd submodule && 225 compare_head 226 ) && 227 git submodule update --force submodule && 228 cd submodule && 229 ! compare_head 230 ) 231' 232 233test_expect_success 'submodule update --force forcibly checks out submodules' ' 234 (cd super && 235 (cd submodule && 236 rm -f file 237 ) && 238 git submodule update --force submodule && 239 (cd submodule && 240 test "$(git status -s file)" = "" 241 ) 242 ) 243' 244 245test_expect_success 'submodule update --remote should fetch upstream changes' ' 246 (cd submodule && 247 echo line4 >> file && 248 git add file && 249 test_tick && 250 git commit -m "upstream line4" 251 ) && 252 (cd super && 253 git submodule update --remote --force submodule && 254 cd submodule && 255 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)" 256 ) 257' 258 259test_expect_success 'submodule update --remote should fetch upstream changes with .' ' 260 ( 261 cd super && 262 git config -f .gitmodules submodule."submodule".branch "." && 263 git add .gitmodules && 264 git commit -m "submodules: update from the respective superproject branch" 265 ) && 266 ( 267 cd submodule && 268 echo line4a >> file && 269 git add file && 270 test_tick && 271 git commit -m "upstream line4a" && 272 git checkout -b test-branch && 273 test_commit on-test-branch 274 ) && 275 ( 276 cd super && 277 git submodule update --remote --force submodule && 278 git -C submodule log -1 --oneline >actual && 279 git -C ../submodule log -1 --oneline main >expect && 280 test_cmp expect actual && 281 git checkout -b test-branch && 282 git submodule update --remote --force submodule && 283 git -C submodule log -1 --oneline >actual && 284 git -C ../submodule log -1 --oneline test-branch >expect && 285 test_cmp expect actual && 286 git checkout main && 287 git branch -d test-branch && 288 git reset --hard HEAD^ 289 ) 290' 291 292test_expect_success 'local config should override .gitmodules branch' ' 293 (cd submodule && 294 git checkout test-branch && 295 echo line5 >> file && 296 git add file && 297 test_tick && 298 git commit -m "upstream line5" && 299 git checkout main 300 ) && 301 (cd super && 302 git config submodule.submodule.branch test-branch && 303 git submodule update --remote --force submodule && 304 cd submodule && 305 test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)" 306 ) 307' 308 309test_expect_success 'submodule update --rebase staying on main' ' 310 (cd super/submodule && 311 git checkout main 312 ) && 313 (cd super && 314 (cd submodule && 315 compare_head 316 ) && 317 git submodule update --rebase submodule && 318 cd submodule && 319 compare_head 320 ) 321' 322 323test_expect_success 'submodule update --merge staying on main' ' 324 (cd super/submodule && 325 git reset --hard HEAD~1 326 ) && 327 (cd super && 328 (cd submodule && 329 compare_head 330 ) && 331 git submodule update --merge submodule && 332 cd submodule && 333 compare_head 334 ) 335' 336 337test_expect_success 'submodule update - rebase in .git/config' ' 338 (cd super && 339 git config submodule.submodule.update rebase 340 ) && 341 (cd super/submodule && 342 git reset --hard HEAD~1 343 ) && 344 (cd super && 345 (cd submodule && 346 compare_head 347 ) && 348 git submodule update submodule && 349 cd submodule && 350 compare_head 351 ) 352' 353 354test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' 355 (cd super && 356 git config submodule.submodule.update checkout 357 ) && 358 (cd super/submodule && 359 git reset --hard HEAD~1 360 ) && 361 (cd super && 362 (cd submodule && 363 compare_head 364 ) && 365 git submodule update --rebase submodule && 366 cd submodule && 367 compare_head 368 ) 369' 370 371test_expect_success 'submodule update - merge in .git/config' ' 372 (cd super && 373 git config submodule.submodule.update merge 374 ) && 375 (cd super/submodule && 376 git reset --hard HEAD~1 377 ) && 378 (cd super && 379 (cd submodule && 380 compare_head 381 ) && 382 git submodule update submodule && 383 cd submodule && 384 compare_head 385 ) 386' 387 388test_expect_success 'submodule update - checkout in .git/config but --merge given' ' 389 (cd super && 390 git config submodule.submodule.update checkout 391 ) && 392 (cd super/submodule && 393 git reset --hard HEAD~1 394 ) && 395 (cd super && 396 (cd submodule && 397 compare_head 398 ) && 399 git submodule update --merge submodule && 400 cd submodule && 401 compare_head 402 ) 403' 404 405test_expect_success 'submodule update - checkout in .git/config' ' 406 (cd super && 407 git config submodule.submodule.update checkout 408 ) && 409 (cd super/submodule && 410 git reset --hard HEAD^ 411 ) && 412 (cd super && 413 (cd submodule && 414 compare_head 415 ) && 416 git submodule update submodule && 417 cd submodule && 418 ! compare_head 419 ) 420' 421 422test_expect_success 'submodule update - command in .git/config' ' 423 (cd super && 424 git config submodule.submodule.update "!git checkout" 425 ) && 426 (cd super/submodule && 427 git reset --hard HEAD^ 428 ) && 429 (cd super && 430 (cd submodule && 431 compare_head 432 ) && 433 git submodule update submodule && 434 cd submodule && 435 ! compare_head 436 ) 437' 438 439test_expect_success 'submodule update - command in .gitmodules is rejected' ' 440 test_when_finished "git -C super reset --hard HEAD^" && 441 git -C super config -f .gitmodules submodule.submodule.update "!false" && 442 git -C super commit -a -m "add command to .gitmodules file" && 443 git -C super/submodule reset --hard $submodulesha1^ && 444 test_must_fail git -C super submodule update submodule 445' 446 447test_expect_success 'fsck detects command in .gitmodules' ' 448 git init command-in-gitmodules && 449 ( 450 cd command-in-gitmodules && 451 git submodule add ../submodule submodule && 452 test_commit adding-submodule && 453 454 git config -f .gitmodules submodule.submodule.update "!false" && 455 git add .gitmodules && 456 test_commit configuring-update && 457 test_must_fail git fsck 458 ) 459' 460 461cat << EOF >expect 462fatal: Execution of 'false $submodulesha1' failed in submodule path 'submodule' 463EOF 464 465test_expect_success 'submodule update - command in .git/config catches failure' ' 466 (cd super && 467 git config submodule.submodule.update "!false" 468 ) && 469 (cd super/submodule && 470 git reset --hard $submodulesha1^ 471 ) && 472 (cd super && 473 test_must_fail git submodule update submodule 2>../actual 474 ) && 475 test_cmp actual expect 476' 477 478cat << EOF >expect 479fatal: Execution of 'false $submodulesha1' failed in submodule path '../submodule' 480EOF 481 482test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' ' 483 (cd super && 484 git config submodule.submodule.update "!false" 485 ) && 486 (cd super/submodule && 487 git reset --hard $submodulesha1^ 488 ) && 489 (cd super && 490 mkdir tmp && cd tmp && 491 test_must_fail git submodule update ../submodule 2>../../actual 492 ) && 493 test_cmp actual expect 494' 495 496test_expect_success 'submodule update - command run for initial population of submodule' ' 497 cat >expect <<-EOF && 498 fatal: Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\'' 499 EOF 500 rm -rf super/submodule && 501 test_must_fail git -C super submodule update 2>actual && 502 test_cmp expect actual && 503 git -C super submodule update --checkout 504' 505 506cat << EOF >expect 507fatal: Execution of 'false $submodulesha1' failed in submodule path '../super/submodule' 508fatal: Failed to recurse into submodule path '../super' 509EOF 510 511test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' ' 512 (cd recursivesuper && 513 git submodule update --remote super && 514 git add super && 515 git commit -m "update to latest to have more than one commit in submodules" 516 ) && 517 git -C recursivesuper/super config submodule.submodule.update "!false" && 518 git -C recursivesuper/super/submodule reset --hard $submodulesha1^ && 519 (cd recursivesuper && 520 mkdir -p tmp && cd tmp && 521 test_must_fail git submodule update --recursive ../super 2>../../actual 522 ) && 523 test_cmp actual expect 524' 525 526test_expect_success 'submodule init does not copy command into .git/config' ' 527 test_when_finished "git -C super update-index --force-remove submodule1" && 528 test_when_finished git config -f super/.gitmodules \ 529 --remove-section submodule.submodule1 && 530 (cd super && 531 git ls-files -s submodule >out && 532 H=$(cut -d" " -f2 out) && 533 mkdir submodule1 && 534 git update-index --add --cacheinfo 160000 $H submodule1 && 535 git config -f .gitmodules submodule.submodule1.path submodule1 && 536 git config -f .gitmodules submodule.submodule1.url ../submodule && 537 git config -f .gitmodules submodule.submodule1.update !false && 538 test_must_fail git submodule init submodule1 && 539 test_expect_code 1 git config submodule.submodule1.update >actual && 540 test_must_be_empty actual 541 ) 542' 543 544test_expect_success 'submodule init picks up rebase' ' 545 (cd super && 546 git config -f .gitmodules submodule.rebasing.update rebase && 547 git submodule init rebasing && 548 test "rebase" = "$(git config submodule.rebasing.update)" 549 ) 550' 551 552test_expect_success 'submodule init picks up merge' ' 553 (cd super && 554 git config -f .gitmodules submodule.merging.update merge && 555 git submodule init merging && 556 test "merge" = "$(git config submodule.merging.update)" 557 ) 558' 559 560test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' 561 test_config -C super submodule.submodule.update checkout && 562 (cd super && 563 rm -rf submodule && 564 git submodule update submodule && 565 git status -s submodule >expect && 566 rm -rf submodule && 567 git submodule update --merge submodule && 568 git status -s submodule >actual && 569 test_cmp expect actual 570 ) 571' 572 573test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' 574 test_config -C super submodule.submodule.update checkout && 575 (cd super && 576 rm -rf submodule && 577 git submodule update submodule && 578 git status -s submodule >expect && 579 rm -rf submodule && 580 git submodule update --rebase submodule && 581 git status -s submodule >actual && 582 test_cmp expect actual 583 ) 584' 585 586test_expect_success 'submodule update ignores update=merge config for new submodules' ' 587 (cd super && 588 rm -rf submodule && 589 git submodule update submodule && 590 git status -s submodule >expect && 591 rm -rf submodule && 592 git config submodule.submodule.update merge && 593 git submodule update submodule && 594 git status -s submodule >actual && 595 git config --unset submodule.submodule.update && 596 test_cmp expect actual 597 ) 598' 599 600test_expect_success 'submodule update ignores update=rebase config for new submodules' ' 601 (cd super && 602 rm -rf submodule && 603 git submodule update submodule && 604 git status -s submodule >expect && 605 rm -rf submodule && 606 git config submodule.submodule.update rebase && 607 git submodule update submodule && 608 git status -s submodule >actual && 609 git config --unset submodule.submodule.update && 610 test_cmp expect actual 611 ) 612' 613 614test_expect_success 'submodule init picks up update=none' ' 615 (cd super && 616 git config -f .gitmodules submodule.none.update none && 617 git submodule init none && 618 test "none" = "$(git config submodule.none.update)" 619 ) 620' 621 622test_expect_success 'submodule update - update=none in .git/config' ' 623 (cd super && 624 git config submodule.submodule.update none && 625 (cd submodule && 626 git checkout main && 627 compare_head 628 ) && 629 git diff --name-only >out && 630 grep ^submodule$ out && 631 git submodule update && 632 git diff --name-only >out && 633 grep ^submodule$ out && 634 (cd submodule && 635 compare_head 636 ) && 637 git config --unset submodule.submodule.update && 638 git submodule update submodule 639 ) 640' 641 642test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' 643 (cd super && 644 git config submodule.submodule.update none && 645 (cd submodule && 646 git checkout main && 647 compare_head 648 ) && 649 git diff --name-only >out && 650 grep ^submodule$ out && 651 git submodule update --checkout && 652 git diff --name-only >out && 653 ! grep ^submodule$ out && 654 (cd submodule && 655 ! compare_head 656 ) && 657 git config --unset submodule.submodule.update 658 ) 659' 660 661test_expect_success 'submodule update --init skips submodule with update=none' ' 662 (cd super && 663 git add .gitmodules && 664 git commit -m ".gitmodules" 665 ) && 666 git clone super cloned && 667 (cd cloned && 668 git submodule update --init && 669 test_path_exists submodule/.git && 670 test_path_is_missing none/.git 671 ) 672' 673 674test_expect_success 'submodule update with pathspec warns against uninitialized ones' ' 675 test_when_finished "rm -fr selective" && 676 git clone super selective && 677 ( 678 cd selective && 679 git submodule init submodule && 680 681 git submodule update submodule 2>err && 682 ! grep "Submodule path .* not initialized" err && 683 684 git submodule update rebasing 2>err && 685 grep "Submodule path .rebasing. not initialized" err && 686 687 test_path_exists submodule/.git && 688 test_path_is_missing rebasing/.git 689 ) 690 691' 692 693test_expect_success 'submodule update without pathspec updates only initialized ones' ' 694 test_when_finished "rm -fr selective" && 695 git clone super selective && 696 ( 697 cd selective && 698 git submodule init submodule && 699 git submodule update 2>err && 700 test_path_exists submodule/.git && 701 test_path_is_missing rebasing/.git && 702 ! grep "Submodule path .* not initialized" err 703 ) 704 705' 706 707test_expect_success 'submodule update continues after checkout error' ' 708 (cd super && 709 git reset --hard HEAD && 710 git submodule add ../submodule submodule2 && 711 git submodule init && 712 git commit -am "new_submodule" && 713 (cd submodule2 && 714 git rev-parse --verify HEAD >../expect 715 ) && 716 (cd submodule && 717 test_commit "update_submodule" file 718 ) && 719 (cd submodule2 && 720 test_commit "update_submodule2" file 721 ) && 722 git add submodule && 723 git add submodule2 && 724 git commit -m "two_new_submodule_commits" && 725 (cd submodule && 726 echo "" > file 727 ) && 728 git checkout HEAD^ && 729 test_must_fail git submodule update && 730 (cd submodule2 && 731 git rev-parse --verify HEAD >../actual 732 ) && 733 test_cmp expect actual 734 ) 735' 736test_expect_success 'submodule update continues after recursive checkout error' ' 737 (cd super && 738 git reset --hard HEAD && 739 git checkout main && 740 git submodule update && 741 (cd submodule && 742 git submodule add ../submodule subsubmodule && 743 git submodule init && 744 git commit -m "new_subsubmodule" 745 ) && 746 git add submodule && 747 git commit -m "update_submodule" && 748 (cd submodule && 749 (cd subsubmodule && 750 test_commit "update_subsubmodule" file 751 ) && 752 git add subsubmodule && 753 test_commit "update_submodule_again" file && 754 (cd subsubmodule && 755 test_commit "update_subsubmodule_again" file 756 ) && 757 test_commit "update_submodule_again_again" file 758 ) && 759 (cd submodule2 && 760 git rev-parse --verify HEAD >../expect && 761 test_commit "update_submodule2_again" file 762 ) && 763 git add submodule && 764 git add submodule2 && 765 git commit -m "new_commits" && 766 git checkout HEAD^ && 767 (cd submodule && 768 git checkout HEAD^ && 769 (cd subsubmodule && 770 echo "" > file 771 ) 772 ) && 773 test_expect_code 1 git submodule update --recursive && 774 (cd submodule2 && 775 git rev-parse --verify HEAD >../actual 776 ) && 777 test_cmp expect actual 778 ) 779' 780 781test_expect_success 'submodule update exit immediately in case of merge conflict' ' 782 (cd super && 783 git checkout main && 784 git reset --hard HEAD && 785 (cd submodule && 786 (cd subsubmodule && 787 git reset --hard HEAD 788 ) 789 ) && 790 git submodule update --recursive && 791 (cd submodule && 792 test_commit "update_submodule_2" file 793 ) && 794 (cd submodule2 && 795 test_commit "update_submodule2_2" file 796 ) && 797 git add submodule && 798 git add submodule2 && 799 git commit -m "two_new_submodule_commits" && 800 (cd submodule && 801 git checkout main && 802 test_commit "conflict" file && 803 echo "conflict" > file 804 ) && 805 git checkout HEAD^ && 806 (cd submodule2 && 807 git rev-parse --verify HEAD >../expect 808 ) && 809 git config submodule.submodule.update merge && 810 test_must_fail git submodule update && 811 (cd submodule2 && 812 git rev-parse --verify HEAD >../actual 813 ) && 814 test_cmp expect actual 815 ) 816' 817 818test_expect_success 'submodule update exit immediately after recursive rebase error' ' 819 (cd super && 820 git checkout main && 821 git reset --hard HEAD && 822 (cd submodule && 823 git reset --hard HEAD && 824 git submodule update --recursive 825 ) && 826 (cd submodule && 827 test_commit "update_submodule_3" file 828 ) && 829 (cd submodule2 && 830 test_commit "update_submodule2_3" file 831 ) && 832 git add submodule && 833 git add submodule2 && 834 git commit -m "two_new_submodule_commits" && 835 (cd submodule && 836 git checkout main && 837 test_commit "conflict2" file && 838 echo "conflict" > file 839 ) && 840 git checkout HEAD^ && 841 (cd submodule2 && 842 git rev-parse --verify HEAD >../expect 843 ) && 844 git config submodule.submodule.update rebase && 845 test_must_fail git submodule update && 846 (cd submodule2 && 847 git rev-parse --verify HEAD >../actual 848 ) && 849 test_cmp expect actual 850 ) 851' 852 853test_expect_success 'add different submodules to the same path' ' 854 (cd super && 855 git submodule add ../submodule s1 && 856 test_must_fail git submodule add ../merging s1 857 ) 858' 859 860test_expect_success 'submodule add places git-dir in superprojects git-dir' ' 861 (cd super && 862 mkdir deeper && 863 git submodule add ../submodule deeper/submodule && 864 (cd deeper/submodule && 865 git log > ../../expected 866 ) && 867 (cd .git/modules/deeper/submodule && 868 git log > ../../../../actual 869 ) && 870 test_cmp expected actual 871 ) 872' 873 874test_expect_success 'submodule update places git-dir in superprojects git-dir' ' 875 (cd super && 876 git commit -m "added submodule" 877 ) && 878 git clone super super2 && 879 (cd super2 && 880 git submodule init deeper/submodule && 881 git submodule update && 882 (cd deeper/submodule && 883 git log > ../../expected 884 ) && 885 (cd .git/modules/deeper/submodule && 886 git log > ../../../../actual 887 ) && 888 test_cmp expected actual 889 ) 890' 891 892test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' 893 (cd super2 && 894 (cd deeper/submodule && 895 git submodule add ../submodule subsubmodule && 896 (cd subsubmodule && 897 git log > ../../../expected 898 ) && 899 git commit -m "added subsubmodule" && 900 git push origin : 901 ) && 902 (cd .git/modules/deeper/submodule/modules/subsubmodule && 903 git log > ../../../../../actual 904 ) && 905 git add deeper/submodule && 906 git commit -m "update submodule" && 907 git push origin : && 908 test_cmp expected actual 909 ) 910' 911 912test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' 913 mkdir super_update_r && 914 (cd super_update_r && 915 git init --bare 916 ) && 917 mkdir subsuper_update_r && 918 (cd subsuper_update_r && 919 git init --bare 920 ) && 921 mkdir subsubsuper_update_r && 922 (cd subsubsuper_update_r && 923 git init --bare 924 ) && 925 git clone subsubsuper_update_r subsubsuper_update_r2 && 926 (cd subsubsuper_update_r2 && 927 test_commit "update_subsubsuper" file && 928 git push origin main 929 ) && 930 git clone subsuper_update_r subsuper_update_r2 && 931 (cd subsuper_update_r2 && 932 test_commit "update_subsuper" file && 933 git submodule add ../subsubsuper_update_r subsubmodule && 934 git commit -am "subsubmodule" && 935 git push origin main 936 ) && 937 git clone super_update_r super_update_r2 && 938 (cd super_update_r2 && 939 test_commit "update_super" file && 940 git submodule add ../subsuper_update_r submodule && 941 git commit -am "submodule" && 942 git push origin main 943 ) && 944 rm -rf super_update_r2 && 945 git clone super_update_r super_update_r2 && 946 (cd super_update_r2 && 947 git submodule update --init --recursive >actual && 948 test_grep "Submodule path .submodule/subsubmodule.: checked out" actual && 949 (cd submodule/subsubmodule && 950 git log > ../../expected 951 ) && 952 (cd .git/modules/submodule/modules/subsubmodule && 953 git log > ../../../../../actual 954 ) && 955 test_cmp expected actual 956 ) 957' 958 959test_expect_success 'submodule add properly re-creates deeper level submodules' ' 960 (cd super && 961 git reset --hard main && 962 rm -rf deeper/ && 963 git submodule add --force ../submodule deeper/submodule 964 ) 965' 966 967test_expect_success 'submodule update properly revives a moved submodule' ' 968 (cd super && 969 H=$(git rev-parse --short HEAD) && 970 git commit -am "pre move" && 971 H2=$(git rev-parse --short HEAD) && 972 git status >out && 973 sed "s/$H/XXX/" out >expect && 974 H=$(cd submodule2 && git rev-parse HEAD) && 975 git rm --cached submodule2 && 976 rm -rf submodule2 && 977 mkdir -p "moved/sub module" && 978 git update-index --add --cacheinfo 160000 $H "moved/sub module" && 979 git config -f .gitmodules submodule.submodule2.path "moved/sub module" && 980 git commit -am "post move" && 981 git submodule update && 982 git status > out && 983 sed "s/$H2/XXX/" out >actual && 984 test_cmp expect actual 985 ) 986' 987 988test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' 989 mkdir -p linked/dir && 990 ln -s linked/dir linkto && 991 (cd linkto && 992 git clone "$TRASH_DIRECTORY"/super_update_r2 super && 993 (cd super && 994 git submodule update --init --recursive 995 ) 996 ) 997' 998 999test_expect_success 'submodule update clone shallow submodule' ' 1000 test_when_finished "rm -rf super3" && 1001 first=$(git -C cloned rev-parse HEAD:submodule) && 1002 second=$(git -C submodule rev-parse HEAD) && 1003 commit_count=$(git -C submodule rev-list --count $first^..$second) && 1004 git clone cloned super3 && 1005 pwd=$(pwd) && 1006 ( 1007 cd super3 && 1008 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && 1009 mv -f .gitmodules.tmp .gitmodules && 1010 git submodule update --init --depth=$commit_count && 1011 git -C submodule log --oneline >out && 1012 test_line_count = 1 out 1013 ) 1014' 1015 1016test_expect_success 'submodule update clone shallow submodule outside of depth' ' 1017 test_when_finished "rm -rf super3" && 1018 git clone cloned super3 && 1019 pwd=$(pwd) && 1020 ( 1021 cd super3 && 1022 sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp && 1023 mv -f .gitmodules.tmp .gitmodules && 1024 # Some protocol versions (e.g. 2) support fetching 1025 # unadvertised objects, so restrict this test to v0. 1026 test_must_fail env GIT_TEST_PROTOCOL_VERSION=0 \ 1027 git submodule update --init --depth=1 2>actual && 1028 test_grep "Direct fetching of that commit failed." actual && 1029 git -C ../submodule config uploadpack.allowReachableSHA1InWant true && 1030 git submodule update --init --depth=1 >actual && 1031 git -C submodule log --oneline >out && 1032 test_line_count = 1 out 1033 ) 1034' 1035 1036test_expect_success 'submodule update --recursive drops module name before recursing' ' 1037 (cd super2 && 1038 (cd deeper/submodule/subsubmodule && 1039 git checkout HEAD^ 1040 ) && 1041 git submodule update --recursive deeper/submodule >actual && 1042 test_grep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual 1043 ) 1044' 1045 1046test_expect_success 'submodule update can be run in parallel' ' 1047 (cd super2 && 1048 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 && 1049 grep "7 tasks" trace.out && 1050 git config submodule.fetchJobs 8 && 1051 GIT_TRACE=$(pwd)/trace.out git submodule update && 1052 grep "8 tasks" trace.out && 1053 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 && 1054 grep "9 tasks" trace.out 1055 ) 1056' 1057 1058test_expect_success 'git clone passes the parallel jobs config on to submodules' ' 1059 test_when_finished "rm -rf super4" && 1060 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 && 1061 grep "7 tasks" trace.out && 1062 rm -rf super4 && 1063 git config --global submodule.fetchJobs 8 && 1064 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 && 1065 grep "8 tasks" trace.out && 1066 rm -rf super4 && 1067 GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 && 1068 grep "9 tasks" trace.out && 1069 rm -rf super4 1070' 1071 1072test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ' 1073 (cd super && 1074 test_commit -C rebasing message && 1075 git submodule update --rebase --quiet >out 2>err && 1076 test_must_be_empty out && 1077 test_must_be_empty err && 1078 git submodule update --rebase >out 2>err && 1079 test_file_not_empty out && 1080 test_must_be_empty err 1081 ) 1082' 1083 1084test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' ' 1085 test_when_finished "rm -rf super4 super5 super6" && 1086 git clone . super4 && 1087 (cd super4 && 1088 git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 && 1089 git commit -am "setup submodule3" 1090 ) && 1091 (cd submodule && 1092 test_commit line6 file 1093 ) && 1094 git clone super4 super5 && 1095 (cd super5 && 1096 # This test var can mess with the stderr output checked in this test. 1097 GIT_TEST_NAME_HASH_VERSION=1 \ 1098 GIT_TEST_PACK_PATH_WALK=0 \ 1099 git submodule update --quiet --init --depth=1 submodule3 >out 2>err && 1100 test_must_be_empty out && 1101 test_must_be_empty err 1102 ) && 1103 git clone super4 super6 && 1104 (cd super6 && 1105 # This test variable will create a "warning" message to stderr 1106 GIT_TEST_PACK_PATH_WALK=0 \ 1107 git submodule update --init --depth=1 submodule3 >out 2>err && 1108 test_file_not_empty out && 1109 test_file_not_empty err 1110 ) 1111' 1112 1113test_expect_success 'submodule update --filter requires --init' ' 1114 test_expect_code 129 git -C super submodule update --filter blob:none 1115' 1116 1117test_expect_success 'submodule update --filter sets partial clone settings' ' 1118 test_when_finished "rm -rf super-filter" && 1119 git clone cloned super-filter && 1120 git -C super-filter submodule update --init --filter blob:none && 1121 test_cmp_config -C super-filter/submodule true remote.origin.promisor && 1122 test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter 1123' 1124 1125# NEEDSWORK: Clean up the tests so that we can reuse the test setup. 1126# Don't reuse the existing repos because the earlier tests have 1127# intentionally disruptive configurations. 1128test_expect_success 'setup clean recursive superproject' ' 1129 git init bottom && 1130 test_commit -C bottom "bottom" && 1131 git init middle && 1132 git -C middle submodule add ../bottom bottom && 1133 git -C middle commit -m "middle" && 1134 git init top && 1135 git -C top submodule add ../middle middle && 1136 git -C top commit -m "top" && 1137 git clone --recurse-submodules top top-clean 1138' 1139 1140test_expect_success 'submodule update with multiple remotes' ' 1141 test_when_finished "rm -fr top-cloned" && 1142 cp -r top-clean top-cloned && 1143 1144 # Create a commit in each repo, starting with bottom 1145 test_commit -C bottom multiple_remote_commit && 1146 # Create middle commit 1147 git -C middle/bottom fetch && 1148 git -C middle/bottom checkout -f FETCH_HEAD && 1149 git -C middle add bottom && 1150 git -C middle commit -m "multiple_remote_commit" && 1151 # Create top commit 1152 git -C top/middle fetch && 1153 git -C top/middle checkout -f FETCH_HEAD && 1154 git -C top add middle && 1155 git -C top commit -m "multiple_remote_commit" && 1156 1157 # rename the submodule remote 1158 git -C top-cloned/middle remote rename origin upstream && 1159 1160 # Add another remote 1161 git -C top-cloned/middle remote add other bogus && 1162 1163 # Make the update of "middle" a no-op, otherwise we error out 1164 # because of its unmerged state 1165 test_config -C top-cloned submodule.middle.update !true && 1166 git -C top-cloned submodule update --recursive 2>actual.err && 1167 cat >expect.err <<-\EOF && 1168 EOF 1169 test_cmp expect.err actual.err 1170' 1171 1172test_expect_success 'submodule update with renamed remote' ' 1173 test_when_finished "rm -fr top-cloned" && 1174 cp -r top-clean top-cloned && 1175 1176 # Create a commit in each repo, starting with bottom 1177 test_commit -C bottom rename_commit && 1178 # Create middle commit 1179 git -C middle/bottom fetch && 1180 git -C middle/bottom checkout -f FETCH_HEAD && 1181 git -C middle add bottom && 1182 git -C middle commit -m "rename_commit" && 1183 # Create top commit 1184 git -C top/middle fetch && 1185 git -C top/middle checkout -f FETCH_HEAD && 1186 git -C top add middle && 1187 git -C top commit -m "rename_commit" && 1188 1189 # rename the submodule remote 1190 git -C top-cloned/middle remote rename origin upstream && 1191 1192 # Make the update of "middle" a no-op, otherwise we error out 1193 # because of its unmerged state 1194 test_config -C top-cloned submodule.middle.update !true && 1195 git -C top-cloned submodule update --recursive 2>actual.err && 1196 cat >expect.err <<-\EOF && 1197 EOF 1198 test_cmp expect.err actual.err 1199' 1200 1201test_expect_success 'submodule update should skip unmerged submodules' ' 1202 test_when_finished "rm -fr top-cloned" && 1203 cp -r top-clean top-cloned && 1204 1205 # Create an upstream commit in each repo, starting with bottom 1206 test_commit -C bottom upstream_commit && 1207 # Create middle commit 1208 git -C middle/bottom fetch && 1209 git -C middle/bottom checkout -f FETCH_HEAD && 1210 git -C middle add bottom && 1211 git -C middle commit -m "upstream_commit" && 1212 # Create top commit 1213 git -C top/middle fetch && 1214 git -C top/middle checkout -f FETCH_HEAD && 1215 git -C top add middle && 1216 git -C top commit -m "upstream_commit" && 1217 1218 # Create a downstream conflict 1219 test_commit -C top-cloned/middle/bottom downstream_commit && 1220 git -C top-cloned/middle add bottom && 1221 git -C top-cloned/middle commit -m "downstream_commit" && 1222 git -C top-cloned/middle fetch --recurse-submodules origin && 1223 test_must_fail git -C top-cloned/middle merge origin/main && 1224 1225 # Make the update of "middle" a no-op, otherwise we error out 1226 # because of its unmerged state 1227 test_config -C top-cloned submodule.middle.update !true && 1228 git -C top-cloned submodule update --recursive 2>actual.err && 1229 cat >expect.err <<-\EOF && 1230 Skipping unmerged submodule middle/bottom 1231 EOF 1232 test_cmp expect.err actual.err 1233' 1234 1235test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' 1236 test_when_finished "rm -fr top-cloned" && 1237 cp -r top-clean top-cloned && 1238 1239 test_commit -C top-cloned/middle/bottom downstream_commit && 1240 git -C top-cloned/middle config submodule.bottom.update none && 1241 git -C top-cloned submodule update --recursive 2>actual.err && 1242 cat >expect.err <<-\EOF && 1243 Skipping submodule '\''middle/bottom'\'' 1244 EOF 1245 test_cmp expect.err actual.err 1246' 1247 1248add_submodule_commit_and_validate () { 1249 HASH=$(git rev-parse HEAD) && 1250 git update-index --add --cacheinfo 160000,$HASH,sub && 1251 git commit -m "create submodule" && 1252 echo "160000 commit $HASH sub" >expect && 1253 git ls-tree HEAD -- sub >actual && 1254 test_cmp expect actual 1255} 1256 1257test_expect_success 'commit with staged submodule change' ' 1258 add_submodule_commit_and_validate 1259' 1260 1261test_expect_success 'commit with staged submodule change with ignoreSubmodules dirty' ' 1262 test_config diff.ignoreSubmodules dirty && 1263 add_submodule_commit_and_validate 1264' 1265 1266test_expect_success 'commit with staged submodule change with ignoreSubmodules all' ' 1267 test_config diff.ignoreSubmodules all && 1268 add_submodule_commit_and_validate 1269' 1270 1271test_expect_success CASE_INSENSITIVE_FS,SYMLINKS \ 1272 'submodule paths must not follow symlinks' ' 1273 1274 # This is only needed because we want to run this in a self-contained 1275 # test without having to spin up an HTTP server; However, it would not 1276 # be needed in a real-world scenario where the submodule is simply 1277 # hosted on a public site. 1278 test_config_global protocol.file.allow always && 1279 1280 # Make sure that Git tries to use symlinks on Windows 1281 test_config_global core.symlinks true && 1282 1283 tell_tale_path="$PWD/tell.tale" && 1284 git init hook && 1285 ( 1286 cd hook && 1287 mkdir -p y/hooks && 1288 write_script y/hooks/post-checkout <<-EOF && 1289 echo HOOK-RUN >&2 1290 echo hook-run >"$tell_tale_path" 1291 EOF 1292 git add y/hooks/post-checkout && 1293 test_tick && 1294 git commit -m post-checkout 1295 ) && 1296 1297 hook_repo_path="$(pwd)/hook" && 1298 git init captain && 1299 ( 1300 cd captain && 1301 git submodule add --name x/y "$hook_repo_path" A/modules/x && 1302 test_tick && 1303 git commit -m add-submodule && 1304 1305 printf .git >dotgit.txt && 1306 git hash-object -w --stdin <dotgit.txt >dot-git.hash && 1307 printf "120000 %s 0\ta\n" "$(cat dot-git.hash)" >index.info && 1308 git update-index --index-info <index.info && 1309 test_tick && 1310 git commit -m add-symlink 1311 ) && 1312 1313 test_path_is_missing "$tell_tale_path" && 1314 git clone --recursive captain hooked 2>err && 1315 test_grep ! HOOK-RUN err && 1316 test_path_is_missing "$tell_tale_path" 1317' 1318 1319test_done