01dd3243d605f1562a7358de2488d8d0fb2fc3f3
   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
 382test_expect_success 'submodule init does not copy command into .git/config' '
 383        (cd super &&
 384         H=$(git ls-files -s submodule | cut -d" " -f2) &&
 385         mkdir submodule1 &&
 386         git update-index --add --cacheinfo 160000 $H submodule1 &&
 387         git config -f .gitmodules submodule.submodule1.path submodule1 &&
 388         git config -f .gitmodules submodule.submodule1.url ../submodule &&
 389         git config -f .gitmodules submodule.submodule1.update !false &&
 390         git submodule init submodule1 &&
 391         echo "none" >expect &&
 392         git config submodule.submodule1.update >actual &&
 393         test_cmp expect actual
 394        )
 395'
 396
 397test_expect_success 'submodule init picks up rebase' '
 398        (cd super &&
 399         git config -f .gitmodules submodule.rebasing.update rebase &&
 400         git submodule init rebasing &&
 401         test "rebase" = "$(git config submodule.rebasing.update)"
 402        )
 403'
 404
 405test_expect_success 'submodule init picks up merge' '
 406        (cd super &&
 407         git config -f .gitmodules submodule.merging.update merge &&
 408         git submodule init merging &&
 409         test "merge" = "$(git config submodule.merging.update)"
 410        )
 411'
 412
 413test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
 414        (cd super &&
 415         rm -rf submodule &&
 416         git submodule update submodule &&
 417         git status -s submodule >expect &&
 418         rm -rf submodule &&
 419         git submodule update --merge submodule &&
 420         git status -s submodule >actual &&
 421         test_cmp expect actual
 422        )
 423'
 424
 425test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
 426        (cd super &&
 427         rm -rf submodule &&
 428         git submodule update submodule &&
 429         git status -s submodule >expect &&
 430         rm -rf submodule &&
 431         git submodule update --rebase submodule &&
 432         git status -s submodule >actual &&
 433         test_cmp expect actual
 434        )
 435'
 436
 437test_expect_success 'submodule update ignores update=merge config for new submodules' '
 438        (cd super &&
 439         rm -rf submodule &&
 440         git submodule update submodule &&
 441         git status -s submodule >expect &&
 442         rm -rf submodule &&
 443         git config submodule.submodule.update merge &&
 444         git submodule update submodule &&
 445         git status -s submodule >actual &&
 446         git config --unset submodule.submodule.update &&
 447         test_cmp expect actual
 448        )
 449'
 450
 451test_expect_success 'submodule update ignores update=rebase config for new submodules' '
 452        (cd super &&
 453         rm -rf submodule &&
 454         git submodule update submodule &&
 455         git status -s submodule >expect &&
 456         rm -rf submodule &&
 457         git config submodule.submodule.update rebase &&
 458         git submodule update submodule &&
 459         git status -s submodule >actual &&
 460         git config --unset submodule.submodule.update &&
 461         test_cmp expect actual
 462        )
 463'
 464
 465test_expect_success 'submodule init picks up update=none' '
 466        (cd super &&
 467         git config -f .gitmodules submodule.none.update none &&
 468         git submodule init none &&
 469         test "none" = "$(git config submodule.none.update)"
 470        )
 471'
 472
 473test_expect_success 'submodule update - update=none in .git/config' '
 474        (cd super &&
 475         git config submodule.submodule.update none &&
 476         (cd submodule &&
 477          git checkout master &&
 478          compare_head
 479         ) &&
 480         git diff --raw | grep "        submodule" &&
 481         git submodule update &&
 482         git diff --raw | grep "        submodule" &&
 483         (cd submodule &&
 484          compare_head
 485         ) &&
 486         git config --unset submodule.submodule.update &&
 487         git submodule update submodule
 488        )
 489'
 490
 491test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
 492        (cd super &&
 493         git config submodule.submodule.update none &&
 494         (cd submodule &&
 495          git checkout master &&
 496          compare_head
 497         ) &&
 498         git diff --raw | grep "        submodule" &&
 499         git submodule update --checkout &&
 500         test_must_fail git diff --raw \| grep "        submodule" &&
 501         (cd submodule &&
 502          test_must_fail compare_head
 503         ) &&
 504         git config --unset submodule.submodule.update
 505        )
 506'
 507
 508test_expect_success 'submodule update --init skips submodule with update=none' '
 509        (cd super &&
 510         git add .gitmodules &&
 511         git commit -m ".gitmodules"
 512        ) &&
 513        git clone super cloned &&
 514        (cd cloned &&
 515         git submodule update --init &&
 516         test -e submodule/.git &&
 517         test_must_fail test -e none/.git
 518        )
 519'
 520
 521test_expect_success 'submodule update continues after checkout error' '
 522        (cd super &&
 523         git reset --hard HEAD &&
 524         git submodule add ../submodule submodule2 &&
 525         git submodule init &&
 526         git commit -am "new_submodule" &&
 527         (cd submodule2 &&
 528          git rev-parse --verify HEAD >../expect
 529         ) &&
 530         (cd submodule &&
 531          test_commit "update_submodule" file
 532         ) &&
 533         (cd submodule2 &&
 534          test_commit "update_submodule2" file
 535         ) &&
 536         git add submodule &&
 537         git add submodule2 &&
 538         git commit -m "two_new_submodule_commits" &&
 539         (cd submodule &&
 540          echo "" > file
 541         ) &&
 542         git checkout HEAD^ &&
 543         test_must_fail git submodule update &&
 544         (cd submodule2 &&
 545          git rev-parse --verify HEAD >../actual
 546         ) &&
 547         test_cmp expect actual
 548        )
 549'
 550test_expect_success 'submodule update continues after recursive checkout error' '
 551        (cd super &&
 552         git reset --hard HEAD &&
 553         git checkout master &&
 554         git submodule update &&
 555         (cd submodule &&
 556          git submodule add ../submodule subsubmodule &&
 557          git submodule init &&
 558          git commit -m "new_subsubmodule"
 559         ) &&
 560         git add submodule &&
 561         git commit -m "update_submodule" &&
 562         (cd submodule &&
 563          (cd subsubmodule &&
 564           test_commit "update_subsubmodule" file
 565          ) &&
 566          git add subsubmodule &&
 567          test_commit "update_submodule_again" file &&
 568          (cd subsubmodule &&
 569           test_commit "update_subsubmodule_again" file
 570          ) &&
 571          test_commit "update_submodule_again_again" file
 572         ) &&
 573         (cd submodule2 &&
 574          git rev-parse --verify HEAD >../expect &&
 575          test_commit "update_submodule2_again" file
 576         ) &&
 577         git add submodule &&
 578         git add submodule2 &&
 579         git commit -m "new_commits" &&
 580         git checkout HEAD^ &&
 581         (cd submodule &&
 582          git checkout HEAD^ &&
 583          (cd subsubmodule &&
 584           echo "" > file
 585          )
 586         ) &&
 587         test_must_fail git submodule update --recursive &&
 588         (cd submodule2 &&
 589          git rev-parse --verify HEAD >../actual
 590         ) &&
 591         test_cmp expect actual
 592        )
 593'
 594
 595test_expect_success 'submodule update exit immediately in case of merge conflict' '
 596        (cd super &&
 597         git checkout master &&
 598         git reset --hard HEAD &&
 599         (cd submodule &&
 600          (cd subsubmodule &&
 601           git reset --hard HEAD
 602          )
 603         ) &&
 604         git submodule update --recursive &&
 605         (cd submodule &&
 606          test_commit "update_submodule_2" file
 607         ) &&
 608         (cd submodule2 &&
 609          test_commit "update_submodule2_2" file
 610         ) &&
 611         git add submodule &&
 612         git add submodule2 &&
 613         git commit -m "two_new_submodule_commits" &&
 614         (cd submodule &&
 615          git checkout master &&
 616          test_commit "conflict" file &&
 617          echo "conflict" > file
 618         ) &&
 619         git checkout HEAD^ &&
 620         (cd submodule2 &&
 621          git rev-parse --verify HEAD >../expect
 622         ) &&
 623         git config submodule.submodule.update merge &&
 624         test_must_fail git submodule update &&
 625         (cd submodule2 &&
 626          git rev-parse --verify HEAD >../actual
 627         ) &&
 628         test_cmp expect actual
 629        )
 630'
 631
 632test_expect_success 'submodule update exit immediately after recursive rebase error' '
 633        (cd super &&
 634         git checkout master &&
 635         git reset --hard HEAD &&
 636         (cd submodule &&
 637          git reset --hard HEAD &&
 638          git submodule update --recursive
 639         ) &&
 640         (cd submodule &&
 641          test_commit "update_submodule_3" file
 642         ) &&
 643         (cd submodule2 &&
 644          test_commit "update_submodule2_3" file
 645         ) &&
 646         git add submodule &&
 647         git add submodule2 &&
 648         git commit -m "two_new_submodule_commits" &&
 649         (cd submodule &&
 650          git checkout master &&
 651          test_commit "conflict2" file &&
 652          echo "conflict" > file
 653         ) &&
 654         git checkout HEAD^ &&
 655         (cd submodule2 &&
 656          git rev-parse --verify HEAD >../expect
 657         ) &&
 658         git config submodule.submodule.update rebase &&
 659         test_must_fail git submodule update &&
 660         (cd submodule2 &&
 661          git rev-parse --verify HEAD >../actual
 662         ) &&
 663         test_cmp expect actual
 664        )
 665'
 666
 667test_expect_success 'add different submodules to the same path' '
 668        (cd super &&
 669         git submodule add ../submodule s1 &&
 670         test_must_fail git submodule add ../merging s1
 671        )
 672'
 673
 674test_expect_success 'submodule add places git-dir in superprojects git-dir' '
 675        (cd super &&
 676         mkdir deeper &&
 677         git submodule add ../submodule deeper/submodule &&
 678         (cd deeper/submodule &&
 679          git log > ../../expected
 680         ) &&
 681         (cd .git/modules/deeper/submodule &&
 682          git log > ../../../../actual
 683         ) &&
 684         test_cmp actual expected
 685        )
 686'
 687
 688test_expect_success 'submodule update places git-dir in superprojects git-dir' '
 689        (cd super &&
 690         git commit -m "added submodule"
 691        ) &&
 692        git clone super super2 &&
 693        (cd super2 &&
 694         git submodule init deeper/submodule &&
 695         git submodule update &&
 696         (cd deeper/submodule &&
 697          git log > ../../expected
 698         ) &&
 699         (cd .git/modules/deeper/submodule &&
 700          git log > ../../../../actual
 701         ) &&
 702         test_cmp actual expected
 703        )
 704'
 705
 706test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
 707        (cd super2 &&
 708         (cd deeper/submodule &&
 709          git submodule add ../submodule subsubmodule &&
 710          (cd subsubmodule &&
 711           git log > ../../../expected
 712          ) &&
 713          git commit -m "added subsubmodule" &&
 714          git push origin :
 715         ) &&
 716         (cd .git/modules/deeper/submodule/modules/subsubmodule &&
 717          git log > ../../../../../actual
 718         ) &&
 719         git add deeper/submodule &&
 720         git commit -m "update submodule" &&
 721         git push origin : &&
 722         test_cmp actual expected
 723        )
 724'
 725
 726test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
 727        mkdir super_update_r &&
 728        (cd super_update_r &&
 729         git init --bare
 730        ) &&
 731        mkdir subsuper_update_r &&
 732        (cd subsuper_update_r &&
 733         git init --bare
 734        ) &&
 735        mkdir subsubsuper_update_r &&
 736        (cd subsubsuper_update_r &&
 737         git init --bare
 738        ) &&
 739        git clone subsubsuper_update_r subsubsuper_update_r2 &&
 740        (cd subsubsuper_update_r2 &&
 741         test_commit "update_subsubsuper" file &&
 742         git push origin master
 743        ) &&
 744        git clone subsuper_update_r subsuper_update_r2 &&
 745        (cd subsuper_update_r2 &&
 746         test_commit "update_subsuper" file &&
 747         git submodule add ../subsubsuper_update_r subsubmodule &&
 748         git commit -am "subsubmodule" &&
 749         git push origin master
 750        ) &&
 751        git clone super_update_r super_update_r2 &&
 752        (cd super_update_r2 &&
 753         test_commit "update_super" file &&
 754         git submodule add ../subsuper_update_r submodule &&
 755         git commit -am "submodule" &&
 756         git push origin master
 757        ) &&
 758        rm -rf super_update_r2 &&
 759        git clone super_update_r super_update_r2 &&
 760        (cd super_update_r2 &&
 761         git submodule update --init --recursive >actual &&
 762         test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
 763         (cd submodule/subsubmodule &&
 764          git log > ../../expected
 765         ) &&
 766         (cd .git/modules/submodule/modules/subsubmodule
 767          git log > ../../../../../actual
 768         )
 769         test_cmp actual expected
 770        )
 771'
 772
 773test_expect_success 'submodule add properly re-creates deeper level submodules' '
 774        (cd super &&
 775         git reset --hard master &&
 776         rm -rf deeper/ &&
 777         git submodule add --force ../submodule deeper/submodule
 778        )
 779'
 780
 781test_expect_success 'submodule update properly revives a moved submodule' '
 782        (cd super &&
 783         H=$(git rev-parse --short HEAD) &&
 784         git commit -am "pre move" &&
 785         H2=$(git rev-parse --short HEAD) &&
 786         git status | sed "s/$H/XXX/" >expect &&
 787         H=$(cd submodule2; git rev-parse HEAD) &&
 788         git rm --cached submodule2 &&
 789         rm -rf submodule2 &&
 790         mkdir -p "moved/sub module" &&
 791         git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
 792         git config -f .gitmodules submodule.submodule2.path "moved/sub module"
 793         git commit -am "post move" &&
 794         git submodule update &&
 795         git status | sed "s/$H2/XXX/" >actual &&
 796         test_cmp expect actual
 797        )
 798'
 799
 800test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
 801        mkdir -p linked/dir &&
 802        ln -s linked/dir linkto &&
 803        (cd linkto &&
 804         git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
 805         (cd super &&
 806          git submodule update --init --recursive
 807         )
 808        )
 809'
 810
 811test_expect_success 'submodule update clone shallow submodule' '
 812        git clone cloned super3 &&
 813        pwd=$(pwd) &&
 814        (cd super3 &&
 815         sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 816         mv -f .gitmodules.tmp .gitmodules &&
 817         git submodule update --init --depth=3
 818         (cd submodule &&
 819          test 1 = $(git log --oneline | wc -l)
 820         )
 821)
 822'
 823
 824test_expect_success 'submodule update --recursive drops module name before recursing' '
 825        (cd super2 &&
 826         (cd deeper/submodule/subsubmodule &&
 827          git checkout HEAD^
 828         ) &&
 829         git submodule update --recursive deeper/submodule >actual &&
 830         test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 831        )
 832'
 833test_done