t / t4060-diff-submodule-option-diff-format.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
   4# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
   5# Copyright (c) 2016 Jacob Keller (copy + convert to --submodule=diff)
   6#
   7
   8test_description='Support for diff format verbose submodule difference in git diff
   9
  10This test tries to verify the sanity of --submodule=diff option of git diff.
  11'
  12
  13. ./test-lib.sh
  14
  15# Tested non-UTF-8 encoding
  16test_encoding="ISO8859-1"
  17
  18# String "added" in German (translated with Google Translate), encoded in UTF-8,
  19# used in sample commit log messages in add_file() function below.
  20added=$(printf "hinzugef\303\274gt")
  21
  22add_file () {
  23        (
  24                cd "$1" &&
  25                shift &&
  26                for name
  27                do
  28                        echo "$name" >"$name" &&
  29                        git add "$name" &&
  30                        test_tick &&
  31                        # "git commit -m" would break MinGW, as Windows refuse to pass
  32                        # $test_encoding encoded parameter to git.
  33                        echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
  34                        git -c "i18n.commitEncoding=$test_encoding" commit -F -
  35                done >/dev/null &&
  36                git rev-parse --short --verify HEAD
  37        )
  38}
  39
  40commit_file () {
  41        test_tick &&
  42        git commit "$@" -m "Commit $*" >/dev/null
  43}
  44
  45test_expect_success 'setup repository' '
  46        test_create_repo sm1 &&
  47        add_file . foo &&
  48        head1=$(add_file sm1 foo1 foo2) &&
  49        fullhead1=$(git -C sm1 rev-parse --verify HEAD)
  50'
  51
  52test_expect_success 'added submodule' '
  53        git add sm1 &&
  54        git diff-index -p --submodule=diff HEAD >actual &&
  55        cat >expected <<-EOF &&
  56        Submodule sm1 0000000...$head1 (new submodule)
  57        diff --git a/sm1/foo1 b/sm1/foo1
  58        new file mode 100644
  59        index 0000000..1715acd
  60        --- /dev/null
  61        +++ b/sm1/foo1
  62        @@ -0,0 +1 @@
  63        +foo1
  64        diff --git a/sm1/foo2 b/sm1/foo2
  65        new file mode 100644
  66        index 0000000..54b060e
  67        --- /dev/null
  68        +++ b/sm1/foo2
  69        @@ -0,0 +1 @@
  70        +foo2
  71        EOF
  72        test_cmp expected actual
  73'
  74
  75test_expect_success 'added submodule, set diff.submodule' '
  76        test_config diff.submodule log &&
  77        git add sm1 &&
  78        git diff-index -p --submodule=diff HEAD >actual &&
  79        cat >expected <<-EOF &&
  80        Submodule sm1 0000000...$head1 (new submodule)
  81        diff --git a/sm1/foo1 b/sm1/foo1
  82        new file mode 100644
  83        index 0000000..1715acd
  84        --- /dev/null
  85        +++ b/sm1/foo1
  86        @@ -0,0 +1 @@
  87        +foo1
  88        diff --git a/sm1/foo2 b/sm1/foo2
  89        new file mode 100644
  90        index 0000000..54b060e
  91        --- /dev/null
  92        +++ b/sm1/foo2
  93        @@ -0,0 +1 @@
  94        +foo2
  95        EOF
  96        test_cmp expected actual
  97'
  98
  99test_expect_success '--submodule=short overrides diff.submodule' '
 100        test_config diff.submodule log &&
 101        git add sm1 &&
 102        git diff --submodule=short --cached >actual &&
 103        cat >expected <<-EOF &&
 104        diff --git a/sm1 b/sm1
 105        new file mode 160000
 106        index 0000000..$head1
 107        --- /dev/null
 108        +++ b/sm1
 109        @@ -0,0 +1 @@
 110        +Subproject commit $fullhead1
 111        EOF
 112        test_cmp expected actual
 113'
 114
 115test_expect_success 'diff.submodule does not affect plumbing' '
 116        test_config diff.submodule log &&
 117        git diff-index -p HEAD >actual &&
 118        cat >expected <<-EOF &&
 119        diff --git a/sm1 b/sm1
 120        new file mode 160000
 121        index 0000000..$head1
 122        --- /dev/null
 123        +++ b/sm1
 124        @@ -0,0 +1 @@
 125        +Subproject commit $fullhead1
 126        EOF
 127        test_cmp expected actual
 128'
 129
 130commit_file sm1 &&
 131head2=$(add_file sm1 foo3)
 132
 133test_expect_success 'modified submodule(forward)' '
 134        git diff-index -p --submodule=diff HEAD >actual &&
 135        cat >expected <<-EOF &&
 136        Submodule sm1 $head1..$head2:
 137        diff --git a/sm1/foo3 b/sm1/foo3
 138        new file mode 100644
 139        index 0000000..c1ec6c6
 140        --- /dev/null
 141        +++ b/sm1/foo3
 142        @@ -0,0 +1 @@
 143        +foo3
 144        EOF
 145        test_cmp expected actual
 146'
 147
 148test_expect_success 'modified submodule(forward)' '
 149        git diff --submodule=diff >actual &&
 150        cat >expected <<-EOF &&
 151        Submodule sm1 $head1..$head2:
 152        diff --git a/sm1/foo3 b/sm1/foo3
 153        new file mode 100644
 154        index 0000000..c1ec6c6
 155        --- /dev/null
 156        +++ b/sm1/foo3
 157        @@ -0,0 +1 @@
 158        +foo3
 159        EOF
 160        test_cmp expected actual
 161'
 162
 163test_expect_success 'modified submodule(forward) --submodule' '
 164        git diff --submodule >actual &&
 165        cat >expected <<-EOF &&
 166        Submodule sm1 $head1..$head2:
 167          > Add foo3 ($added foo3)
 168        EOF
 169        test_cmp expected actual
 170'
 171
 172fullhead2=$(cd sm1; git rev-parse --verify HEAD)
 173test_expect_success 'modified submodule(forward) --submodule=short' '
 174        git diff --submodule=short >actual &&
 175        cat >expected <<-EOF &&
 176        diff --git a/sm1 b/sm1
 177        index $head1..$head2 160000
 178        --- a/sm1
 179        +++ b/sm1
 180        @@ -1 +1 @@
 181        -Subproject commit $fullhead1
 182        +Subproject commit $fullhead2
 183        EOF
 184        test_cmp expected actual
 185'
 186
 187commit_file sm1 &&
 188head3=$(
 189        cd sm1 &&
 190        git reset --hard HEAD~2 >/dev/null &&
 191        git rev-parse --short --verify HEAD
 192)
 193
 194test_expect_success 'modified submodule(backward)' '
 195        git diff-index -p --submodule=diff HEAD >actual &&
 196        cat >expected <<-EOF &&
 197        Submodule sm1 $head2..$head3 (rewind):
 198        diff --git a/sm1/foo2 b/sm1/foo2
 199        deleted file mode 100644
 200        index 54b060e..0000000
 201        --- a/sm1/foo2
 202        +++ /dev/null
 203        @@ -1 +0,0 @@
 204        -foo2
 205        diff --git a/sm1/foo3 b/sm1/foo3
 206        deleted file mode 100644
 207        index c1ec6c6..0000000
 208        --- a/sm1/foo3
 209        +++ /dev/null
 210        @@ -1 +0,0 @@
 211        -foo3
 212        EOF
 213        test_cmp expected actual
 214'
 215
 216head4=$(add_file sm1 foo4 foo5)
 217test_expect_success 'modified submodule(backward and forward)' '
 218        git diff-index -p --submodule=diff HEAD >actual &&
 219        cat >expected <<-EOF &&
 220        Submodule sm1 $head2...$head4:
 221        diff --git a/sm1/foo2 b/sm1/foo2
 222        deleted file mode 100644
 223        index 54b060e..0000000
 224        --- a/sm1/foo2
 225        +++ /dev/null
 226        @@ -1 +0,0 @@
 227        -foo2
 228        diff --git a/sm1/foo3 b/sm1/foo3
 229        deleted file mode 100644
 230        index c1ec6c6..0000000
 231        --- a/sm1/foo3
 232        +++ /dev/null
 233        @@ -1 +0,0 @@
 234        -foo3
 235        diff --git a/sm1/foo4 b/sm1/foo4
 236        new file mode 100644
 237        index 0000000..a0016db
 238        --- /dev/null
 239        +++ b/sm1/foo4
 240        @@ -0,0 +1 @@
 241        +foo4
 242        diff --git a/sm1/foo5 b/sm1/foo5
 243        new file mode 100644
 244        index 0000000..d6f2413
 245        --- /dev/null
 246        +++ b/sm1/foo5
 247        @@ -0,0 +1 @@
 248        +foo5
 249        EOF
 250        test_cmp expected actual
 251'
 252
 253commit_file sm1 &&
 254mv sm1 sm1-bak &&
 255echo sm1 >sm1 &&
 256head5=$(git hash-object sm1 | cut -c1-7) &&
 257git add sm1 &&
 258rm -f sm1 &&
 259mv sm1-bak sm1
 260
 261test_expect_success 'typechanged submodule(submodule->blob), --cached' '
 262        git diff --submodule=diff --cached >actual &&
 263        cat >expected <<-EOF &&
 264        Submodule sm1 $head4...0000000 (submodule deleted)
 265        diff --git a/sm1/foo1 b/sm1/foo1
 266        deleted file mode 100644
 267        index 1715acd..0000000
 268        --- a/sm1/foo1
 269        +++ /dev/null
 270        @@ -1 +0,0 @@
 271        -foo1
 272        diff --git a/sm1/foo4 b/sm1/foo4
 273        deleted file mode 100644
 274        index a0016db..0000000
 275        --- a/sm1/foo4
 276        +++ /dev/null
 277        @@ -1 +0,0 @@
 278        -foo4
 279        diff --git a/sm1/foo5 b/sm1/foo5
 280        deleted file mode 100644
 281        index d6f2413..0000000
 282        --- a/sm1/foo5
 283        +++ /dev/null
 284        @@ -1 +0,0 @@
 285        -foo5
 286        diff --git a/sm1 b/sm1
 287        new file mode 100644
 288        index 0000000..9da5fb8
 289        --- /dev/null
 290        +++ b/sm1
 291        @@ -0,0 +1 @@
 292        +sm1
 293        EOF
 294        test_cmp expected actual
 295'
 296
 297test_expect_success 'typechanged submodule(submodule->blob)' '
 298        git diff --submodule=diff >actual &&
 299        cat >expected <<-EOF &&
 300        diff --git a/sm1 b/sm1
 301        deleted file mode 100644
 302        index 9da5fb8..0000000
 303        --- a/sm1
 304        +++ /dev/null
 305        @@ -1 +0,0 @@
 306        -sm1
 307        Submodule sm1 0000000...$head4 (new submodule)
 308        diff --git a/sm1/foo1 b/sm1/foo1
 309        new file mode 100644
 310        index 0000000..1715acd
 311        --- /dev/null
 312        +++ b/sm1/foo1
 313        @@ -0,0 +1 @@
 314        +foo1
 315        diff --git a/sm1/foo4 b/sm1/foo4
 316        new file mode 100644
 317        index 0000000..a0016db
 318        --- /dev/null
 319        +++ b/sm1/foo4
 320        @@ -0,0 +1 @@
 321        +foo4
 322        diff --git a/sm1/foo5 b/sm1/foo5
 323        new file mode 100644
 324        index 0000000..d6f2413
 325        --- /dev/null
 326        +++ b/sm1/foo5
 327        @@ -0,0 +1 @@
 328        +foo5
 329        EOF
 330        test_cmp expected actual
 331'
 332
 333rm -rf sm1 &&
 334git checkout-index sm1
 335test_expect_success 'typechanged submodule(submodule->blob)' '
 336        git diff-index -p --submodule=diff HEAD >actual &&
 337        cat >expected <<-EOF &&
 338        Submodule sm1 $head4...0000000 (submodule deleted)
 339        diff --git a/sm1 b/sm1
 340        new file mode 100644
 341        index 0000000..9da5fb8
 342        --- /dev/null
 343        +++ b/sm1
 344        @@ -0,0 +1 @@
 345        +sm1
 346        EOF
 347        test_cmp expected actual
 348'
 349
 350rm -f sm1 &&
 351test_create_repo sm1 &&
 352head6=$(add_file sm1 foo6 foo7)
 353fullhead6=$(cd sm1; git rev-parse --verify HEAD)
 354test_expect_success 'nonexistent commit' '
 355        git diff-index -p --submodule=diff HEAD >actual &&
 356        cat >expected <<-EOF &&
 357        Submodule sm1 $head4...$head6 (commits not present)
 358        EOF
 359        test_cmp expected actual
 360'
 361
 362commit_file
 363test_expect_success 'typechanged submodule(blob->submodule)' '
 364        git diff-index -p --submodule=diff HEAD >actual &&
 365        cat >expected <<-EOF &&
 366        diff --git a/sm1 b/sm1
 367        deleted file mode 100644
 368        index 9da5fb8..0000000
 369        --- a/sm1
 370        +++ /dev/null
 371        @@ -1 +0,0 @@
 372        -sm1
 373        Submodule sm1 0000000...$head6 (new submodule)
 374        diff --git a/sm1/foo6 b/sm1/foo6
 375        new file mode 100644
 376        index 0000000..462398b
 377        --- /dev/null
 378        +++ b/sm1/foo6
 379        @@ -0,0 +1 @@
 380        +foo6
 381        diff --git a/sm1/foo7 b/sm1/foo7
 382        new file mode 100644
 383        index 0000000..6e9262c
 384        --- /dev/null
 385        +++ b/sm1/foo7
 386        @@ -0,0 +1 @@
 387        +foo7
 388        EOF
 389        test_cmp expected actual
 390'
 391
 392commit_file sm1 &&
 393test_expect_success 'submodule is up to date' '
 394        git diff-index -p --submodule=diff HEAD >actual &&
 395        test_must_be_empty actual
 396'
 397
 398test_expect_success 'submodule contains untracked content' '
 399        echo new > sm1/new-file &&
 400        git diff-index -p --submodule=diff HEAD >actual &&
 401        cat >expected <<-EOF &&
 402        Submodule sm1 contains untracked content
 403        EOF
 404        test_cmp expected actual
 405'
 406
 407test_expect_success 'submodule contains untracked content (untracked ignored)' '
 408        git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
 409        test_must_be_empty actual
 410'
 411
 412test_expect_success 'submodule contains untracked content (dirty ignored)' '
 413        git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
 414        test_must_be_empty actual
 415'
 416
 417test_expect_success 'submodule contains untracked content (all ignored)' '
 418        git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
 419        test_must_be_empty actual
 420'
 421
 422test_expect_success 'submodule contains untracked and modified content' '
 423        echo new > sm1/foo6 &&
 424        git diff-index -p --submodule=diff HEAD >actual &&
 425        cat >expected <<-EOF &&
 426        Submodule sm1 contains untracked content
 427        Submodule sm1 contains modified content
 428        diff --git a/sm1/foo6 b/sm1/foo6
 429        index 462398b..3e75765 100644
 430        --- a/sm1/foo6
 431        +++ b/sm1/foo6
 432        @@ -1 +1 @@
 433        -foo6
 434        +new
 435        EOF
 436        test_cmp expected actual
 437'
 438
 439# NOT OK
 440test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
 441        echo new > sm1/foo6 &&
 442        git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
 443        cat >expected <<-EOF &&
 444        Submodule sm1 contains modified content
 445        diff --git a/sm1/foo6 b/sm1/foo6
 446        index 462398b..3e75765 100644
 447        --- a/sm1/foo6
 448        +++ b/sm1/foo6
 449        @@ -1 +1 @@
 450        -foo6
 451        +new
 452        EOF
 453        test_cmp expected actual
 454'
 455
 456test_expect_success 'submodule contains untracked and modified content (dirty ignored)' '
 457        echo new > sm1/foo6 &&
 458        git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
 459        test_must_be_empty actual
 460'
 461
 462test_expect_success 'submodule contains untracked and modified content (all ignored)' '
 463        echo new > sm1/foo6 &&
 464        git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
 465        test_must_be_empty actual
 466'
 467
 468test_expect_success 'submodule contains modified content' '
 469        rm -f sm1/new-file &&
 470        git diff-index -p --submodule=diff HEAD >actual &&
 471        cat >expected <<-EOF &&
 472        Submodule sm1 contains modified content
 473        diff --git a/sm1/foo6 b/sm1/foo6
 474        index 462398b..3e75765 100644
 475        --- a/sm1/foo6
 476        +++ b/sm1/foo6
 477        @@ -1 +1 @@
 478        -foo6
 479        +new
 480        EOF
 481        test_cmp expected actual
 482'
 483
 484(cd sm1; git commit -mchange foo6 >/dev/null) &&
 485head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
 486test_expect_success 'submodule is modified' '
 487        git diff-index -p --submodule=diff HEAD >actual &&
 488        cat >expected <<-EOF &&
 489        Submodule sm1 17243c9..$head8:
 490        diff --git a/sm1/foo6 b/sm1/foo6
 491        index 462398b..3e75765 100644
 492        --- a/sm1/foo6
 493        +++ b/sm1/foo6
 494        @@ -1 +1 @@
 495        -foo6
 496        +new
 497        EOF
 498        test_cmp expected actual
 499'
 500
 501test_expect_success 'modified submodule contains untracked content' '
 502        echo new > sm1/new-file &&
 503        git diff-index -p --submodule=diff HEAD >actual &&
 504        cat >expected <<-EOF &&
 505        Submodule sm1 contains untracked content
 506        Submodule sm1 17243c9..$head8:
 507        diff --git a/sm1/foo6 b/sm1/foo6
 508        index 462398b..3e75765 100644
 509        --- a/sm1/foo6
 510        +++ b/sm1/foo6
 511        @@ -1 +1 @@
 512        -foo6
 513        +new
 514        EOF
 515        test_cmp expected actual
 516'
 517
 518test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
 519        git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
 520        cat >expected <<-EOF &&
 521        Submodule sm1 17243c9..$head8:
 522        diff --git a/sm1/foo6 b/sm1/foo6
 523        index 462398b..3e75765 100644
 524        --- a/sm1/foo6
 525        +++ b/sm1/foo6
 526        @@ -1 +1 @@
 527        -foo6
 528        +new
 529        EOF
 530        test_cmp expected actual
 531'
 532
 533test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
 534        git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
 535        cat >expected <<-EOF &&
 536        Submodule sm1 17243c9..cfce562:
 537        diff --git a/sm1/foo6 b/sm1/foo6
 538        index 462398b..3e75765 100644
 539        --- a/sm1/foo6
 540        +++ b/sm1/foo6
 541        @@ -1 +1 @@
 542        -foo6
 543        +new
 544        EOF
 545        test_cmp expected actual
 546'
 547
 548test_expect_success 'modified submodule contains untracked content (all ignored)' '
 549        git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
 550        test_must_be_empty actual
 551'
 552
 553test_expect_success 'modified submodule contains untracked and modified content' '
 554        echo modification >> sm1/foo6 &&
 555        git diff-index -p --submodule=diff HEAD >actual &&
 556        cat >expected <<-EOF &&
 557        Submodule sm1 contains untracked content
 558        Submodule sm1 contains modified content
 559        Submodule sm1 17243c9..cfce562:
 560        diff --git a/sm1/foo6 b/sm1/foo6
 561        index 462398b..dfda541 100644
 562        --- a/sm1/foo6
 563        +++ b/sm1/foo6
 564        @@ -1 +1,2 @@
 565        -foo6
 566        +new
 567        +modification
 568        EOF
 569        test_cmp expected actual
 570'
 571
 572test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
 573        echo modification >> sm1/foo6 &&
 574        git diff-index -p --ignore-submodules=untracked --submodule=diff HEAD >actual &&
 575        cat >expected <<-EOF &&
 576        Submodule sm1 contains modified content
 577        Submodule sm1 17243c9..cfce562:
 578        diff --git a/sm1/foo6 b/sm1/foo6
 579        index 462398b..e20e2d9 100644
 580        --- a/sm1/foo6
 581        +++ b/sm1/foo6
 582        @@ -1 +1,3 @@
 583        -foo6
 584        +new
 585        +modification
 586        +modification
 587        EOF
 588        test_cmp expected actual
 589'
 590
 591test_expect_success 'modified submodule contains untracked and modified content (dirty ignored)' '
 592        echo modification >> sm1/foo6 &&
 593        git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
 594        cat >expected <<-EOF &&
 595        Submodule sm1 17243c9..cfce562:
 596        diff --git a/sm1/foo6 b/sm1/foo6
 597        index 462398b..3e75765 100644
 598        --- a/sm1/foo6
 599        +++ b/sm1/foo6
 600        @@ -1 +1 @@
 601        -foo6
 602        +new
 603        EOF
 604        test_cmp expected actual
 605'
 606
 607test_expect_success 'modified submodule contains untracked and modified content (all ignored)' '
 608        echo modification >> sm1/foo6 &&
 609        git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
 610        test_must_be_empty actual
 611'
 612
 613# NOT OK
 614test_expect_success 'modified submodule contains modified content' '
 615        rm -f sm1/new-file &&
 616        git diff-index -p --submodule=diff HEAD >actual &&
 617        cat >expected <<-EOF &&
 618        Submodule sm1 contains modified content
 619        Submodule sm1 17243c9..cfce562:
 620        diff --git a/sm1/foo6 b/sm1/foo6
 621        index 462398b..ac466ca 100644
 622        --- a/sm1/foo6
 623        +++ b/sm1/foo6
 624        @@ -1 +1,5 @@
 625        -foo6
 626        +new
 627        +modification
 628        +modification
 629        +modification
 630        +modification
 631        EOF
 632        test_cmp expected actual
 633'
 634
 635rm -rf sm1
 636test_expect_success 'deleted submodule' '
 637        git diff-index -p --submodule=diff HEAD >actual &&
 638        cat >expected <<-EOF &&
 639        Submodule sm1 17243c9...0000000 (submodule deleted)
 640        EOF
 641        test_cmp expected actual
 642'
 643
 644test_expect_success 'create second submodule' '
 645        test_create_repo sm2 &&
 646        head7=$(add_file sm2 foo8 foo9) &&
 647        git add sm2
 648'
 649
 650test_expect_success 'multiple submodules' '
 651        git diff-index -p --submodule=diff HEAD >actual &&
 652        cat >expected <<-EOF &&
 653        Submodule sm1 17243c9...0000000 (submodule deleted)
 654        Submodule sm2 0000000...a5a65c9 (new submodule)
 655        diff --git a/sm2/foo8 b/sm2/foo8
 656        new file mode 100644
 657        index 0000000..db9916b
 658        --- /dev/null
 659        +++ b/sm2/foo8
 660        @@ -0,0 +1 @@
 661        +foo8
 662        diff --git a/sm2/foo9 b/sm2/foo9
 663        new file mode 100644
 664        index 0000000..9c3b4f6
 665        --- /dev/null
 666        +++ b/sm2/foo9
 667        @@ -0,0 +1 @@
 668        +foo9
 669        EOF
 670        test_cmp expected actual
 671'
 672
 673test_expect_success 'path filter' '
 674        git diff-index -p --submodule=diff HEAD sm2 >actual &&
 675        cat >expected <<-EOF &&
 676        Submodule sm2 0000000...a5a65c9 (new submodule)
 677        diff --git a/sm2/foo8 b/sm2/foo8
 678        new file mode 100644
 679        index 0000000..db9916b
 680        --- /dev/null
 681        +++ b/sm2/foo8
 682        @@ -0,0 +1 @@
 683        +foo8
 684        diff --git a/sm2/foo9 b/sm2/foo9
 685        new file mode 100644
 686        index 0000000..9c3b4f6
 687        --- /dev/null
 688        +++ b/sm2/foo9
 689        @@ -0,0 +1 @@
 690        +foo9
 691        EOF
 692        test_cmp expected actual
 693'
 694
 695commit_file sm2
 696test_expect_success 'given commit' '
 697        git diff-index -p --submodule=diff HEAD^ >actual &&
 698        cat >expected <<-EOF &&
 699        Submodule sm1 17243c9...0000000 (submodule deleted)
 700        Submodule sm2 0000000...a5a65c9 (new submodule)
 701        diff --git a/sm2/foo8 b/sm2/foo8
 702        new file mode 100644
 703        index 0000000..db9916b
 704        --- /dev/null
 705        +++ b/sm2/foo8
 706        @@ -0,0 +1 @@
 707        +foo8
 708        diff --git a/sm2/foo9 b/sm2/foo9
 709        new file mode 100644
 710        index 0000000..9c3b4f6
 711        --- /dev/null
 712        +++ b/sm2/foo9
 713        @@ -0,0 +1 @@
 714        +foo9
 715        EOF
 716        test_cmp expected actual
 717'
 718
 719test_expect_success 'setup .git file for sm2' '
 720        (cd sm2 &&
 721         REAL="$(pwd)/../.real" &&
 722         mv .git "$REAL" &&
 723         echo "gitdir: $REAL" >.git)
 724'
 725
 726test_expect_success 'diff --submodule=diff with .git file' '
 727        git diff --submodule=diff HEAD^ >actual &&
 728        cat >expected <<-EOF &&
 729        Submodule sm1 17243c9...0000000 (submodule deleted)
 730        Submodule sm2 0000000...a5a65c9 (new submodule)
 731        diff --git a/sm2/foo8 b/sm2/foo8
 732        new file mode 100644
 733        index 0000000..db9916b
 734        --- /dev/null
 735        +++ b/sm2/foo8
 736        @@ -0,0 +1 @@
 737        +foo8
 738        diff --git a/sm2/foo9 b/sm2/foo9
 739        new file mode 100644
 740        index 0000000..9c3b4f6
 741        --- /dev/null
 742        +++ b/sm2/foo9
 743        @@ -0,0 +1 @@
 744        +foo9
 745        EOF
 746        test_cmp expected actual
 747'
 748
 749test_expect_success 'setup nested submodule' '
 750        git submodule add -f ./sm2 &&
 751        git commit -a -m "add sm2" &&
 752        git -C sm2 submodule add ../sm2 nested &&
 753        git -C sm2 commit -a -m "nested sub"
 754'
 755
 756test_expect_success 'move nested submodule HEAD' '
 757        echo "nested content" >sm2/nested/file &&
 758        git -C sm2/nested add file &&
 759        git -C sm2/nested commit --allow-empty -m "new HEAD"
 760'
 761
 762test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
 763        cat >expected <<-EOF &&
 764        Submodule nested a5a65c9..b55928c:
 765        diff --git a/nested/file b/nested/file
 766        new file mode 100644
 767        index 0000000..ca281f5
 768        --- /dev/null
 769        +++ b/nested/file
 770        @@ -0,0 +1 @@
 771        +nested content
 772        EOF
 773        git -C sm2 diff --submodule=diff >actual 2>err &&
 774        test_must_be_empty err &&
 775        test_cmp expected actual
 776'
 777
 778test_expect_success 'diff --submodule=diff recurses into nested submodules' '
 779        cat >expected <<-EOF &&
 780        Submodule sm2 contains modified content
 781        Submodule sm2 a5a65c9..280969a:
 782        diff --git a/sm2/.gitmodules b/sm2/.gitmodules
 783        new file mode 100644
 784        index 0000000..3a816b8
 785        --- /dev/null
 786        +++ b/sm2/.gitmodules
 787        @@ -0,0 +1,3 @@
 788        +[submodule "nested"]
 789        +       path = nested
 790        +       url = ../sm2
 791        Submodule nested 0000000...b55928c (new submodule)
 792        diff --git a/sm2/nested/file b/sm2/nested/file
 793        new file mode 100644
 794        index 0000000..ca281f5
 795        --- /dev/null
 796        +++ b/sm2/nested/file
 797        @@ -0,0 +1 @@
 798        +nested content
 799        diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
 800        new file mode 100644
 801        index 0000000..db9916b
 802        --- /dev/null
 803        +++ b/sm2/nested/foo8
 804        @@ -0,0 +1 @@
 805        +foo8
 806        diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
 807        new file mode 100644
 808        index 0000000..9c3b4f6
 809        --- /dev/null
 810        +++ b/sm2/nested/foo9
 811        @@ -0,0 +1 @@
 812        +foo9
 813        EOF
 814        git diff --submodule=diff >actual 2>err &&
 815        test_must_be_empty err &&
 816        test_cmp expected actual
 817'
 818
 819test_done