t / t7406-submodule-update.shon commit Merge branch 'js/mingw-hooks-with-exe-suffix' (cddbda4)
   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 path '../super/merging': checked out '$mergingsha1'
 112Submodule path '../super/none': checked out '$nonesha1'
 113Submodule path '../super/rebasing': checked out '$rebasingsha1'
 114Submodule path '../super/submodule': checked out '$submodulesha1'
 115EOF
 116
 117cat <<EOF >expect2
 118Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
 119Submodule 'none' ($pwd/none) registered for path '../super/none'
 120Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
 121Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
 122Cloning into '$pwd/recursivesuper/super/merging'...
 123done.
 124Cloning into '$pwd/recursivesuper/super/none'...
 125done.
 126Cloning into '$pwd/recursivesuper/super/rebasing'...
 127done.
 128Cloning into '$pwd/recursivesuper/super/submodule'...
 129done.
 130EOF
 131
 132test_expect_success 'submodule update --init --recursive from subdirectory' '
 133        git -C recursivesuper/super reset --hard HEAD^ &&
 134        (cd recursivesuper &&
 135         mkdir tmp &&
 136         cd tmp &&
 137         git submodule update --init --recursive ../super >../../actual 2>../../actual2
 138        ) &&
 139        test_i18ncmp expect actual &&
 140        test_i18ncmp expect2 actual2
 141'
 142
 143cat <<EOF >expect2
 144Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
 145EOF
 146
 147test_expect_success 'submodule update --init from and of subdirectory' '
 148        git init withsubs &&
 149        (cd withsubs &&
 150         mkdir foo &&
 151         git submodule add "$(pwd)/../rebasing" foo/sub &&
 152         (cd foo &&
 153          git submodule deinit -f sub &&
 154          git submodule update --init sub 2>../../actual2
 155         )
 156        ) &&
 157        test_i18ncmp expect2 actual2
 158'
 159
 160apos="'";
 161test_expect_success 'submodule update does not fetch already present commits' '
 162        (cd submodule &&
 163          echo line3 >> file &&
 164          git add file &&
 165          test_tick &&
 166          git commit -m "upstream line3"
 167        ) &&
 168        (cd super/submodule &&
 169          head=$(git rev-parse --verify HEAD) &&
 170          echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
 171          git reset --hard HEAD~1
 172        ) &&
 173        (cd super &&
 174          git submodule update > ../actual 2> ../actual.err
 175        ) &&
 176        test_i18ncmp expected actual &&
 177        ! test -s actual.err
 178'
 179
 180test_expect_success 'submodule update should fail due to local changes' '
 181        (cd super/submodule &&
 182         git reset --hard HEAD~1 &&
 183         echo "local change" > file
 184        ) &&
 185        (cd super &&
 186         (cd submodule &&
 187          compare_head
 188         ) &&
 189         test_must_fail git submodule update submodule
 190        )
 191'
 192test_expect_success 'submodule update should throw away changes with --force ' '
 193        (cd super &&
 194         (cd submodule &&
 195          compare_head
 196         ) &&
 197         git submodule update --force submodule &&
 198         cd submodule &&
 199         ! compare_head
 200        )
 201'
 202
 203test_expect_success 'submodule update --force forcibly checks out submodules' '
 204        (cd super &&
 205         (cd submodule &&
 206          rm -f file
 207         ) &&
 208         git submodule update --force submodule &&
 209         (cd submodule &&
 210          test "$(git status -s file)" = ""
 211         )
 212        )
 213'
 214
 215test_expect_success 'submodule update --remote should fetch upstream changes' '
 216        (cd submodule &&
 217         echo line4 >> file &&
 218         git add file &&
 219         test_tick &&
 220         git commit -m "upstream line4"
 221        ) &&
 222        (cd super &&
 223         git submodule update --remote --force submodule &&
 224         cd submodule &&
 225         test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
 226        )
 227'
 228
 229test_expect_success 'submodule update --remote should fetch upstream changes with .' '
 230        (
 231                cd super &&
 232                git config -f .gitmodules submodule."submodule".branch "." &&
 233                git add .gitmodules &&
 234                git commit -m "submodules: update from the respective superproject branch"
 235        ) &&
 236        (
 237                cd submodule &&
 238                echo line4a >> file &&
 239                git add file &&
 240                test_tick &&
 241                git commit -m "upstream line4a" &&
 242                git checkout -b test-branch &&
 243                test_commit on-test-branch
 244        ) &&
 245        (
 246                cd super &&
 247                git submodule update --remote --force submodule &&
 248                git -C submodule log -1 --oneline >actual
 249                git -C ../submodule log -1 --oneline master >expect
 250                test_cmp expect actual &&
 251                git checkout -b test-branch &&
 252                git submodule update --remote --force submodule &&
 253                git -C submodule log -1 --oneline >actual
 254                git -C ../submodule log -1 --oneline test-branch >expect
 255                test_cmp expect actual &&
 256                git checkout master &&
 257                git branch -d test-branch &&
 258                git reset --hard HEAD^
 259        )
 260'
 261
 262test_expect_success 'local config should override .gitmodules branch' '
 263        (cd submodule &&
 264         git checkout test-branch &&
 265         echo line5 >> file &&
 266         git add file &&
 267         test_tick &&
 268         git commit -m "upstream line5" &&
 269         git checkout master
 270        ) &&
 271        (cd super &&
 272         git config submodule.submodule.branch test-branch &&
 273         git submodule update --remote --force submodule &&
 274         cd submodule &&
 275         test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline test-branch)"
 276        )
 277'
 278
 279test_expect_success 'submodule update --rebase staying on master' '
 280        (cd super/submodule &&
 281          git checkout master
 282        ) &&
 283        (cd super &&
 284         (cd submodule &&
 285          compare_head
 286         ) &&
 287         git submodule update --rebase submodule &&
 288         cd submodule &&
 289         compare_head
 290        )
 291'
 292
 293test_expect_success 'submodule update --merge staying on master' '
 294        (cd super/submodule &&
 295          git reset --hard HEAD~1
 296        ) &&
 297        (cd super &&
 298         (cd submodule &&
 299          compare_head
 300         ) &&
 301         git submodule update --merge submodule &&
 302         cd submodule &&
 303         compare_head
 304        )
 305'
 306
 307test_expect_success 'submodule update - rebase in .git/config' '
 308        (cd super &&
 309         git config submodule.submodule.update rebase
 310        ) &&
 311        (cd super/submodule &&
 312          git reset --hard HEAD~1
 313        ) &&
 314        (cd super &&
 315         (cd submodule &&
 316          compare_head
 317         ) &&
 318         git submodule update submodule &&
 319         cd submodule &&
 320         compare_head
 321        )
 322'
 323
 324test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
 325        (cd super &&
 326         git config submodule.submodule.update checkout
 327        ) &&
 328        (cd super/submodule &&
 329          git reset --hard HEAD~1
 330        ) &&
 331        (cd super &&
 332         (cd submodule &&
 333          compare_head
 334         ) &&
 335         git submodule update --rebase submodule &&
 336         cd submodule &&
 337         compare_head
 338        )
 339'
 340
 341test_expect_success 'submodule update - merge in .git/config' '
 342        (cd super &&
 343         git config submodule.submodule.update merge
 344        ) &&
 345        (cd super/submodule &&
 346          git reset --hard HEAD~1
 347        ) &&
 348        (cd super &&
 349         (cd submodule &&
 350          compare_head
 351         ) &&
 352         git submodule update submodule &&
 353         cd submodule &&
 354         compare_head
 355        )
 356'
 357
 358test_expect_success 'submodule update - checkout in .git/config but --merge given' '
 359        (cd super &&
 360         git config submodule.submodule.update checkout
 361        ) &&
 362        (cd super/submodule &&
 363          git reset --hard HEAD~1
 364        ) &&
 365        (cd super &&
 366         (cd submodule &&
 367          compare_head
 368         ) &&
 369         git submodule update --merge submodule &&
 370         cd submodule &&
 371         compare_head
 372        )
 373'
 374
 375test_expect_success 'submodule update - checkout in .git/config' '
 376        (cd super &&
 377         git config submodule.submodule.update checkout
 378        ) &&
 379        (cd super/submodule &&
 380          git reset --hard HEAD^
 381        ) &&
 382        (cd super &&
 383         (cd submodule &&
 384          compare_head
 385         ) &&
 386         git submodule update submodule &&
 387         cd submodule &&
 388         ! compare_head
 389        )
 390'
 391
 392test_expect_success 'submodule update - command in .git/config' '
 393        (cd super &&
 394         git config submodule.submodule.update "!git checkout"
 395        ) &&
 396        (cd super/submodule &&
 397          git reset --hard HEAD^
 398        ) &&
 399        (cd super &&
 400         (cd submodule &&
 401          compare_head
 402         ) &&
 403         git submodule update submodule &&
 404         cd submodule &&
 405         ! compare_head
 406        )
 407'
 408
 409cat << EOF >expect
 410Execution of 'false $submodulesha1' failed in submodule path 'submodule'
 411EOF
 412
 413test_expect_success 'submodule update - command in .git/config catches failure' '
 414        (cd super &&
 415         git config submodule.submodule.update "!false"
 416        ) &&
 417        (cd super/submodule &&
 418          git reset --hard $submodulesha1^
 419        ) &&
 420        (cd super &&
 421         test_must_fail git submodule update submodule 2>../actual
 422        ) &&
 423        test_i18ncmp actual expect
 424'
 425
 426cat << EOF >expect
 427Execution of 'false $submodulesha1' failed in submodule path '../submodule'
 428EOF
 429
 430test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
 431        (cd super &&
 432         git config submodule.submodule.update "!false"
 433        ) &&
 434        (cd super/submodule &&
 435          git reset --hard $submodulesha1^
 436        ) &&
 437        (cd super &&
 438         mkdir tmp && cd tmp &&
 439         test_must_fail git submodule update ../submodule 2>../../actual
 440        ) &&
 441        test_i18ncmp actual expect
 442'
 443
 444cat << EOF >expect
 445Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
 446Failed to recurse into submodule path '../super'
 447EOF
 448
 449test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
 450        (cd recursivesuper &&
 451         git submodule update --remote super &&
 452         git add super &&
 453         git commit -m "update to latest to have more than one commit in submodules"
 454        ) &&
 455        git -C recursivesuper/super config submodule.submodule.update "!false" &&
 456        git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
 457        (cd recursivesuper &&
 458         mkdir -p tmp && cd tmp &&
 459         test_must_fail git submodule update --recursive ../super 2>../../actual
 460        ) &&
 461        test_i18ncmp actual expect
 462'
 463
 464test_expect_success 'submodule init does not copy command into .git/config' '
 465        (cd super &&
 466         H=$(git ls-files -s submodule | cut -d" " -f2) &&
 467         mkdir submodule1 &&
 468         git update-index --add --cacheinfo 160000 $H submodule1 &&
 469         git config -f .gitmodules submodule.submodule1.path submodule1 &&
 470         git config -f .gitmodules submodule.submodule1.url ../submodule &&
 471         git config -f .gitmodules submodule.submodule1.update !false &&
 472         git submodule init submodule1 &&
 473         echo "none" >expect &&
 474         git config submodule.submodule1.update >actual &&
 475         test_cmp expect actual
 476        )
 477'
 478
 479test_expect_success 'submodule init picks up rebase' '
 480        (cd super &&
 481         git config -f .gitmodules submodule.rebasing.update rebase &&
 482         git submodule init rebasing &&
 483         test "rebase" = "$(git config submodule.rebasing.update)"
 484        )
 485'
 486
 487test_expect_success 'submodule init picks up merge' '
 488        (cd super &&
 489         git config -f .gitmodules submodule.merging.update merge &&
 490         git submodule init merging &&
 491         test "merge" = "$(git config submodule.merging.update)"
 492        )
 493'
 494
 495test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
 496        (cd super &&
 497         rm -rf submodule &&
 498         git submodule update submodule &&
 499         git status -s submodule >expect &&
 500         rm -rf submodule &&
 501         git submodule update --merge submodule &&
 502         git status -s submodule >actual &&
 503         test_cmp expect actual
 504        )
 505'
 506
 507test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
 508        (cd super &&
 509         rm -rf submodule &&
 510         git submodule update submodule &&
 511         git status -s submodule >expect &&
 512         rm -rf submodule &&
 513         git submodule update --rebase submodule &&
 514         git status -s submodule >actual &&
 515         test_cmp expect actual
 516        )
 517'
 518
 519test_expect_success 'submodule update ignores update=merge config for new submodules' '
 520        (cd super &&
 521         rm -rf submodule &&
 522         git submodule update submodule &&
 523         git status -s submodule >expect &&
 524         rm -rf submodule &&
 525         git config submodule.submodule.update merge &&
 526         git submodule update submodule &&
 527         git status -s submodule >actual &&
 528         git config --unset submodule.submodule.update &&
 529         test_cmp expect actual
 530        )
 531'
 532
 533test_expect_success 'submodule update ignores update=rebase config for new submodules' '
 534        (cd super &&
 535         rm -rf submodule &&
 536         git submodule update submodule &&
 537         git status -s submodule >expect &&
 538         rm -rf submodule &&
 539         git config submodule.submodule.update rebase &&
 540         git submodule update submodule &&
 541         git status -s submodule >actual &&
 542         git config --unset submodule.submodule.update &&
 543         test_cmp expect actual
 544        )
 545'
 546
 547test_expect_success 'submodule init picks up update=none' '
 548        (cd super &&
 549         git config -f .gitmodules submodule.none.update none &&
 550         git submodule init none &&
 551         test "none" = "$(git config submodule.none.update)"
 552        )
 553'
 554
 555test_expect_success 'submodule update - update=none in .git/config' '
 556        (cd super &&
 557         git config submodule.submodule.update none &&
 558         (cd submodule &&
 559          git checkout master &&
 560          compare_head
 561         ) &&
 562         git diff --raw | grep "        submodule" &&
 563         git submodule update &&
 564         git diff --raw | grep "        submodule" &&
 565         (cd submodule &&
 566          compare_head
 567         ) &&
 568         git config --unset submodule.submodule.update &&
 569         git submodule update submodule
 570        )
 571'
 572
 573test_expect_success 'submodule update - update=none in .git/config but --checkout given' '
 574        (cd super &&
 575         git config submodule.submodule.update none &&
 576         (cd submodule &&
 577          git checkout master &&
 578          compare_head
 579         ) &&
 580         git diff --raw | grep "        submodule" &&
 581         git submodule update --checkout &&
 582         test_must_fail git diff --raw \| grep "        submodule" &&
 583         (cd submodule &&
 584          test_must_fail compare_head
 585         ) &&
 586         git config --unset submodule.submodule.update
 587        )
 588'
 589
 590test_expect_success 'submodule update --init skips submodule with update=none' '
 591        (cd super &&
 592         git add .gitmodules &&
 593         git commit -m ".gitmodules"
 594        ) &&
 595        git clone super cloned &&
 596        (cd cloned &&
 597         git submodule update --init &&
 598         test -e submodule/.git &&
 599         test_must_fail test -e none/.git
 600        )
 601'
 602
 603test_expect_success 'submodule update continues after checkout error' '
 604        (cd super &&
 605         git reset --hard HEAD &&
 606         git submodule add ../submodule submodule2 &&
 607         git submodule init &&
 608         git commit -am "new_submodule" &&
 609         (cd submodule2 &&
 610          git rev-parse --verify HEAD >../expect
 611         ) &&
 612         (cd submodule &&
 613          test_commit "update_submodule" file
 614         ) &&
 615         (cd submodule2 &&
 616          test_commit "update_submodule2" file
 617         ) &&
 618         git add submodule &&
 619         git add submodule2 &&
 620         git commit -m "two_new_submodule_commits" &&
 621         (cd submodule &&
 622          echo "" > file
 623         ) &&
 624         git checkout HEAD^ &&
 625         test_must_fail git submodule update &&
 626         (cd submodule2 &&
 627          git rev-parse --verify HEAD >../actual
 628         ) &&
 629         test_cmp expect actual
 630        )
 631'
 632test_expect_success 'submodule update continues after recursive checkout error' '
 633        (cd super &&
 634         git reset --hard HEAD &&
 635         git checkout master &&
 636         git submodule update &&
 637         (cd submodule &&
 638          git submodule add ../submodule subsubmodule &&
 639          git submodule init &&
 640          git commit -m "new_subsubmodule"
 641         ) &&
 642         git add submodule &&
 643         git commit -m "update_submodule" &&
 644         (cd submodule &&
 645          (cd subsubmodule &&
 646           test_commit "update_subsubmodule" file
 647          ) &&
 648          git add subsubmodule &&
 649          test_commit "update_submodule_again" file &&
 650          (cd subsubmodule &&
 651           test_commit "update_subsubmodule_again" file
 652          ) &&
 653          test_commit "update_submodule_again_again" file
 654         ) &&
 655         (cd submodule2 &&
 656          git rev-parse --verify HEAD >../expect &&
 657          test_commit "update_submodule2_again" file
 658         ) &&
 659         git add submodule &&
 660         git add submodule2 &&
 661         git commit -m "new_commits" &&
 662         git checkout HEAD^ &&
 663         (cd submodule &&
 664          git checkout HEAD^ &&
 665          (cd subsubmodule &&
 666           echo "" > file
 667          )
 668         ) &&
 669         test_must_fail git submodule update --recursive &&
 670         (cd submodule2 &&
 671          git rev-parse --verify HEAD >../actual
 672         ) &&
 673         test_cmp expect actual
 674        )
 675'
 676
 677test_expect_success 'submodule update exit immediately in case of merge conflict' '
 678        (cd super &&
 679         git checkout master &&
 680         git reset --hard HEAD &&
 681         (cd submodule &&
 682          (cd subsubmodule &&
 683           git reset --hard HEAD
 684          )
 685         ) &&
 686         git submodule update --recursive &&
 687         (cd submodule &&
 688          test_commit "update_submodule_2" file
 689         ) &&
 690         (cd submodule2 &&
 691          test_commit "update_submodule2_2" file
 692         ) &&
 693         git add submodule &&
 694         git add submodule2 &&
 695         git commit -m "two_new_submodule_commits" &&
 696         (cd submodule &&
 697          git checkout master &&
 698          test_commit "conflict" file &&
 699          echo "conflict" > file
 700         ) &&
 701         git checkout HEAD^ &&
 702         (cd submodule2 &&
 703          git rev-parse --verify HEAD >../expect
 704         ) &&
 705         git config submodule.submodule.update merge &&
 706         test_must_fail git submodule update &&
 707         (cd submodule2 &&
 708          git rev-parse --verify HEAD >../actual
 709         ) &&
 710         test_cmp expect actual
 711        )
 712'
 713
 714test_expect_success 'submodule update exit immediately after recursive rebase error' '
 715        (cd super &&
 716         git checkout master &&
 717         git reset --hard HEAD &&
 718         (cd submodule &&
 719          git reset --hard HEAD &&
 720          git submodule update --recursive
 721         ) &&
 722         (cd submodule &&
 723          test_commit "update_submodule_3" file
 724         ) &&
 725         (cd submodule2 &&
 726          test_commit "update_submodule2_3" file
 727         ) &&
 728         git add submodule &&
 729         git add submodule2 &&
 730         git commit -m "two_new_submodule_commits" &&
 731         (cd submodule &&
 732          git checkout master &&
 733          test_commit "conflict2" file &&
 734          echo "conflict" > file
 735         ) &&
 736         git checkout HEAD^ &&
 737         (cd submodule2 &&
 738          git rev-parse --verify HEAD >../expect
 739         ) &&
 740         git config submodule.submodule.update rebase &&
 741         test_must_fail git submodule update &&
 742         (cd submodule2 &&
 743          git rev-parse --verify HEAD >../actual
 744         ) &&
 745         test_cmp expect actual
 746        )
 747'
 748
 749test_expect_success 'add different submodules to the same path' '
 750        (cd super &&
 751         git submodule add ../submodule s1 &&
 752         test_must_fail git submodule add ../merging s1
 753        )
 754'
 755
 756test_expect_success 'submodule add places git-dir in superprojects git-dir' '
 757        (cd super &&
 758         mkdir deeper &&
 759         git submodule add ../submodule deeper/submodule &&
 760         (cd deeper/submodule &&
 761          git log > ../../expected
 762         ) &&
 763         (cd .git/modules/deeper/submodule &&
 764          git log > ../../../../actual
 765         ) &&
 766         test_cmp actual expected
 767        )
 768'
 769
 770test_expect_success 'submodule update places git-dir in superprojects git-dir' '
 771        (cd super &&
 772         git commit -m "added submodule"
 773        ) &&
 774        git clone super super2 &&
 775        (cd super2 &&
 776         git submodule init deeper/submodule &&
 777         git submodule update &&
 778         (cd deeper/submodule &&
 779          git log > ../../expected
 780         ) &&
 781         (cd .git/modules/deeper/submodule &&
 782          git log > ../../../../actual
 783         ) &&
 784         test_cmp actual expected
 785        )
 786'
 787
 788test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' '
 789        (cd super2 &&
 790         (cd deeper/submodule &&
 791          git submodule add ../submodule subsubmodule &&
 792          (cd subsubmodule &&
 793           git log > ../../../expected
 794          ) &&
 795          git commit -m "added subsubmodule" &&
 796          git push origin :
 797         ) &&
 798         (cd .git/modules/deeper/submodule/modules/subsubmodule &&
 799          git log > ../../../../../actual
 800         ) &&
 801         git add deeper/submodule &&
 802         git commit -m "update submodule" &&
 803         git push origin : &&
 804         test_cmp actual expected
 805        )
 806'
 807
 808test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' '
 809        mkdir super_update_r &&
 810        (cd super_update_r &&
 811         git init --bare
 812        ) &&
 813        mkdir subsuper_update_r &&
 814        (cd subsuper_update_r &&
 815         git init --bare
 816        ) &&
 817        mkdir subsubsuper_update_r &&
 818        (cd subsubsuper_update_r &&
 819         git init --bare
 820        ) &&
 821        git clone subsubsuper_update_r subsubsuper_update_r2 &&
 822        (cd subsubsuper_update_r2 &&
 823         test_commit "update_subsubsuper" file &&
 824         git push origin master
 825        ) &&
 826        git clone subsuper_update_r subsuper_update_r2 &&
 827        (cd subsuper_update_r2 &&
 828         test_commit "update_subsuper" file &&
 829         git submodule add ../subsubsuper_update_r subsubmodule &&
 830         git commit -am "subsubmodule" &&
 831         git push origin master
 832        ) &&
 833        git clone super_update_r super_update_r2 &&
 834        (cd super_update_r2 &&
 835         test_commit "update_super" file &&
 836         git submodule add ../subsuper_update_r submodule &&
 837         git commit -am "submodule" &&
 838         git push origin master
 839        ) &&
 840        rm -rf super_update_r2 &&
 841        git clone super_update_r super_update_r2 &&
 842        (cd super_update_r2 &&
 843         git submodule update --init --recursive >actual &&
 844         test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual &&
 845         (cd submodule/subsubmodule &&
 846          git log > ../../expected
 847         ) &&
 848         (cd .git/modules/submodule/modules/subsubmodule
 849          git log > ../../../../../actual
 850         )
 851         test_cmp actual expected
 852        )
 853'
 854
 855test_expect_success 'submodule add properly re-creates deeper level submodules' '
 856        (cd super &&
 857         git reset --hard master &&
 858         rm -rf deeper/ &&
 859         git submodule add --force ../submodule deeper/submodule
 860        )
 861'
 862
 863test_expect_success 'submodule update properly revives a moved submodule' '
 864        (cd super &&
 865         H=$(git rev-parse --short HEAD) &&
 866         git commit -am "pre move" &&
 867         H2=$(git rev-parse --short HEAD) &&
 868         git status | sed "s/$H/XXX/" >expect &&
 869         H=$(cd submodule2; git rev-parse HEAD) &&
 870         git rm --cached submodule2 &&
 871         rm -rf submodule2 &&
 872         mkdir -p "moved/sub module" &&
 873         git update-index --add --cacheinfo 160000 $H "moved/sub module" &&
 874         git config -f .gitmodules submodule.submodule2.path "moved/sub module"
 875         git commit -am "post move" &&
 876         git submodule update &&
 877         git status | sed "s/$H2/XXX/" >actual &&
 878         test_cmp expect actual
 879        )
 880'
 881
 882test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
 883        mkdir -p linked/dir &&
 884        ln -s linked/dir linkto &&
 885        (cd linkto &&
 886         git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
 887         (cd super &&
 888          git submodule update --init --recursive
 889         )
 890        )
 891'
 892
 893test_expect_success 'submodule update clone shallow submodule' '
 894        test_when_finished "rm -rf super3" &&
 895        first=$(git -C cloned submodule status submodule |cut -c2-41) &&
 896        second=$(git -C submodule rev-parse HEAD) &&
 897        commit_count=$(git -C submodule rev-list --count $first^..$second) &&
 898        git clone cloned super3 &&
 899        pwd=$(pwd) &&
 900        (
 901                cd super3 &&
 902                sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 903                mv -f .gitmodules.tmp .gitmodules &&
 904                git submodule update --init --depth=$commit_count &&
 905                test 1 = $(git -C submodule log --oneline | wc -l)
 906        )
 907'
 908
 909test_expect_success 'submodule update clone shallow submodule outside of depth' '
 910        test_when_finished "rm -rf super3" &&
 911        git clone cloned super3 &&
 912        pwd=$(pwd) &&
 913        (
 914                cd super3 &&
 915                sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
 916                mv -f .gitmodules.tmp .gitmodules &&
 917                test_must_fail git submodule update --init --depth=1 2>actual &&
 918                test_i18ngrep "Direct fetching of that commit failed." actual &&
 919                git -C ../submodule config uploadpack.allowReachableSHA1InWant true &&
 920                git submodule update --init --depth=1 >actual &&
 921                test 1 = $(git -C submodule log --oneline | wc -l)
 922        )
 923'
 924
 925test_expect_success 'submodule update --recursive drops module name before recursing' '
 926        (cd super2 &&
 927         (cd deeper/submodule/subsubmodule &&
 928          git checkout HEAD^
 929         ) &&
 930         git submodule update --recursive deeper/submodule >actual &&
 931         test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 932        )
 933'
 934
 935test_expect_success 'submodule update can be run in parallel' '
 936        (cd super2 &&
 937         GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
 938         grep "7 tasks" trace.out &&
 939         git config submodule.fetchJobs 8 &&
 940         GIT_TRACE=$(pwd)/trace.out git submodule update &&
 941         grep "8 tasks" trace.out &&
 942         GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
 943         grep "9 tasks" trace.out
 944        )
 945'
 946
 947test_expect_success 'git clone passes the parallel jobs config on to submodules' '
 948        test_when_finished "rm -rf super4" &&
 949        GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
 950        grep "7 tasks" trace.out &&
 951        rm -rf super4 &&
 952        git config --global submodule.fetchJobs 8 &&
 953        GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
 954        grep "8 tasks" trace.out &&
 955        rm -rf super4 &&
 956        GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
 957        grep "9 tasks" trace.out &&
 958        rm -rf super4
 959'
 960
 961test_done