t / t7406-submodule-update.shon commit t1007: factor out repeated setup (4d0efa1)
   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
  12. ./test-lib.sh
  13
  14
  15compare_head()
  16{
  17    sha_master=$(git rev-list --max-count=1 master)
  18    sha_head=$(git rev-list --max-count=1 HEAD)
  19
  20    test "$sha_master" = "$sha_head"
  21}
  22
  23
  24test_expect_success 'setup a submodule tree' '
  25        echo file > file &&
  26        git add file &&
  27        test_tick &&
  28        git commit -m upstream &&
  29        git clone . super &&
  30        git clone super submodule &&
  31        git clone super rebasing &&
  32        git clone super merging &&
  33        git clone super none &&
  34        (cd super &&
  35         git submodule add ../submodule submodule &&
  36         test_tick &&
  37         git commit -m "submodule" &&
  38         git submodule init submodule
  39        ) &&
  40        (cd submodule &&
  41        echo "line2" > file &&
  42        git add file &&
  43        git commit -m "Commit 2"
  44        ) &&
  45        (cd super &&
  46         (cd submodule &&
  47          git pull --rebase origin
  48         ) &&
  49         git add submodule &&
  50         git commit -m "submodule update"
  51        ) &&
  52        (cd super &&
  53         git submodule add ../rebasing rebasing &&
  54         test_tick &&
  55         git commit -m "rebasing"
  56        ) &&
  57        (cd super &&
  58         git submodule add ../merging merging &&
  59         test_tick &&
  60         git commit -m "rebasing"
  61        ) &&
  62        (cd super &&
  63         git submodule add ../none none &&
  64         test_tick &&
  65         git commit -m "none"
  66        ) &&
  67        git clone . recursivesuper &&
  68        ( cd recursivesuper
  69         git submodule add ../super super
  70        )
  71'
  72
  73test_expect_success 'submodule update detaching the HEAD ' '
  74        (cd super/submodule &&
  75         git reset --hard HEAD~1
  76        ) &&
  77        (cd super &&
  78         (cd submodule &&
  79          compare_head
  80         ) &&
  81         git submodule update submodule &&
  82         cd submodule &&
  83         ! compare_head
  84        )
  85'
  86
  87test_expect_success 'submodule update from subdirectory' '
  88        (cd super/submodule &&
  89         git reset --hard HEAD~1
  90        ) &&
  91        mkdir super/sub &&
  92        (cd super/sub &&
  93         (cd ../submodule &&
  94          compare_head
  95         ) &&
  96         git submodule update ../submodule &&
  97         cd ../submodule &&
  98         ! compare_head
  99        )
 100'
 101
 102supersha1=$(git -C super rev-parse HEAD)
 103mergingsha1=$(git -C super/merging rev-parse HEAD)
 104nonesha1=$(git -C super/none rev-parse HEAD)
 105rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
 106submodulesha1=$(git -C super/submodule rev-parse HEAD)
 107pwd=$(pwd)
 108
 109cat <<EOF >expect
 110Submodule path '../super': checked out '$supersha1'
 111Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
 112Submodule 'none' ($pwd/none) registered for path '../super/none'
 113Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
 114Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
 115Submodule path '../super/merging': checked out '$mergingsha1'
 116Submodule path '../super/none': checked out '$nonesha1'
 117Submodule path '../super/rebasing': checked out '$rebasingsha1'
 118Submodule path '../super/submodule': checked out '$submodulesha1'
 119EOF
 120
 121test_expect_success 'submodule update --init --recursive from subdirectory' '
 122        git -C recursivesuper/super reset --hard HEAD^ &&
 123        (cd recursivesuper &&
 124         mkdir tmp &&
 125         cd tmp &&
 126         git submodule update --init --recursive ../super >../../actual
 127        ) &&
 128        test_cmp expect actual
 129'
 130
 131apos="'";
 132test_expect_success 'submodule update does not fetch already present commits' '
 133        (cd submodule &&
 134          echo line3 >> file &&
 135          git add file &&
 136          test_tick &&
 137          git commit -m "upstream line3"
 138        ) &&
 139        (cd super/submodule &&
 140          head=$(git rev-parse --verify HEAD) &&
 141          echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
 142          git reset --hard HEAD~1
 143        ) &&
 144        (cd super &&
 145          git submodule update > ../actual 2> ../actual.err
 146        ) &&
 147        test_i18ncmp expected actual &&
 148        ! test -s actual.err
 149'
 150
 151test_expect_success 'submodule update should fail due to local changes' '
 152        (cd super/submodule &&
 153         git reset --hard HEAD~1 &&
 154         echo "local change" > file
 155        ) &&
 156        (cd super &&
 157         (cd submodule &&
 158          compare_head
 159         ) &&
 160         test_must_fail git submodule update submodule
 161        )
 162'
 163test_expect_success 'submodule update should throw away changes with --force ' '
 164        (cd super &&
 165         (cd submodule &&
 166          compare_head
 167         ) &&
 168         git submodule update --force submodule &&
 169         cd submodule &&
 170         ! compare_head
 171        )
 172'
 173
 174test_expect_success 'submodule update --force forcibly checks out submodules' '
 175        (cd super &&
 176         (cd submodule &&
 177          rm -f file
 178         ) &&
 179         git submodule update --force submodule &&
 180         (cd submodule &&
 181          test "$(git status -s file)" = ""
 182         )
 183        )
 184'
 185
 186test_expect_success 'submodule update --remote should fetch upstream changes' '
 187        (cd submodule &&
 188         echo line4 >> file &&
 189         git add file &&
 190         test_tick &&
 191         git commit -m "upstream line4"
 192        ) &&
 193        (cd super &&
 194         git submodule update --remote --force submodule &&
 195         cd submodule &&
 196         test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
 197        )
 198'
 199
 200test_expect_success 'local config should override .gitmodules branch' '
 201        (cd submodule &&
 202         git checkout -b test-branch &&
 203         echo line5 >> file &&
 204         git add file &&
 205         test_tick &&
 206         git commit -m "upstream line5" &&
 207         git checkout master
 208        ) &&
 209        (cd super &&
 210         git config submodule.submodule.branch test-branch &&
 211         git submodule update --remote --force submodule &&
 212         cd submodule &&
 213         test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
 214        )
 215'
 216
 217test_expect_success 'submodule update --rebase staying on master' '
 218        (cd super/submodule &&
 219          git checkout master
 220        ) &&
 221        (cd super &&
 222         (cd submodule &&
 223          compare_head
 224         ) &&
 225         git submodule update --rebase submodule &&
 226         cd submodule &&
 227         compare_head
 228        )
 229'
 230
 231test_expect_success 'submodule update --merge staying on master' '
 232        (cd super/submodule &&
 233          git reset --hard HEAD~1
 234        ) &&
 235        (cd super &&
 236         (cd submodule &&
 237          compare_head
 238         ) &&
 239         git submodule update --merge submodule &&
 240         cd submodule &&
 241         compare_head
 242        )
 243'
 244
 245test_expect_success 'submodule update - rebase in .git/config' '
 246        (cd super &&
 247         git config submodule.submodule.update rebase
 248        ) &&
 249        (cd super/submodule &&
 250          git reset --hard HEAD~1
 251        ) &&
 252        (cd super &&
 253         (cd submodule &&
 254          compare_head
 255         ) &&
 256         git submodule update submodule &&
 257         cd submodule &&
 258         compare_head
 259        )
 260'
 261
 262test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
 263        (cd super &&
 264         git config submodule.submodule.update checkout
 265        ) &&
 266        (cd super/submodule &&
 267          git reset --hard HEAD~1
 268        ) &&
 269        (cd super &&
 270         (cd submodule &&
 271          compare_head
 272         ) &&
 273         git submodule update --rebase submodule &&
 274         cd submodule &&
 275         compare_head
 276        )
 277'
 278
 279test_expect_success 'submodule update - merge in .git/config' '
 280        (cd super &&
 281         git config submodule.submodule.update merge
 282        ) &&
 283        (cd super/submodule &&
 284          git reset --hard HEAD~1
 285        ) &&
 286        (cd super &&
 287         (cd submodule &&
 288          compare_head
 289         ) &&
 290         git submodule update submodule &&
 291         cd submodule &&
 292         compare_head
 293        )
 294'
 295
 296test_expect_success 'submodule update - checkout in .git/config but --merge given' '
 297        (cd super &&
 298         git config submodule.submodule.update checkout
 299        ) &&
 300        (cd super/submodule &&
 301          git reset --hard HEAD~1
 302        ) &&
 303        (cd super &&
 304         (cd submodule &&
 305          compare_head
 306         ) &&
 307         git submodule update --merge submodule &&
 308         cd submodule &&
 309         compare_head
 310        )
 311'
 312
 313test_expect_success 'submodule update - checkout in .git/config' '
 314        (cd super &&
 315         git config submodule.submodule.update checkout
 316        ) &&
 317        (cd super/submodule &&
 318          git reset --hard HEAD^
 319        ) &&
 320        (cd super &&
 321         (cd submodule &&
 322          compare_head
 323         ) &&
 324         git submodule update submodule &&
 325         cd submodule &&
 326         ! compare_head
 327        )
 328'
 329
 330test_expect_success 'submodule update - command in .git/config' '
 331        (cd super &&
 332         git config submodule.submodule.update "!git checkout"
 333        ) &&
 334        (cd super/submodule &&
 335          git reset --hard HEAD^
 336        ) &&
 337        (cd super &&
 338         (cd submodule &&
 339          compare_head
 340         ) &&
 341         git submodule update submodule &&
 342         cd submodule &&
 343         ! compare_head
 344        )
 345'
 346
 347cat << EOF >expect
 348Execution of 'false $submodulesha1' failed in submodule path 'submodule'
 349EOF
 350
 351test_expect_success 'submodule update - command in .git/config catches failure' '
 352        (cd super &&
 353         git config submodule.submodule.update "!false"
 354        ) &&
 355        (cd super/submodule &&
 356          git reset --hard $submodulesha1^
 357        ) &&
 358        (cd super &&
 359         test_must_fail git submodule update submodule 2>../actual
 360        ) &&
 361        test_cmp actual expect
 362'
 363
 364cat << EOF >expect
 365Execution of 'false $submodulesha1' failed in submodule path '../submodule'
 366EOF
 367
 368test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
 369        (cd super &&
 370         git config submodule.submodule.update "!false"
 371        ) &&
 372        (cd super/submodule &&
 373          git reset --hard $submodulesha1^
 374        ) &&
 375        (cd super &&
 376         mkdir tmp && cd tmp &&
 377         test_must_fail git submodule update ../submodule 2>../../actual
 378        ) &&
 379        test_cmp actual expect
 380'
 381
 382cat << EOF >expect
 383Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
 384Failed to recurse into submodule path '../super'
 385EOF
 386
 387test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
 388        (cd recursivesuper &&
 389         git submodule update --remote super &&
 390         git add super &&
 391         git commit -m "update to latest to have more than one commit in submodules"
 392        ) &&
 393        git -C recursivesuper/super config submodule.submodule.update "!false" &&
 394        git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
 395        (cd recursivesuper &&
 396         mkdir -p tmp && cd tmp &&
 397         test_must_fail git submodule update --recursive ../super 2>../../actual
 398        ) &&
 399        test_cmp actual expect
 400'
 401
 402test_expect_success 'submodule init does not copy command into .git/config' '
 403        (cd super &&
 404         H=$(git ls-files -s submodule | cut -d" " -f2) &&
 405         mkdir submodule1 &&
 406         git update-index --add --cacheinfo 160000 $H submodule1 &&
 407         git config -f .gitmodules submodule.submodule1.path submodule1 &&
 408         git config -f .gitmodules submodule.submodule1.url ../submodule &&
 409         git config -f .gitmodules submodule.submodule1.update !false &&
 410         git submodule init submodule1 &&
 411         echo "none" >expect &&
 412         git config submodule.submodule1.update >actual &&
 413         test_cmp expect actual
 414        )
 415'
 416
 417test_expect_success 'submodule init picks up rebase' '
 418        (cd super &&
 419         git config -f .gitmodules submodule.rebasing.update rebase &&
 420         git submodule init rebasing &&
 421         test "rebase" = "$(git config submodule.rebasing.update)"
 422        )
 423'
 424
 425test_expect_success 'submodule init picks up merge' '
 426        (cd super &&
 427         git config -f .gitmodules submodule.merging.update merge &&
 428         git submodule init merging &&
 429         test "merge" = "$(git config submodule.merging.update)"
 430        )
 431'
 432
 433test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
 434        (cd super &&
 435         rm -rf submodule &&
 436         git submodule update submodule &&
 437         git status -s submodule >expect &&
 438         rm -rf submodule &&
 439         git submodule update --merge submodule &&
 440         git status -s submodule >actual &&
 441         test_cmp expect actual
 442        )
 443'
 444
 445test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
 446        (cd super &&
 447         rm -rf submodule &&
 448         git submodule update submodule &&
 449         git status -s submodule >expect &&
 450         rm -rf submodule &&
 451         git submodule update --rebase submodule &&
 452         git status -s submodule >actual &&
 453         test_cmp expect actual
 454        )
 455'
 456
 457test_expect_success 'submodule update ignores update=merge config for new submodules' '
 458        (cd super &&
 459         rm -rf submodule &&
 460         git submodule update submodule &&
 461         git status -s submodule >expect &&
 462         rm -rf submodule &&
 463         git config submodule.submodule.update merge &&
 464         git submodule update submodule &&
 465         git status -s submodule >actual &&
 466         git config --unset submodule.submodule.update &&
 467         test_cmp expect actual
 468        )
 469'
 470
 471test_expect_success 'submodule update ignores update=rebase config for new submodules' '
 472        (cd super &&
 473         rm -rf submodule &&
 474         git submodule update submodule &&
 475         git status -s submodule >expect &&
 476         rm -rf submodule &&
 477         git config submodule.submodule.update rebase &&
 478         git submodule update submodule &&
 479         git status -s submodule >actual &&
 480         git config --unset submodule.submodule.update &&
 481         test_cmp expect actual
 482        )
 483'
 484
 485test_expect_success 'submodule init picks up update=none' '
 486        (cd super &&
 487         git config -f .gitmodules submodule.none.update none &&
 488         git submodule init none &&
 489         test "none" = "$(git config submodule.none.update)"
 490        )
 491'
 492
 493test_expect_success 'submodule update - update=none in .git/config' '
 494        (cd super &&
 495         git config submodule.submodule.update none &&
 496         (cd submodule &&
 497          git checkout master &&
 498          compare_head
 499         ) &&
 500         git diff --raw | grep "        submodule" &&
 501         git submodule update &&
 502         git diff --raw | grep "        submodule" &&
 503         (cd submodule &&
 504          compare_head
 505         ) &&
 506         git config --unset submodule.submodule.update &&
 507         git submodule update submodule
 508        )
 509'
 510
 511test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
 512        (cd super &&
 513         git config submodule.submodule.update none &&
 514         (cd submodule &&
 515          git checkout master &&
 516          compare_head
 517         ) &&
 518         git diff --raw | grep "        submodule" &&
 519         git submodule update --checkout &&
 520         test_must_fail git diff --raw \| grep "        submodule" &&
 521         (cd submodule &&
 522          test_must_fail compare_head
 523         ) &&
 524         git config --unset submodule.submodule.update
 525        )
 526'
 527
 528test_expect_success 'submodule update --init skips submodule with update=none' '
 529        (cd super &&
 530         git add .gitmodules &&
 531         git commit -m ".gitmodules"
 532        ) &&
 533        git clone super cloned &&
 534        (cd cloned &&
 535         git submodule update --init &&
 536         test -e submodule/.git &&
 537         test_must_fail test -e none/.git
 538        )
 539'
 540
 541test_expect_success 'submodule update continues after checkout error' '
 542        (cd super &&
 543         git reset --hard HEAD &&
 544         git submodule add ../submodule submodule2 &&
 545         git submodule init &&
 546         git commit -am "new_submodule" &&
 547         (cd submodule2 &&
 548          git rev-parse --verify HEAD >../expect
 549         ) &&
 550         (cd submodule &&
 551          test_commit "update_submodule" file
 552         ) &&
 553         (cd submodule2 &&
 554          test_commit "update_submodule2" file
 555         ) &&
 556         git add submodule &&
 557         git add submodule2 &&
 558         git commit -m "two_new_submodule_commits" &&
 559         (cd submodule &&
 560          echo "" > file
 561         ) &&
 562         git checkout HEAD^ &&
 563         test_must_fail git submodule update &&
 564         (cd submodule2 &&
 565          git rev-parse --verify HEAD >../actual
 566         ) &&
 567         test_cmp expect actual
 568        )
 569'
 570test_expect_success 'submodule update continues after recursive checkout error' '
 571        (cd super &&
 572         git reset --hard HEAD &&
 573         git checkout master &&
 574         git submodule update &&
 575         (cd submodule &&
 576          git submodule add ../submodule subsubmodule &&
 577          git submodule init &&
 578          git commit -m "new_subsubmodule"
 579         ) &&
 580         git add submodule &&
 581         git commit -m "update_submodule" &&
 582         (cd submodule &&
 583          (cd subsubmodule &&
 584           test_commit "update_subsubmodule" file
 585          ) &&
 586          git add subsubmodule &&
 587          test_commit "update_submodule_again" file &&
 588          (cd subsubmodule &&
 589           test_commit "update_subsubmodule_again" file
 590          ) &&
 591          test_commit "update_submodule_again_again" file
 592         ) &&
 593         (cd submodule2 &&
 594          git rev-parse --verify HEAD >../expect &&
 595          test_commit "update_submodule2_again" file
 596         ) &&
 597         git add submodule &&
 598         git add submodule2 &&
 599         git commit -m "new_commits" &&
 600         git checkout HEAD^ &&
 601         (cd submodule &&
 602          git checkout HEAD^ &&
 603          (cd subsubmodule &&
 604           echo "" > file
 605          )
 606         ) &&
 607         test_must_fail git submodule update --recursive &&
 608         (cd submodule2 &&
 609          git rev-parse --verify HEAD >../actual
 610         ) &&
 611         test_cmp expect actual
 612        )
 613'
 614
 615test_expect_success 'submodule update exit immediately in case of merge conflict' '
 616        (cd super &&
 617         git checkout master &&
 618         git reset --hard HEAD &&
 619         (cd submodule &&
 620          (cd subsubmodule &&
 621           git reset --hard HEAD
 622          )
 623         ) &&
 624         git submodule update --recursive &&
 625         (cd submodule &&
 626          test_commit "update_submodule_2" file
 627         ) &&
 628         (cd submodule2 &&
 629          test_commit "update_submodule2_2" file
 630         ) &&
 631         git add submodule &&
 632         git add submodule2 &&
 633         git commit -m "two_new_submodule_commits" &&
 634         (cd submodule &&
 635          git checkout master &&
 636          test_commit "conflict" file &&
 637          echo "conflict" > file
 638         ) &&
 639         git checkout HEAD^ &&
 640         (cd submodule2 &&
 641          git rev-parse --verify HEAD >../expect
 642         ) &&
 643         git config submodule.submodule.update merge &&
 644         test_must_fail git submodule update &&
 645         (cd submodule2 &&
 646          git rev-parse --verify HEAD >../actual
 647         ) &&
 648         test_cmp expect actual
 649        )
 650'
 651
 652test_expect_success 'submodule update exit immediately after recursive rebase error' '
 653        (cd super &&
 654         git checkout master &&
 655         git reset --hard HEAD &&
 656         (cd submodule &&
 657          git reset --hard HEAD &&
 658          git submodule update --recursive
 659         ) &&
 660         (cd submodule &&
 661          test_commit "update_submodule_3" file
 662         ) &&
 663         (cd submodule2 &&
 664          test_commit "update_submodule2_3" file
 665         ) &&
 666         git add submodule &&
 667         git add submodule2 &&
 668         git commit -m "two_new_submodule_commits" &&
 669         (cd submodule &&
 670          git checkout master &&
 671          test_commit "conflict2" file &&
 672          echo "conflict" > file
 673         ) &&
 674         git checkout HEAD^ &&
 675         (cd submodule2 &&
 676          git rev-parse --verify HEAD >../expect
 677         ) &&
 678         git config submodule.submodule.update rebase &&
 679         test_must_fail git submodule update &&
 680         (cd submodule2 &&
 681          git rev-parse --verify HEAD >../actual
 682         ) &&
 683         test_cmp expect actual
 684        )
 685'
 686
 687test_expect_success 'add different submodules to the same path' '
 688        (cd super &&
 689         git submodule add ../submodule s1 &&
 690         test_must_fail git submodule add ../merging s1
 691        )
 692'
 693
 694test_expect_success 'submodule add places git-dir in superprojects git-dir' '
 695        (cd super &&
 696         mkdir deeper &&
 697         git submodule add ../submodule deeper/submodule &&
 698         (cd deeper/submodule &&
 699          git log > ../../expected
 700         ) &&
 701         (cd .git/modules/deeper/submodule &&
 702          git log > ../../../../actual
 703         ) &&
 704         test_cmp actual expected
 705        )
 706'
 707
 708test_expect_success 'submodule update places git-dir in superprojects git-dir' '
 709        (cd super &&
 710         git commit -m "added submodule"
 711        ) &&
 712        git clone super super2 &&
 713        (cd super2 &&
 714         git submodule init deeper/submodule &&
 715         git submodule update &&
 716         (cd deeper/submodule &&
 717          git log > ../../expected
 718         ) &&
 719         (cd .git/modules/deeper/submodule &&
 720          git log > ../../../../actual
 721         ) &&
 722         test_cmp actual expected
 723        )
 724'
 725
 726test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
 727        (cd super2 &&
 728         (cd deeper/submodule &&
 729          git submodule add ../submodule subsubmodule &&
 730          (cd subsubmodule &&
 731           git log > ../../../expected
 732          ) &&
 733          git commit -m "added subsubmodule" &&
 734          git push origin :
 735         ) &&
 736         (cd .git/modules/deeper/submodule/modules/subsubmodule &&
 737          git log > ../../../../../actual
 738         ) &&
 739         git add deeper/submodule &&
 740         git commit -m "update submodule" &&
 741         git push origin : &&
 742         test_cmp actual expected
 743        )
 744'
 745
 746test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
 747        mkdir super_update_r &&
 748        (cd super_update_r &&
 749         git init --bare
 750        ) &&
 751        mkdir subsuper_update_r &&
 752        (cd subsuper_update_r &&
 753         git init --bare
 754        ) &&
 755        mkdir subsubsuper_update_r &&
 756        (cd subsubsuper_update_r &&
 757         git init --bare
 758        ) &&
 759        git clone subsubsuper_update_r subsubsuper_update_r2 &&
 760        (cd subsubsuper_update_r2 &&
 761         test_commit "update_subsubsuper" file &&
 762         git push origin master
 763        ) &&
 764        git clone subsuper_update_r subsuper_update_r2 &&
 765        (cd subsuper_update_r2 &&
 766         test_commit "update_subsuper" file &&
 767         git submodule add ../subsubsuper_update_r subsubmodule &&
 768         git commit -am "subsubmodule" &&
 769         git push origin master
 770        ) &&
 771        git clone super_update_r super_update_r2 &&
 772        (cd super_update_r2 &&
 773         test_commit "update_super" file &&
 774         git submodule add ../subsuper_update_r submodule &&
 775         git commit -am "submodule" &&
 776         git push origin master
 777        ) &&
 778        rm -rf super_update_r2 &&
 779        git clone super_update_r super_update_r2 &&
 780        (cd super_update_r2 &&
 781         git submodule update --init --recursive >actual &&
 782         test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
 783         (cd submodule/subsubmodule &&
 784          git log > ../../expected
 785         ) &&
 786         (cd .git/modules/submodule/modules/subsubmodule
 787          git log > ../../../../../actual
 788         )
 789         test_cmp actual expected
 790        )
 791'
 792
 793test_expect_success 'submodule add properly re-creates deeper level submodules' '
 794        (cd super &&
 795         git reset --hard master &&
 796         rm -rf deeper/ &&
 797         git submodule add --force ../submodule deeper/submodule
 798        )
 799'
 800
 801test_expect_success 'submodule update properly revives a moved submodule' '
 802        (cd super &&
 803         H=$(git rev-parse --short HEAD) &&
 804         git commit -am "pre move" &&
 805         H2=$(git rev-parse --short HEAD) &&
 806         git status | sed "s/$H/XXX/" >expect &&
 807         H=$(cd submodule2; git rev-parse HEAD) &&
 808         git rm --cached submodule2 &&
 809         rm -rf submodule2 &&
 810         mkdir -p "moved/sub module" &&
 811         git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
 812         git config -f .gitmodules submodule.submodule2.path "moved/sub module"
 813         git commit -am "post move" &&
 814         git submodule update &&
 815         git status | sed "s/$H2/XXX/" >actual &&
 816         test_cmp expect actual
 817        )
 818'
 819
 820test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
 821        mkdir -p linked/dir &&
 822        ln -s linked/dir linkto &&
 823        (cd linkto &&
 824         git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
 825         (cd super &&
 826          git submodule update --init --recursive
 827         )
 828        )
 829'
 830
 831test_expect_success 'submodule update clone shallow submodule' '
 832        git clone cloned super3 &&
 833        pwd=$(pwd) &&
 834        (cd super3 &&
 835         sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 836         mv -f .gitmodules.tmp .gitmodules &&
 837         git submodule update --init --depth=3
 838         (cd submodule &&
 839          test 1 = $(git log --oneline | wc -l)
 840         )
 841)
 842'
 843
 844test_expect_success 'submodule update --recursive drops module name before recursing' '
 845        (cd super2 &&
 846         (cd deeper/submodule/subsubmodule &&
 847          git checkout HEAD^
 848         ) &&
 849         git submodule update --recursive deeper/submodule >actual &&
 850         test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 851        )
 852'
 853test_done