t / t5526-fetch-submodules.shon commit Merge branch 'jm/mergetool-submodules' into maint (ab02095)
   1#!/bin/sh
   2# Copyright (c) 2010, Jens Lehmann
   3
   4test_description='Recursive "git fetch" for submodules'
   5
   6. ./test-lib.sh
   7
   8pwd=$(pwd)
   9
  10add_upstream_commit() {
  11        (
  12                cd submodule &&
  13                head1=$(git rev-parse --short HEAD) &&
  14                echo new >> subfile &&
  15                test_tick &&
  16                git add subfile &&
  17                git commit -m new subfile &&
  18                head2=$(git rev-parse --short HEAD) &&
  19                echo "From $pwd/submodule" > ../expect.err &&
  20                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err
  21        ) &&
  22        (
  23                cd deepsubmodule &&
  24                head1=$(git rev-parse --short HEAD) &&
  25                echo new >> deepsubfile &&
  26                test_tick &&
  27                git add deepsubfile &&
  28                git commit -m new deepsubfile &&
  29                head2=$(git rev-parse --short HEAD) &&
  30                echo "From $pwd/deepsubmodule" >> ../expect.err &&
  31                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err
  32        )
  33}
  34
  35test_expect_success setup '
  36        mkdir deepsubmodule &&
  37        (
  38                cd deepsubmodule &&
  39                git init &&
  40                echo deepsubcontent > deepsubfile &&
  41                git add deepsubfile &&
  42                git commit -m new deepsubfile
  43        ) &&
  44        mkdir submodule &&
  45        (
  46                cd submodule &&
  47                git init &&
  48                echo subcontent > subfile &&
  49                git add subfile &&
  50                git submodule add "$pwd/deepsubmodule" deepsubmodule &&
  51                git commit -a -m new
  52        ) &&
  53        git submodule add "$pwd/submodule" submodule &&
  54        git commit -am initial &&
  55        git clone . downstream &&
  56        (
  57                cd downstream &&
  58                git submodule update --init --recursive
  59        ) &&
  60        echo "Fetching submodule submodule" > expect.out &&
  61        echo "Fetching submodule submodule/deepsubmodule" >> expect.out
  62'
  63
  64test_expect_success "fetch --recurse-submodules recurses into submodules" '
  65        add_upstream_commit &&
  66        (
  67                cd downstream &&
  68                git fetch --recurse-submodules >../actual.out 2>../actual.err
  69        )
  70'
  71
  72test_expect_success C_LOCALE_OUTPUT "fetch --recurse-submodules recurses into submodules: output" '
  73        test_cmp expect.out actual.out &&
  74        test_cmp expect.err actual.err
  75'
  76
  77test_expect_success "fetch alone only fetches superproject" '
  78        add_upstream_commit &&
  79        (
  80                cd downstream &&
  81                git fetch >../actual.out 2>../actual.err
  82        ) &&
  83        ! test -s actual.out &&
  84        ! test -s actual.err
  85'
  86
  87test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
  88        (
  89                cd downstream &&
  90                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
  91        ) &&
  92        ! test -s actual.out &&
  93        ! test -s actual.err
  94'
  95
  96test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
  97        (
  98                cd downstream &&
  99                git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
 100                git fetch >../actual.out 2>../actual.err
 101        )
 102'
 103
 104test_expect_success C_LOCALE_OUTPUT "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
 105        test_cmp expect.out actual.out &&
 106        test_cmp expect.err actual.err
 107'
 108
 109test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
 110        add_upstream_commit &&
 111        (
 112                cd downstream &&
 113                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
 114        ) &&
 115        ! test -s actual.out &&
 116        ! test -s actual.err
 117'
 118
 119test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
 120        (
 121                cd downstream &&
 122                git config submodule.submodule.fetchRecurseSubmodules false &&
 123                git fetch >../actual.out 2>../actual.err
 124        ) &&
 125        ! test -s actual.out &&
 126        ! test -s actual.err
 127'
 128
 129test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
 130        (
 131                cd downstream &&
 132                git fetch --recurse-submodules >../actual.out 2>../actual.err &&
 133                git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
 134                git config --unset submodule.submodule.fetchRecurseSubmodules
 135        )
 136'
 137
 138test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config: output" '
 139        test_cmp expect.out actual.out &&
 140        test_cmp expect.err actual.err
 141'
 142
 143test_expect_success "--quiet propagates to submodules" '
 144        (
 145                cd downstream &&
 146                git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
 147        ) &&
 148        ! test -s actual.out &&
 149        ! test -s actual.err
 150'
 151
 152test_expect_success "--dry-run propagates to submodules" '
 153        add_upstream_commit &&
 154        (
 155                cd downstream &&
 156                git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
 157        )
 158'
 159
 160test_expect_success C_LOCALE_OUTPUT "--dry-run propagates to submodules: output" '
 161        test_cmp expect.out actual.out &&
 162        test_cmp expect.err actual.err
 163'
 164
 165test_expect_success "Without --dry-run propagates to submodules" '
 166        (
 167                cd downstream &&
 168                git fetch --recurse-submodules >../actual.out 2>../actual.err
 169        )
 170'
 171
 172test_expect_success C_LOCALE_OUTPUT "Without --dry-run propagates to submodules: output" '
 173        test_cmp expect.out actual.out &&
 174        test_cmp expect.err actual.err
 175'
 176
 177test_expect_success "recurseSubmodules=true propagates into submodules" '
 178        add_upstream_commit &&
 179        (
 180                cd downstream &&
 181                git config fetch.recurseSubmodules true
 182                git fetch >../actual.out 2>../actual.err
 183        )
 184'
 185
 186test_expect_success C_LOCALE_OUTPUT "recurseSubmodules=true propagates into submodules: output" '
 187        test_cmp expect.out actual.out &&
 188        test_cmp expect.err actual.err
 189'
 190
 191test_expect_success "--recurse-submodules overrides config in submodule" '
 192        add_upstream_commit &&
 193        (
 194                cd downstream &&
 195                (
 196                        cd submodule &&
 197                        git config fetch.recurseSubmodules false
 198                ) &&
 199                git fetch --recurse-submodules >../actual.out 2>../actual.err
 200        )
 201'
 202
 203test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides config in submodule: output" '
 204        test_cmp expect.out actual.out &&
 205        test_cmp expect.err actual.err
 206'
 207
 208test_expect_success "--no-recurse-submodules overrides config setting" '
 209        add_upstream_commit &&
 210        (
 211                cd downstream &&
 212                git config fetch.recurseSubmodules true
 213                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
 214        ) &&
 215        ! test -s actual.out &&
 216        ! test -s actual.err
 217'
 218
 219test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" '
 220        (
 221                cd downstream &&
 222                (
 223                        cd submodule &&
 224                        git config --unset fetch.recurseSubmodules
 225                ) &&
 226                git config --unset fetch.recurseSubmodules
 227                git fetch >../actual.out 2>../actual.err
 228        ) &&
 229        ! test -s actual.out &&
 230        ! test -s actual.err
 231'
 232
 233test_expect_success "Recursion stops when no new submodule commits are fetched" '
 234        head1=$(git rev-parse --short HEAD) &&
 235        git add submodule &&
 236        git commit -m "new submodule" &&
 237        head2=$(git rev-parse --short HEAD) &&
 238        echo "Fetching submodule submodule" > expect.out.sub &&
 239        echo "From $pwd/." > expect.err.sub &&
 240        echo "   $head1..$head2  master     -> origin/master" >> expect.err.sub
 241        head -2 expect.err >> expect.err.sub &&
 242        (
 243                cd downstream &&
 244                git fetch >../actual.out 2>../actual.err
 245        ) &&
 246        test_cmp expect.err.sub actual.err &&
 247        test_cmp expect.out.sub actual.out
 248'
 249
 250test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" '
 251        add_upstream_commit &&
 252        head1=$(git rev-parse --short HEAD) &&
 253        echo a > file &&
 254        git add file &&
 255        git commit -m "new file" &&
 256        head2=$(git rev-parse --short HEAD) &&
 257        echo "From $pwd/." > expect.err.file &&
 258        echo "   $head1..$head2  master     -> origin/master" >> expect.err.file &&
 259        (
 260                cd downstream &&
 261                git fetch >../actual.out 2>../actual.err
 262        ) &&
 263        ! test -s actual.out &&
 264        test_cmp expect.err.file actual.err
 265'
 266
 267test_expect_success "Recursion picks up config in submodule" '
 268        (
 269                cd downstream &&
 270                git fetch --recurse-submodules &&
 271                (
 272                        cd submodule &&
 273                        git config fetch.recurseSubmodules true
 274                )
 275        ) &&
 276        add_upstream_commit &&
 277        head1=$(git rev-parse --short HEAD) &&
 278        git add submodule &&
 279        git commit -m "new submodule" &&
 280        head2=$(git rev-parse --short HEAD) &&
 281        echo "From $pwd/." > expect.err.sub &&
 282        echo "   $head1..$head2  master     -> origin/master" >> expect.err.sub &&
 283        cat expect.err >> expect.err.sub &&
 284        (
 285                cd downstream &&
 286                git fetch >../actual.out 2>../actual.err &&
 287                (
 288                        cd submodule &&
 289                        git config --unset fetch.recurseSubmodules
 290                )
 291        ) &&
 292        test_cmp expect.err.sub actual.err &&
 293        test_cmp expect.out actual.out
 294'
 295
 296test_expect_success "Recursion picks up all submodules when necessary" '
 297        add_upstream_commit &&
 298        (
 299                cd submodule &&
 300                (
 301                        cd deepsubmodule &&
 302                        git fetch &&
 303                        git checkout -q FETCH_HEAD
 304                ) &&
 305                head1=$(git rev-parse --short HEAD^) &&
 306                git add deepsubmodule &&
 307                git commit -m "new deepsubmodule"
 308                head2=$(git rev-parse --short HEAD) &&
 309                echo "From $pwd/submodule" > ../expect.err.sub &&
 310                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err.sub
 311        ) &&
 312        head1=$(git rev-parse --short HEAD) &&
 313        git add submodule &&
 314        git commit -m "new submodule" &&
 315        head2=$(git rev-parse --short HEAD) &&
 316        echo "From $pwd/." > expect.err.2 &&
 317        echo "   $head1..$head2  master     -> origin/master" >> expect.err.2 &&
 318        cat expect.err.sub >> expect.err.2 &&
 319        tail -2 expect.err >> expect.err.2 &&
 320        (
 321                cd downstream &&
 322                git fetch >../actual.out 2>../actual.err
 323        ) &&
 324        test_cmp expect.err.2 actual.err &&
 325        test_cmp expect.out actual.out
 326'
 327
 328test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" '
 329        add_upstream_commit &&
 330        (
 331                cd submodule &&
 332                (
 333                        cd deepsubmodule &&
 334                        git fetch &&
 335                        git checkout -q FETCH_HEAD
 336                ) &&
 337                head1=$(git rev-parse --short HEAD^) &&
 338                git add deepsubmodule &&
 339                git commit -m "new deepsubmodule"
 340                head2=$(git rev-parse --short HEAD) &&
 341                echo "From $pwd/submodule" > ../expect.err.sub &&
 342                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err.sub
 343        ) &&
 344        (
 345                cd downstream &&
 346                git config fetch.recurseSubmodules true &&
 347                git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
 348                git config --unset fetch.recurseSubmodules
 349        ) &&
 350        ! test -s actual.out &&
 351        ! test -s actual.err
 352'
 353
 354test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" '
 355        head1=$(git rev-parse --short HEAD) &&
 356        git add submodule &&
 357        git commit -m "new submodule" &&
 358        head2=$(git rev-parse --short HEAD) &&
 359        tail -2 expect.err > expect.err.deepsub &&
 360        echo "From $pwd/." > expect.err &&
 361        echo "   $head1..$head2  master     -> origin/master" >> expect.err
 362        cat expect.err.sub >> expect.err &&
 363        cat expect.err.deepsub >> expect.err &&
 364        (
 365                cd downstream &&
 366                git config fetch.recurseSubmodules false &&
 367                (
 368                        cd submodule &&
 369                        git config -f .gitmodules submodule.deepsubmodule.fetchRecursive false
 370                ) &&
 371                git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err &&
 372                git config --unset fetch.recurseSubmodules
 373                (
 374                        cd submodule &&
 375                        git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive
 376                )
 377        ) &&
 378        test_cmp expect.out actual.out &&
 379        test_cmp expect.err actual.err
 380'
 381
 382test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" '
 383        add_upstream_commit &&
 384        head1=$(git rev-parse --short HEAD) &&
 385        echo a >> file &&
 386        git add file &&
 387        git commit -m "new file" &&
 388        head2=$(git rev-parse --short HEAD) &&
 389        echo "From $pwd/." > expect.err.file &&
 390        echo "   $head1..$head2  master     -> origin/master" >> expect.err.file &&
 391        (
 392                cd downstream &&
 393                git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err
 394        ) &&
 395        ! test -s actual.out &&
 396        test_cmp expect.err.file actual.err
 397'
 398
 399test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" '
 400        (
 401                cd downstream &&
 402                git fetch --recurse-submodules
 403        ) &&
 404        add_upstream_commit &&
 405        git config --global fetch.recurseSubmodules false &&
 406        head1=$(git rev-parse --short HEAD) &&
 407        git add submodule &&
 408        git commit -m "new submodule" &&
 409        head2=$(git rev-parse --short HEAD) &&
 410        echo "From $pwd/." > expect.err.2 &&
 411        echo "   $head1..$head2  master     -> origin/master" >> expect.err.2
 412        head -2 expect.err >> expect.err.2 &&
 413        (
 414                cd downstream &&
 415                git config fetch.recurseSubmodules on-demand &&
 416                git fetch >../actual.out 2>../actual.err
 417        ) &&
 418        git config --global --unset fetch.recurseSubmodules &&
 419        (
 420                cd downstream &&
 421                git config --unset fetch.recurseSubmodules
 422        ) &&
 423        test_cmp expect.out.sub actual.out &&
 424        test_cmp expect.err.2 actual.err
 425'
 426
 427test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" '
 428        (
 429                cd downstream &&
 430                git fetch --recurse-submodules
 431        ) &&
 432        add_upstream_commit &&
 433        git config fetch.recurseSubmodules false &&
 434        head1=$(git rev-parse --short HEAD) &&
 435        git add submodule &&
 436        git commit -m "new submodule" &&
 437        head2=$(git rev-parse --short HEAD) &&
 438        echo "From $pwd/." > expect.err.2 &&
 439        echo "   $head1..$head2  master     -> origin/master" >> expect.err.2
 440        head -2 expect.err >> expect.err.2 &&
 441        (
 442                cd downstream &&
 443                git config submodule.submodule.fetchRecurseSubmodules on-demand &&
 444                git fetch >../actual.out 2>../actual.err
 445        ) &&
 446        git config --unset fetch.recurseSubmodules &&
 447        (
 448                cd downstream &&
 449                git config --unset submodule.submodule.fetchRecurseSubmodules
 450        ) &&
 451        test_cmp expect.out.sub actual.out &&
 452        test_cmp expect.err.2 actual.err
 453'
 454
 455test_expect_success "don't fetch submodule when newly recorded commits are already present" '
 456        (
 457                cd submodule &&
 458                git checkout -q HEAD^^
 459        ) &&
 460        head1=$(git rev-parse --short HEAD) &&
 461        git add submodule &&
 462        git commit -m "submodule rewound" &&
 463        head2=$(git rev-parse --short HEAD) &&
 464        echo "From $pwd/." > expect.err &&
 465        echo "   $head1..$head2  master     -> origin/master" >> expect.err &&
 466        (
 467                cd downstream &&
 468                git fetch >../actual.out 2>../actual.err
 469        ) &&
 470        ! test -s actual.out &&
 471        test_cmp expect.err actual.err
 472'
 473
 474test_done