t / t7508-status.shon commit Merge branch 'ds/push-squelch-ambig-warning' (1373999)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='git status'
   7
   8. ./test-lib.sh
   9. "$TEST_DIRECTORY"/lib-terminal.sh
  10
  11test_expect_success 'status -h in broken repository' '
  12        git config --global advice.statusuoption false &&
  13        mkdir broken &&
  14        test_when_finished "rm -fr broken" &&
  15        (
  16                cd broken &&
  17                git init &&
  18                echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
  19                test_expect_code 129 git status -h >usage 2>&1
  20        ) &&
  21        test_i18ngrep "[Uu]sage" broken/usage
  22'
  23
  24test_expect_success 'commit -h in broken repository' '
  25        mkdir broken &&
  26        test_when_finished "rm -fr broken" &&
  27        (
  28                cd broken &&
  29                git init &&
  30                echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
  31                test_expect_code 129 git commit -h >usage 2>&1
  32        ) &&
  33        test_i18ngrep "[Uu]sage" broken/usage
  34'
  35
  36test_expect_success 'create upstream branch' '
  37        git checkout -b upstream &&
  38        test_commit upstream1 &&
  39        test_commit upstream2 &&
  40        # leave the first commit on master as root because several
  41        # tests depend on this case; for our upstream we only
  42        # care about commit counts anyway, so a totally divergent
  43        # history is OK
  44        git checkout --orphan master
  45'
  46
  47test_expect_success 'setup' '
  48        : >tracked &&
  49        : >modified &&
  50        mkdir dir1 &&
  51        : >dir1/tracked &&
  52        : >dir1/modified &&
  53        mkdir dir2 &&
  54        : >dir1/tracked &&
  55        : >dir1/modified &&
  56        git add . &&
  57
  58        git status >output &&
  59
  60        test_tick &&
  61        git commit -m initial &&
  62        : >untracked &&
  63        : >dir1/untracked &&
  64        : >dir2/untracked &&
  65        echo 1 >dir1/modified &&
  66        echo 2 >dir2/modified &&
  67        echo 3 >dir2/added &&
  68        git add dir2/added &&
  69
  70        git branch --set-upstream-to=upstream
  71'
  72
  73test_expect_success 'status (1)' '
  74        test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
  75'
  76
  77strip_comments () {
  78        tab='   '
  79        sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
  80        rm "$1" && mv "$1".tmp "$1"
  81}
  82
  83cat >.gitignore <<\EOF
  84.gitignore
  85expect*
  86output*
  87EOF
  88
  89test_expect_success 'status --column' '
  90        cat >expect <<\EOF &&
  91# On branch master
  92# Your branch and '\''upstream'\'' have diverged,
  93# and have 1 and 2 different commits each, respectively.
  94#   (use "git pull" to merge the remote branch into yours)
  95#
  96# Changes to be committed:
  97#   (use "git reset HEAD <file>..." to unstage)
  98#
  99#       new file:   dir2/added
 100#
 101# Changes not staged for commit:
 102#   (use "git add <file>..." to update what will be committed)
 103#   (use "git checkout -- <file>..." to discard changes in working directory)
 104#
 105#       modified:   dir1/modified
 106#
 107# Untracked files:
 108#   (use "git add <file>..." to include in what will be committed)
 109#
 110#       dir1/untracked dir2/untracked
 111#       dir2/modified  untracked
 112#
 113EOF
 114        COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
 115        test_i18ncmp expect output
 116'
 117
 118test_expect_success 'status --column status.displayCommentPrefix=false' '
 119        strip_comments expect &&
 120        COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
 121        test_i18ncmp expect output
 122'
 123
 124cat >expect <<\EOF
 125# On branch master
 126# Your branch and 'upstream' have diverged,
 127# and have 1 and 2 different commits each, respectively.
 128#   (use "git pull" to merge the remote branch into yours)
 129#
 130# Changes to be committed:
 131#   (use "git reset HEAD <file>..." to unstage)
 132#
 133#       new file:   dir2/added
 134#
 135# Changes not staged for commit:
 136#   (use "git add <file>..." to update what will be committed)
 137#   (use "git checkout -- <file>..." to discard changes in working directory)
 138#
 139#       modified:   dir1/modified
 140#
 141# Untracked files:
 142#   (use "git add <file>..." to include in what will be committed)
 143#
 144#       dir1/untracked
 145#       dir2/modified
 146#       dir2/untracked
 147#       untracked
 148#
 149EOF
 150
 151test_expect_success 'status with status.displayCommentPrefix=true' '
 152        git -c status.displayCommentPrefix=true status >output &&
 153        test_i18ncmp expect output
 154'
 155
 156test_expect_success 'status with status.displayCommentPrefix=false' '
 157        strip_comments expect &&
 158        git -c status.displayCommentPrefix=false status >output &&
 159        test_i18ncmp expect output
 160'
 161
 162test_expect_success 'status -v' '
 163        (cat expect && git diff --cached) >expect-with-v &&
 164        git status -v >output &&
 165        test_i18ncmp expect-with-v output
 166'
 167
 168test_expect_success 'status -v -v' '
 169        (cat expect &&
 170         echo "Changes to be committed:" &&
 171         git -c diff.mnemonicprefix=true diff --cached &&
 172         echo "--------------------------------------------------" &&
 173         echo "Changes not staged for commit:" &&
 174         git -c diff.mnemonicprefix=true diff) >expect-with-v &&
 175        git status -v -v >output &&
 176        test_i18ncmp expect-with-v output
 177'
 178
 179test_expect_success 'setup fake editor' '
 180        cat >.git/editor <<-\EOF &&
 181        #! /bin/sh
 182        cp "$1" output
 183EOF
 184        chmod 755 .git/editor
 185'
 186
 187commit_template_commented () {
 188        (
 189                EDITOR=.git/editor &&
 190                export EDITOR &&
 191                # Fails due to empty message
 192                test_must_fail git commit
 193        ) &&
 194        ! grep '^[^#]' output
 195}
 196
 197test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
 198        commit_template_commented
 199'
 200
 201cat >expect <<\EOF
 202On branch master
 203Your branch and 'upstream' have diverged,
 204and have 1 and 2 different commits each, respectively.
 205
 206Changes to be committed:
 207        new file:   dir2/added
 208
 209Changes not staged for commit:
 210        modified:   dir1/modified
 211
 212Untracked files:
 213        dir1/untracked
 214        dir2/modified
 215        dir2/untracked
 216        untracked
 217
 218EOF
 219
 220test_expect_success 'status (advice.statusHints false)' '
 221        test_config advice.statusHints false &&
 222        git status >output &&
 223        test_i18ncmp expect output
 224
 225'
 226
 227cat >expect <<\EOF
 228 M dir1/modified
 229A  dir2/added
 230?? dir1/untracked
 231?? dir2/modified
 232?? dir2/untracked
 233?? untracked
 234EOF
 235
 236test_expect_success 'status -s' '
 237
 238        git status -s >output &&
 239        test_cmp expect output
 240
 241'
 242
 243test_expect_success 'status with gitignore' '
 244        {
 245                echo ".gitignore" &&
 246                echo "expect*" &&
 247                echo "output" &&
 248                echo "untracked"
 249        } >.gitignore &&
 250
 251        cat >expect <<-\EOF &&
 252         M dir1/modified
 253        A  dir2/added
 254        ?? dir2/modified
 255        EOF
 256        git status -s >output &&
 257        test_cmp expect output &&
 258
 259        cat >expect <<-\EOF &&
 260         M dir1/modified
 261        A  dir2/added
 262        ?? dir2/modified
 263        !! .gitignore
 264        !! dir1/untracked
 265        !! dir2/untracked
 266        !! expect
 267        !! expect-with-v
 268        !! output
 269        !! untracked
 270        EOF
 271        git status -s --ignored >output &&
 272        test_cmp expect output &&
 273
 274        cat >expect <<\EOF &&
 275On branch master
 276Your branch and '\''upstream'\'' have diverged,
 277and have 1 and 2 different commits each, respectively.
 278  (use "git pull" to merge the remote branch into yours)
 279
 280Changes to be committed:
 281  (use "git reset HEAD <file>..." to unstage)
 282
 283        new file:   dir2/added
 284
 285Changes not staged for commit:
 286  (use "git add <file>..." to update what will be committed)
 287  (use "git checkout -- <file>..." to discard changes in working directory)
 288
 289        modified:   dir1/modified
 290
 291Untracked files:
 292  (use "git add <file>..." to include in what will be committed)
 293
 294        dir2/modified
 295
 296Ignored files:
 297  (use "git add -f <file>..." to include in what will be committed)
 298
 299        .gitignore
 300        dir1/untracked
 301        dir2/untracked
 302        expect
 303        expect-with-v
 304        output
 305        untracked
 306
 307EOF
 308        git status --ignored >output &&
 309        test_i18ncmp expect output
 310'
 311
 312test_expect_success 'status with gitignore (nothing untracked)' '
 313        {
 314                echo ".gitignore" &&
 315                echo "expect*" &&
 316                echo "dir2/modified" &&
 317                echo "output" &&
 318                echo "untracked"
 319        } >.gitignore &&
 320
 321        cat >expect <<-\EOF &&
 322         M dir1/modified
 323        A  dir2/added
 324        EOF
 325        git status -s >output &&
 326        test_cmp expect output &&
 327
 328        cat >expect <<-\EOF &&
 329         M dir1/modified
 330        A  dir2/added
 331        !! .gitignore
 332        !! dir1/untracked
 333        !! dir2/modified
 334        !! dir2/untracked
 335        !! expect
 336        !! expect-with-v
 337        !! output
 338        !! untracked
 339        EOF
 340        git status -s --ignored >output &&
 341        test_cmp expect output &&
 342
 343        cat >expect <<\EOF &&
 344On branch master
 345Your branch and '\''upstream'\'' have diverged,
 346and have 1 and 2 different commits each, respectively.
 347  (use "git pull" to merge the remote branch into yours)
 348
 349Changes to be committed:
 350  (use "git reset HEAD <file>..." to unstage)
 351
 352        new file:   dir2/added
 353
 354Changes not staged for commit:
 355  (use "git add <file>..." to update what will be committed)
 356  (use "git checkout -- <file>..." to discard changes in working directory)
 357
 358        modified:   dir1/modified
 359
 360Ignored files:
 361  (use "git add -f <file>..." to include in what will be committed)
 362
 363        .gitignore
 364        dir1/untracked
 365        dir2/modified
 366        dir2/untracked
 367        expect
 368        expect-with-v
 369        output
 370        untracked
 371
 372EOF
 373        git status --ignored >output &&
 374        test_i18ncmp expect output
 375'
 376
 377cat >.gitignore <<\EOF
 378.gitignore
 379expect*
 380output*
 381EOF
 382
 383cat >expect <<\EOF
 384## master...upstream [ahead 1, behind 2]
 385 M dir1/modified
 386A  dir2/added
 387?? dir1/untracked
 388?? dir2/modified
 389?? dir2/untracked
 390?? untracked
 391EOF
 392
 393test_expect_success 'status -s -b' '
 394
 395        git status -s -b >output &&
 396        test_i18ncmp expect output
 397
 398'
 399
 400test_expect_success 'status -s -z -b' '
 401        tr "\\n" Q <expect >expect.q &&
 402        mv expect.q expect &&
 403        git status -s -z -b >output &&
 404        nul_to_q <output >output.q &&
 405        mv output.q output &&
 406        test_i18ncmp expect output
 407'
 408
 409test_expect_success 'setup dir3' '
 410        mkdir dir3 &&
 411        : >dir3/untracked1 &&
 412        : >dir3/untracked2
 413'
 414
 415test_expect_success 'status -uno' '
 416        cat >expect <<EOF &&
 417On branch master
 418Your branch and '\''upstream'\'' have diverged,
 419and have 1 and 2 different commits each, respectively.
 420  (use "git pull" to merge the remote branch into yours)
 421
 422Changes to be committed:
 423  (use "git reset HEAD <file>..." to unstage)
 424
 425        new file:   dir2/added
 426
 427Changes not staged for commit:
 428  (use "git add <file>..." to update what will be committed)
 429  (use "git checkout -- <file>..." to discard changes in working directory)
 430
 431        modified:   dir1/modified
 432
 433Untracked files not listed (use -u option to show untracked files)
 434EOF
 435        git status -uno >output &&
 436        test_i18ncmp expect output
 437'
 438
 439test_expect_success 'status (status.showUntrackedFiles no)' '
 440        test_config status.showuntrackedfiles no &&
 441        git status >output &&
 442        test_i18ncmp expect output
 443'
 444
 445test_expect_success 'status -uno (advice.statusHints false)' '
 446        cat >expect <<EOF &&
 447On branch master
 448Your branch and '\''upstream'\'' have diverged,
 449and have 1 and 2 different commits each, respectively.
 450
 451Changes to be committed:
 452        new file:   dir2/added
 453
 454Changes not staged for commit:
 455        modified:   dir1/modified
 456
 457Untracked files not listed
 458EOF
 459        test_config advice.statusHints false &&
 460        git status -uno >output &&
 461        test_i18ncmp expect output
 462'
 463
 464cat >expect << EOF
 465 M dir1/modified
 466A  dir2/added
 467EOF
 468test_expect_success 'status -s -uno' '
 469        git status -s -uno >output &&
 470        test_cmp expect output
 471'
 472
 473test_expect_success 'status -s (status.showUntrackedFiles no)' '
 474        git config status.showuntrackedfiles no &&
 475        git status -s >output &&
 476        test_cmp expect output
 477'
 478
 479test_expect_success 'status -unormal' '
 480        cat >expect <<EOF &&
 481On branch master
 482Your branch and '\''upstream'\'' have diverged,
 483and have 1 and 2 different commits each, respectively.
 484  (use "git pull" to merge the remote branch into yours)
 485
 486Changes to be committed:
 487  (use "git reset HEAD <file>..." to unstage)
 488
 489        new file:   dir2/added
 490
 491Changes not staged for commit:
 492  (use "git add <file>..." to update what will be committed)
 493  (use "git checkout -- <file>..." to discard changes in working directory)
 494
 495        modified:   dir1/modified
 496
 497Untracked files:
 498  (use "git add <file>..." to include in what will be committed)
 499
 500        dir1/untracked
 501        dir2/modified
 502        dir2/untracked
 503        dir3/
 504        untracked
 505
 506EOF
 507        git status -unormal >output &&
 508        test_i18ncmp expect output
 509'
 510
 511test_expect_success 'status (status.showUntrackedFiles normal)' '
 512        test_config status.showuntrackedfiles normal &&
 513        git status >output &&
 514        test_i18ncmp expect output
 515'
 516
 517cat >expect <<EOF
 518 M dir1/modified
 519A  dir2/added
 520?? dir1/untracked
 521?? dir2/modified
 522?? dir2/untracked
 523?? dir3/
 524?? untracked
 525EOF
 526test_expect_success 'status -s -unormal' '
 527        git status -s -unormal >output &&
 528        test_cmp expect output
 529'
 530
 531test_expect_success 'status -s (status.showUntrackedFiles normal)' '
 532        git config status.showuntrackedfiles normal &&
 533        git status -s >output &&
 534        test_cmp expect output
 535'
 536
 537test_expect_success 'status -uall' '
 538        cat >expect <<EOF &&
 539On branch master
 540Your branch and '\''upstream'\'' have diverged,
 541and have 1 and 2 different commits each, respectively.
 542  (use "git pull" to merge the remote branch into yours)
 543
 544Changes to be committed:
 545  (use "git reset HEAD <file>..." to unstage)
 546
 547        new file:   dir2/added
 548
 549Changes not staged for commit:
 550  (use "git add <file>..." to update what will be committed)
 551  (use "git checkout -- <file>..." to discard changes in working directory)
 552
 553        modified:   dir1/modified
 554
 555Untracked files:
 556  (use "git add <file>..." to include in what will be committed)
 557
 558        dir1/untracked
 559        dir2/modified
 560        dir2/untracked
 561        dir3/untracked1
 562        dir3/untracked2
 563        untracked
 564
 565EOF
 566        git status -uall >output &&
 567        test_i18ncmp expect output
 568'
 569
 570test_expect_success 'status (status.showUntrackedFiles all)' '
 571        test_config status.showuntrackedfiles all &&
 572        git status >output &&
 573        test_i18ncmp expect output
 574'
 575
 576test_expect_success 'teardown dir3' '
 577        rm -rf dir3
 578'
 579
 580cat >expect <<EOF
 581 M dir1/modified
 582A  dir2/added
 583?? dir1/untracked
 584?? dir2/modified
 585?? dir2/untracked
 586?? untracked
 587EOF
 588test_expect_success 'status -s -uall' '
 589        test_unconfig status.showuntrackedfiles &&
 590        git status -s -uall >output &&
 591        test_cmp expect output
 592'
 593test_expect_success 'status -s (status.showUntrackedFiles all)' '
 594        test_config status.showuntrackedfiles all &&
 595        git status -s >output &&
 596        rm -rf dir3 &&
 597        test_cmp expect output
 598'
 599
 600test_expect_success 'status with relative paths' '
 601        cat >expect <<\EOF &&
 602On branch master
 603Your branch and '\''upstream'\'' have diverged,
 604and have 1 and 2 different commits each, respectively.
 605  (use "git pull" to merge the remote branch into yours)
 606
 607Changes to be committed:
 608  (use "git reset HEAD <file>..." to unstage)
 609
 610        new file:   ../dir2/added
 611
 612Changes not staged for commit:
 613  (use "git add <file>..." to update what will be committed)
 614  (use "git checkout -- <file>..." to discard changes in working directory)
 615
 616        modified:   modified
 617
 618Untracked files:
 619  (use "git add <file>..." to include in what will be committed)
 620
 621        untracked
 622        ../dir2/modified
 623        ../dir2/untracked
 624        ../untracked
 625
 626EOF
 627        (cd dir1 && git status) >output &&
 628        test_i18ncmp expect output
 629'
 630
 631cat >expect <<\EOF
 632 M modified
 633A  ../dir2/added
 634?? untracked
 635?? ../dir2/modified
 636?? ../dir2/untracked
 637?? ../untracked
 638EOF
 639test_expect_success 'status -s with relative paths' '
 640
 641        (cd dir1 && git status -s) >output &&
 642        test_cmp expect output
 643
 644'
 645
 646cat >expect <<\EOF
 647 M dir1/modified
 648A  dir2/added
 649?? dir1/untracked
 650?? dir2/modified
 651?? dir2/untracked
 652?? untracked
 653EOF
 654
 655test_expect_success 'status --porcelain ignores relative paths setting' '
 656
 657        (cd dir1 && git status --porcelain) >output &&
 658        test_cmp expect output
 659
 660'
 661
 662test_expect_success 'setup unique colors' '
 663
 664        git config status.color.untracked blue &&
 665        git config status.color.branch green &&
 666        git config status.color.localBranch yellow &&
 667        git config status.color.remoteBranch cyan
 668
 669'
 670
 671test_expect_success TTY 'status with color.ui' '
 672        cat >expect <<\EOF &&
 673On branch <GREEN>master<RESET>
 674Your branch and '\''upstream'\'' have diverged,
 675and have 1 and 2 different commits each, respectively.
 676  (use "git pull" to merge the remote branch into yours)
 677
 678Changes to be committed:
 679  (use "git reset HEAD <file>..." to unstage)
 680
 681        <GREEN>new file:   dir2/added<RESET>
 682
 683Changes not staged for commit:
 684  (use "git add <file>..." to update what will be committed)
 685  (use "git checkout -- <file>..." to discard changes in working directory)
 686
 687        <RED>modified:   dir1/modified<RESET>
 688
 689Untracked files:
 690  (use "git add <file>..." to include in what will be committed)
 691
 692        <BLUE>dir1/untracked<RESET>
 693        <BLUE>dir2/modified<RESET>
 694        <BLUE>dir2/untracked<RESET>
 695        <BLUE>untracked<RESET>
 696
 697EOF
 698        test_config color.ui auto &&
 699        test_terminal git status | test_decode_color >output &&
 700        test_i18ncmp expect output
 701'
 702
 703test_expect_success TTY 'status with color.status' '
 704        test_config color.status auto &&
 705        test_terminal git status | test_decode_color >output &&
 706        test_i18ncmp expect output
 707'
 708
 709cat >expect <<\EOF
 710 <RED>M<RESET> dir1/modified
 711<GREEN>A<RESET>  dir2/added
 712<BLUE>??<RESET> dir1/untracked
 713<BLUE>??<RESET> dir2/modified
 714<BLUE>??<RESET> dir2/untracked
 715<BLUE>??<RESET> untracked
 716EOF
 717
 718test_expect_success TTY 'status -s with color.ui' '
 719
 720        git config color.ui auto &&
 721        test_terminal git status -s | test_decode_color >output &&
 722        test_cmp expect output
 723
 724'
 725
 726test_expect_success TTY 'status -s with color.status' '
 727
 728        git config --unset color.ui &&
 729        git config color.status auto &&
 730        test_terminal git status -s | test_decode_color >output &&
 731        test_cmp expect output
 732
 733'
 734
 735cat >expect <<\EOF
 736## <YELLOW>master<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
 737 <RED>M<RESET> dir1/modified
 738<GREEN>A<RESET>  dir2/added
 739<BLUE>??<RESET> dir1/untracked
 740<BLUE>??<RESET> dir2/modified
 741<BLUE>??<RESET> dir2/untracked
 742<BLUE>??<RESET> untracked
 743EOF
 744
 745test_expect_success TTY 'status -s -b with color.status' '
 746
 747        test_terminal git status -s -b | test_decode_color >output &&
 748        test_i18ncmp expect output
 749
 750'
 751
 752cat >expect <<\EOF
 753 M dir1/modified
 754A  dir2/added
 755?? dir1/untracked
 756?? dir2/modified
 757?? dir2/untracked
 758?? untracked
 759EOF
 760
 761test_expect_success TTY 'status --porcelain ignores color.ui' '
 762
 763        git config --unset color.status &&
 764        git config color.ui auto &&
 765        test_terminal git status --porcelain | test_decode_color >output &&
 766        test_cmp expect output
 767
 768'
 769
 770test_expect_success TTY 'status --porcelain ignores color.status' '
 771
 772        git config --unset color.ui &&
 773        git config color.status auto &&
 774        test_terminal git status --porcelain | test_decode_color >output &&
 775        test_cmp expect output
 776
 777'
 778
 779# recover unconditionally from color tests
 780git config --unset color.status
 781git config --unset color.ui
 782
 783test_expect_success 'status --porcelain respects -b' '
 784
 785        git status --porcelain -b >output &&
 786        {
 787                echo "## master...upstream [ahead 1, behind 2]" &&
 788                cat expect
 789        } >tmp &&
 790        mv tmp expect &&
 791        test_cmp expect output
 792
 793'
 794
 795
 796
 797test_expect_success 'status without relative paths' '
 798        cat >expect <<\EOF &&
 799On branch master
 800Your branch and '\''upstream'\'' have diverged,
 801and have 1 and 2 different commits each, respectively.
 802  (use "git pull" to merge the remote branch into yours)
 803
 804Changes to be committed:
 805  (use "git reset HEAD <file>..." to unstage)
 806
 807        new file:   dir2/added
 808
 809Changes not staged for commit:
 810  (use "git add <file>..." to update what will be committed)
 811  (use "git checkout -- <file>..." to discard changes in working directory)
 812
 813        modified:   dir1/modified
 814
 815Untracked files:
 816  (use "git add <file>..." to include in what will be committed)
 817
 818        dir1/untracked
 819        dir2/modified
 820        dir2/untracked
 821        untracked
 822
 823EOF
 824        test_config status.relativePaths false &&
 825        (cd dir1 && git status) >output &&
 826        test_i18ncmp expect output
 827
 828'
 829
 830cat >expect <<\EOF
 831 M dir1/modified
 832A  dir2/added
 833?? dir1/untracked
 834?? dir2/modified
 835?? dir2/untracked
 836?? untracked
 837EOF
 838
 839test_expect_success 'status -s without relative paths' '
 840
 841        test_config status.relativePaths false &&
 842        (cd dir1 && git status -s) >output &&
 843        test_cmp expect output
 844
 845'
 846
 847test_expect_success 'dry-run of partial commit excluding new file in index' '
 848        cat >expect <<EOF &&
 849On branch master
 850Your branch and '\''upstream'\'' have diverged,
 851and have 1 and 2 different commits each, respectively.
 852  (use "git pull" to merge the remote branch into yours)
 853
 854Changes to be committed:
 855  (use "git reset HEAD <file>..." to unstage)
 856
 857        modified:   dir1/modified
 858
 859Untracked files:
 860  (use "git add <file>..." to include in what will be committed)
 861
 862        dir1/untracked
 863        dir2/
 864        untracked
 865
 866EOF
 867        git commit --dry-run dir1/modified >output &&
 868        test_i18ncmp expect output
 869'
 870
 871cat >expect <<EOF
 872:100644 100644 $EMPTY_BLOB 0000000000000000000000000000000000000000 M   dir1/modified
 873EOF
 874test_expect_success 'status refreshes the index' '
 875        touch dir2/added &&
 876        git status &&
 877        git diff-files >output &&
 878        test_cmp expect output
 879'
 880
 881test_expect_success 'setup status submodule summary' '
 882        test_create_repo sm && (
 883                cd sm &&
 884                >foo &&
 885                git add foo &&
 886                git commit -m "Add foo"
 887        ) &&
 888        git add sm
 889'
 890
 891test_expect_success 'status submodule summary is disabled by default' '
 892        cat >expect <<EOF &&
 893On branch master
 894Your branch and '\''upstream'\'' have diverged,
 895and have 1 and 2 different commits each, respectively.
 896  (use "git pull" to merge the remote branch into yours)
 897
 898Changes to be committed:
 899  (use "git reset HEAD <file>..." to unstage)
 900
 901        new file:   dir2/added
 902        new file:   sm
 903
 904Changes not staged for commit:
 905  (use "git add <file>..." to update what will be committed)
 906  (use "git checkout -- <file>..." to discard changes in working directory)
 907
 908        modified:   dir1/modified
 909
 910Untracked files:
 911  (use "git add <file>..." to include in what will be committed)
 912
 913        dir1/untracked
 914        dir2/modified
 915        dir2/untracked
 916        untracked
 917
 918EOF
 919        git status >output &&
 920        test_i18ncmp expect output
 921'
 922
 923# we expect the same as the previous test
 924test_expect_success 'status --untracked-files=all does not show submodule' '
 925        git status --untracked-files=all >output &&
 926        test_i18ncmp expect output
 927'
 928
 929cat >expect <<EOF
 930 M dir1/modified
 931A  dir2/added
 932A  sm
 933?? dir1/untracked
 934?? dir2/modified
 935?? dir2/untracked
 936?? untracked
 937EOF
 938test_expect_success 'status -s submodule summary is disabled by default' '
 939        git status -s >output &&
 940        test_cmp expect output
 941'
 942
 943# we expect the same as the previous test
 944test_expect_success 'status -s --untracked-files=all does not show submodule' '
 945        git status -s --untracked-files=all >output &&
 946        test_cmp expect output
 947'
 948
 949head=$(cd sm && git rev-parse --short=7 --verify HEAD)
 950
 951test_expect_success 'status submodule summary' '
 952        cat >expect <<EOF &&
 953On branch master
 954Your branch and '\''upstream'\'' have diverged,
 955and have 1 and 2 different commits each, respectively.
 956  (use "git pull" to merge the remote branch into yours)
 957
 958Changes to be committed:
 959  (use "git reset HEAD <file>..." to unstage)
 960
 961        new file:   dir2/added
 962        new file:   sm
 963
 964Changes not staged for commit:
 965  (use "git add <file>..." to update what will be committed)
 966  (use "git checkout -- <file>..." to discard changes in working directory)
 967
 968        modified:   dir1/modified
 969
 970Submodule changes to be committed:
 971
 972* sm 0000000...$head (1):
 973  > Add foo
 974
 975Untracked files:
 976  (use "git add <file>..." to include in what will be committed)
 977
 978        dir1/untracked
 979        dir2/modified
 980        dir2/untracked
 981        untracked
 982
 983EOF
 984        git config status.submodulesummary 10 &&
 985        git status >output &&
 986        test_i18ncmp expect output
 987'
 988
 989test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
 990        strip_comments expect &&
 991        git -c status.displayCommentPrefix=false status >output &&
 992        test_i18ncmp expect output
 993'
 994
 995test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
 996        commit_template_commented
 997'
 998
 999cat >expect <<EOF
1000 M dir1/modified
1001A  dir2/added
1002A  sm
1003?? dir1/untracked
1004?? dir2/modified
1005?? dir2/untracked
1006?? untracked
1007EOF
1008test_expect_success 'status -s submodule summary' '
1009        git status -s >output &&
1010        test_cmp expect output
1011'
1012
1013test_expect_success 'status submodule summary (clean submodule): commit' '
1014        cat >expect <<EOF &&
1015On branch master
1016Your branch and '\''upstream'\'' have diverged,
1017and have 2 and 2 different commits each, respectively.
1018  (use "git pull" to merge the remote branch into yours)
1019
1020Changes not staged for commit:
1021  (use "git add <file>..." to update what will be committed)
1022  (use "git checkout -- <file>..." to discard changes in working directory)
1023
1024        modified:   dir1/modified
1025
1026Untracked files:
1027  (use "git add <file>..." to include in what will be committed)
1028
1029        dir1/untracked
1030        dir2/modified
1031        dir2/untracked
1032        untracked
1033
1034no changes added to commit (use "git add" and/or "git commit -a")
1035EOF
1036        git commit -m "commit submodule" &&
1037        git config status.submodulesummary 10 &&
1038        test_must_fail git commit --dry-run >output &&
1039        test_i18ncmp expect output &&
1040        git status >output &&
1041        test_i18ncmp expect output
1042'
1043
1044cat >expect <<EOF
1045 M dir1/modified
1046?? dir1/untracked
1047?? dir2/modified
1048?? dir2/untracked
1049?? untracked
1050EOF
1051test_expect_success 'status -s submodule summary (clean submodule)' '
1052        git status -s >output &&
1053        test_cmp expect output
1054'
1055
1056test_expect_success 'status -z implies porcelain' '
1057        git status --porcelain |
1058        perl -pe "s/\012/\000/g" >expect &&
1059        git status -z >output &&
1060        test_cmp expect output
1061'
1062
1063test_expect_success 'commit --dry-run submodule summary (--amend)' '
1064        cat >expect <<EOF &&
1065On branch master
1066Your branch and '\''upstream'\'' have diverged,
1067and have 2 and 2 different commits each, respectively.
1068  (use "git pull" to merge the remote branch into yours)
1069
1070Changes to be committed:
1071  (use "git reset HEAD^1 <file>..." to unstage)
1072
1073        new file:   dir2/added
1074        new file:   sm
1075
1076Changes not staged for commit:
1077  (use "git add <file>..." to update what will be committed)
1078  (use "git checkout -- <file>..." to discard changes in working directory)
1079
1080        modified:   dir1/modified
1081
1082Submodule changes to be committed:
1083
1084* sm 0000000...$head (1):
1085  > Add foo
1086
1087Untracked files:
1088  (use "git add <file>..." to include in what will be committed)
1089
1090        dir1/untracked
1091        dir2/modified
1092        dir2/untracked
1093        untracked
1094
1095EOF
1096        git config status.submodulesummary 10 &&
1097        git commit --dry-run --amend >output &&
1098        test_i18ncmp expect output
1099'
1100
1101test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1102        test_when_finished "chmod 775 .git" &&
1103        (
1104                chmod a-w .git &&
1105                # make dir1/tracked stat-dirty
1106                >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1107                git status -s >output &&
1108                ! grep dir1/tracked output &&
1109                # make sure "status" succeeded without writing index out
1110                git diff-files | grep dir1/tracked
1111        )
1112'
1113
1114(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
1115new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1116touch .gitmodules
1117
1118test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1119        cat > expect << EOF &&
1120On branch master
1121Your branch and '\''upstream'\'' have diverged,
1122and have 2 and 2 different commits each, respectively.
1123  (use "git pull" to merge the remote branch into yours)
1124
1125Changes to be committed:
1126  (use "git reset HEAD <file>..." to unstage)
1127
1128        modified:   sm
1129
1130Changes not staged for commit:
1131  (use "git add <file>..." to update what will be committed)
1132  (use "git checkout -- <file>..." to discard changes in working directory)
1133
1134        modified:   dir1/modified
1135
1136Submodule changes to be committed:
1137
1138* sm $head...$new_head (1):
1139  > Add bar
1140
1141Untracked files:
1142  (use "git add <file>..." to include in what will be committed)
1143
1144        .gitmodules
1145        dir1/untracked
1146        dir2/modified
1147        dir2/untracked
1148        untracked
1149
1150EOF
1151        echo modified  sm/untracked &&
1152        git status --ignore-submodules=untracked >output &&
1153        test_i18ncmp expect output
1154'
1155
1156test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
1157        test_config diff.ignoreSubmodules dirty &&
1158        git status >output &&
1159        test_i18ncmp expect output &&
1160        git config --add -f .gitmodules submodule.subname.ignore untracked &&
1161        git config --add -f .gitmodules submodule.subname.path sm &&
1162        git status >output &&
1163        test_i18ncmp expect output &&
1164        git config -f .gitmodules  --remove-section submodule.subname
1165'
1166
1167test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
1168        git config --add -f .gitmodules submodule.subname.ignore none &&
1169        git config --add -f .gitmodules submodule.subname.path sm &&
1170        git config --add submodule.subname.ignore untracked &&
1171        git config --add submodule.subname.path sm &&
1172        git status >output &&
1173        test_i18ncmp expect output &&
1174        git config --remove-section submodule.subname &&
1175        git config --remove-section -f .gitmodules submodule.subname
1176'
1177
1178test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1179        git status --ignore-submodules=dirty >output &&
1180        test_i18ncmp expect output
1181'
1182
1183test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
1184        test_config diff.ignoreSubmodules dirty &&
1185        git status >output &&
1186        ! test -s actual &&
1187        git config --add -f .gitmodules submodule.subname.ignore dirty &&
1188        git config --add -f .gitmodules submodule.subname.path sm &&
1189        git status >output &&
1190        test_i18ncmp expect output &&
1191        git config -f .gitmodules  --remove-section submodule.subname
1192'
1193
1194test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
1195        git config --add -f .gitmodules submodule.subname.ignore none &&
1196        git config --add -f .gitmodules submodule.subname.path sm &&
1197        git config --add submodule.subname.ignore dirty &&
1198        git config --add submodule.subname.path sm &&
1199        git status >output &&
1200        test_i18ncmp expect output &&
1201        git config --remove-section submodule.subname &&
1202        git config -f .gitmodules  --remove-section submodule.subname
1203'
1204
1205test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1206        echo modified >sm/foo &&
1207        git status --ignore-submodules=dirty >output &&
1208        test_i18ncmp expect output
1209'
1210
1211test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
1212        git config --add -f .gitmodules submodule.subname.ignore dirty &&
1213        git config --add -f .gitmodules submodule.subname.path sm &&
1214        git status >output &&
1215        test_i18ncmp expect output &&
1216        git config -f .gitmodules  --remove-section submodule.subname
1217'
1218
1219test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
1220        git config --add -f .gitmodules submodule.subname.ignore none &&
1221        git config --add -f .gitmodules submodule.subname.path sm &&
1222        git config --add submodule.subname.ignore dirty &&
1223        git config --add submodule.subname.path sm &&
1224        git status >output &&
1225        test_i18ncmp expect output &&
1226        git config --remove-section submodule.subname &&
1227        git config -f .gitmodules  --remove-section submodule.subname
1228'
1229
1230test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1231        cat > expect << EOF &&
1232On branch master
1233Your branch and '\''upstream'\'' have diverged,
1234and have 2 and 2 different commits each, respectively.
1235  (use "git pull" to merge the remote branch into yours)
1236
1237Changes to be committed:
1238  (use "git reset HEAD <file>..." to unstage)
1239
1240        modified:   sm
1241
1242Changes not staged for commit:
1243  (use "git add <file>..." to update what will be committed)
1244  (use "git checkout -- <file>..." to discard changes in working directory)
1245  (commit or discard the untracked or modified content in submodules)
1246
1247        modified:   dir1/modified
1248        modified:   sm (modified content)
1249
1250Submodule changes to be committed:
1251
1252* sm $head...$new_head (1):
1253  > Add bar
1254
1255Untracked files:
1256  (use "git add <file>..." to include in what will be committed)
1257
1258        .gitmodules
1259        dir1/untracked
1260        dir2/modified
1261        dir2/untracked
1262        untracked
1263
1264EOF
1265        git status --ignore-submodules=untracked > output &&
1266        test_i18ncmp expect output
1267'
1268
1269test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1270        git config --add -f .gitmodules submodule.subname.ignore untracked &&
1271        git config --add -f .gitmodules submodule.subname.path sm &&
1272        git status >output &&
1273        test_i18ncmp expect output &&
1274        git config -f .gitmodules  --remove-section submodule.subname
1275'
1276
1277test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
1278        git config --add -f .gitmodules submodule.subname.ignore none &&
1279        git config --add -f .gitmodules submodule.subname.path sm &&
1280        git config --add submodule.subname.ignore untracked &&
1281        git config --add submodule.subname.path sm &&
1282        git status >output &&
1283        test_i18ncmp expect output &&
1284        git config --remove-section submodule.subname &&
1285        git config -f .gitmodules  --remove-section submodule.subname
1286'
1287
1288head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1289
1290test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1291        cat > expect << EOF &&
1292On branch master
1293Your branch and '\''upstream'\'' have diverged,
1294and have 2 and 2 different commits each, respectively.
1295  (use "git pull" to merge the remote branch into yours)
1296
1297Changes to be committed:
1298  (use "git reset HEAD <file>..." to unstage)
1299
1300        modified:   sm
1301
1302Changes not staged for commit:
1303  (use "git add <file>..." to update what will be committed)
1304  (use "git checkout -- <file>..." to discard changes in working directory)
1305
1306        modified:   dir1/modified
1307        modified:   sm (new commits)
1308
1309Submodule changes to be committed:
1310
1311* sm $head...$new_head (1):
1312  > Add bar
1313
1314Submodules changed but not updated:
1315
1316* sm $new_head...$head2 (1):
1317  > 2nd commit
1318
1319Untracked files:
1320  (use "git add <file>..." to include in what will be committed)
1321
1322        .gitmodules
1323        dir1/untracked
1324        dir2/modified
1325        dir2/untracked
1326        untracked
1327
1328EOF
1329        git status --ignore-submodules=untracked > output &&
1330        test_i18ncmp expect output
1331'
1332
1333test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
1334        git config --add -f .gitmodules submodule.subname.ignore untracked &&
1335        git config --add -f .gitmodules submodule.subname.path sm &&
1336        git status >output &&
1337        test_i18ncmp expect output &&
1338        git config -f .gitmodules  --remove-section submodule.subname
1339'
1340
1341test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
1342        git config --add -f .gitmodules submodule.subname.ignore none &&
1343        git config --add -f .gitmodules submodule.subname.path sm &&
1344        git config --add submodule.subname.ignore untracked &&
1345        git config --add submodule.subname.path sm &&
1346        git status >output &&
1347        test_i18ncmp expect output &&
1348        git config --remove-section submodule.subname &&
1349        git config -f .gitmodules  --remove-section submodule.subname
1350'
1351
1352test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
1353        git status --ignore-submodules=dirty > output &&
1354        test_i18ncmp expect output
1355'
1356test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
1357        git config --add -f .gitmodules submodule.subname.ignore dirty &&
1358        git config --add -f .gitmodules submodule.subname.path sm &&
1359        git status >output &&
1360        test_i18ncmp expect output &&
1361        git config -f .gitmodules  --remove-section submodule.subname
1362'
1363
1364test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
1365        git config --add -f .gitmodules submodule.subname.ignore none &&
1366        git config --add -f .gitmodules submodule.subname.path sm &&
1367        git config --add submodule.subname.ignore dirty &&
1368        git config --add submodule.subname.path sm &&
1369        git status >output &&
1370        test_i18ncmp expect output &&
1371        git config --remove-section submodule.subname &&
1372        git config -f .gitmodules  --remove-section submodule.subname
1373'
1374
1375cat > expect << EOF
1376; On branch master
1377; Your branch and 'upstream' have diverged,
1378; and have 2 and 2 different commits each, respectively.
1379;   (use "git pull" to merge the remote branch into yours)
1380;
1381; Changes to be committed:
1382;   (use "git reset HEAD <file>..." to unstage)
1383;
1384;       modified:   sm
1385;
1386; Changes not staged for commit:
1387;   (use "git add <file>..." to update what will be committed)
1388;   (use "git checkout -- <file>..." to discard changes in working directory)
1389;
1390;       modified:   dir1/modified
1391;       modified:   sm (new commits)
1392;
1393; Submodule changes to be committed:
1394;
1395; * sm $head...$new_head (1):
1396;   > Add bar
1397;
1398; Submodules changed but not updated:
1399;
1400; * sm $new_head...$head2 (1):
1401;   > 2nd commit
1402;
1403; Untracked files:
1404;   (use "git add <file>..." to include in what will be committed)
1405;
1406;       .gitmodules
1407;       dir1/untracked
1408;       dir2/modified
1409;       dir2/untracked
1410;       untracked
1411;
1412EOF
1413
1414test_expect_success "status (core.commentchar with submodule summary)" '
1415        test_config core.commentchar ";" &&
1416        git -c status.displayCommentPrefix=true status >output &&
1417        test_i18ncmp expect output
1418'
1419
1420test_expect_success "status (core.commentchar with two chars with submodule summary)" '
1421        test_config core.commentchar ";;" &&
1422        test_must_fail git -c status.displayCommentPrefix=true status
1423'
1424
1425test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1426        cat > expect << EOF &&
1427On branch master
1428Your branch and '\''upstream'\'' have diverged,
1429and have 2 and 2 different commits each, respectively.
1430  (use "git pull" to merge the remote branch into yours)
1431
1432Changes not staged for commit:
1433  (use "git add <file>..." to update what will be committed)
1434  (use "git checkout -- <file>..." to discard changes in working directory)
1435
1436        modified:   dir1/modified
1437
1438Untracked files:
1439  (use "git add <file>..." to include in what will be committed)
1440
1441        .gitmodules
1442        dir1/untracked
1443        dir2/modified
1444        dir2/untracked
1445        untracked
1446
1447no changes added to commit (use "git add" and/or "git commit -a")
1448EOF
1449        git status --ignore-submodules=all > output &&
1450        test_i18ncmp expect output
1451'
1452
1453test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1454        cat > expect << EOF &&
1455On branch master
1456Your branch and '\''upstream'\'' have diverged,
1457and have 2 and 2 different commits each, respectively.
1458  (use "git pull" to merge the remote branch into yours)
1459
1460Changes to be committed:
1461  (use "git reset HEAD <file>..." to unstage)
1462
1463        modified:   sm
1464
1465Changes not staged for commit:
1466  (use "git add <file>..." to update what will be committed)
1467  (use "git checkout -- <file>..." to discard changes in working directory)
1468
1469        modified:   dir1/modified
1470
1471Untracked files:
1472  (use "git add <file>..." to include in what will be committed)
1473
1474        .gitmodules
1475        dir1/untracked
1476        dir2/modified
1477        dir2/untracked
1478        untracked
1479
1480EOF
1481        git config --add -f .gitmodules submodule.subname.ignore all &&
1482        git config --add -f .gitmodules submodule.subname.path sm &&
1483        git status > output &&
1484        test_i18ncmp expect output &&
1485        git config -f .gitmodules  --remove-section submodule.subname
1486'
1487
1488test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
1489        git config --add -f .gitmodules submodule.subname.ignore none &&
1490        git config --add -f .gitmodules submodule.subname.path sm &&
1491        git config --add submodule.subname.ignore all &&
1492        git config --add submodule.subname.path sm &&
1493        git status > output &&
1494        test_i18ncmp expect output &&
1495        git config --remove-section submodule.subname &&
1496        git config -f .gitmodules  --remove-section submodule.subname
1497'
1498
1499test_expect_success 'setup of test environment' '
1500        git config status.showUntrackedFiles no &&
1501        git status -s >expected_short &&
1502        git status --no-short >expected_noshort
1503'
1504
1505test_expect_success '"status.short=true" same as "-s"' '
1506        git -c status.short=true status >actual &&
1507        test_cmp expected_short actual
1508'
1509
1510test_expect_success '"status.short=true" weaker than "--no-short"' '
1511        git -c status.short=true status --no-short >actual &&
1512        test_cmp expected_noshort actual
1513'
1514
1515test_expect_success '"status.short=false" same as "--no-short"' '
1516        git -c status.short=false status >actual &&
1517        test_cmp expected_noshort actual
1518'
1519
1520test_expect_success '"status.short=false" weaker than "-s"' '
1521        git -c status.short=false status -s >actual &&
1522        test_cmp expected_short actual
1523'
1524
1525test_expect_success '"status.branch=true" same as "-b"' '
1526        git status -sb >expected_branch &&
1527        git -c status.branch=true status -s >actual &&
1528        test_cmp expected_branch actual
1529'
1530
1531test_expect_success '"status.branch=true" different from "--no-branch"' '
1532        git status -s --no-branch  >expected_nobranch &&
1533        git -c status.branch=true status -s >actual &&
1534        test_must_fail test_cmp expected_nobranch actual
1535'
1536
1537test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1538        git -c status.branch=true status -s --no-branch >actual &&
1539        test_cmp expected_nobranch actual
1540'
1541
1542test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1543       git -c status.branch=true status --porcelain >actual &&
1544       test_cmp expected_nobranch actual
1545'
1546
1547test_expect_success '"status.branch=false" same as "--no-branch"' '
1548        git -c status.branch=false status -s >actual &&
1549        test_cmp expected_nobranch actual
1550'
1551
1552test_expect_success '"status.branch=false" weaker than "-b"' '
1553        git -c status.branch=false status -sb >actual &&
1554        test_cmp expected_branch actual
1555'
1556
1557test_expect_success 'Restore default test environment' '
1558        git config --unset status.showUntrackedFiles
1559'
1560
1561test_expect_success 'git commit will commit a staged but ignored submodule' '
1562        git config --add -f .gitmodules submodule.subname.ignore all &&
1563        git config --add -f .gitmodules submodule.subname.path sm &&
1564        git config --add submodule.subname.ignore all &&
1565        git status -s --ignore-submodules=dirty >output &&
1566        test_i18ngrep "^M. sm" output &&
1567        GIT_EDITOR="echo hello >>\"\$1\"" &&
1568        export GIT_EDITOR &&
1569        git commit -uno &&
1570        git status -s --ignore-submodules=dirty >output &&
1571        test_i18ngrep ! "^M. sm" output
1572'
1573
1574test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
1575        git reset HEAD^ &&
1576        git add sm &&
1577        cat >expect << EOF &&
1578On branch master
1579Your branch and '\''upstream'\'' have diverged,
1580and have 2 and 2 different commits each, respectively.
1581  (use "git pull" to merge the remote branch into yours)
1582
1583Changes to be committed:
1584  (use "git reset HEAD <file>..." to unstage)
1585
1586        modified:   sm
1587
1588Changes not staged for commit:
1589  (use "git add <file>..." to update what will be committed)
1590  (use "git checkout -- <file>..." to discard changes in working directory)
1591
1592        modified:   dir1/modified
1593
1594Untracked files not listed (use -u option to show untracked files)
1595EOF
1596        git commit -uno --dry-run >output &&
1597        test_i18ncmp expect output &&
1598        git status -s --ignore-submodules=dirty >output &&
1599        test_i18ngrep "^M. sm" output
1600'
1601
1602test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1603        git commit -uno -m message &&
1604        git status -s --ignore-submodules=dirty >output &&
1605        test_i18ngrep ! "^M. sm" output &&
1606        git config --remove-section submodule.subname &&
1607        git config -f .gitmodules  --remove-section submodule.subname
1608'
1609
1610test_expect_success 'show stash info with "--show-stash"' '
1611        git reset --hard &&
1612        git stash clear &&
1613        echo 1 >file &&
1614        git add file &&
1615        git stash &&
1616        git status >expected_default &&
1617        git status --show-stash >expected_with_stash &&
1618        test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
1619'
1620
1621test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
1622        git status --show-stash --no-show-stash >expected_without_stash &&
1623        test_cmp expected_default expected_without_stash
1624'
1625
1626test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
1627        git -c status.showStash=false status --show-stash >actual &&
1628        test_cmp expected_with_stash actual
1629'
1630
1631test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
1632        git -c status.showStash=true status --no-show-stash >actual &&
1633        test_cmp expected_without_stash actual
1634'
1635
1636test_expect_success 'no additionnal info if no stash entries' '
1637        git stash clear &&
1638        git -c status.showStash=true status >actual &&
1639        test_cmp expected_without_stash actual
1640'
1641
1642test_expect_success '"No commits yet" should be noted in status output' '
1643        git checkout --orphan empty-branch-1 &&
1644        git status >output &&
1645        test_i18ngrep "No commits yet" output
1646'
1647
1648test_expect_success '"No commits yet" should not be noted in status output' '
1649        git checkout --orphan empty-branch-2 &&
1650        test_commit test-commit-1 &&
1651        git status >output &&
1652        test_i18ngrep ! "No commits yet" output
1653'
1654
1655test_expect_success '"Initial commit" should be noted in commit template' '
1656        git checkout --orphan empty-branch-3 &&
1657        touch to_be_committed_1 &&
1658        git add to_be_committed_1 &&
1659        git commit --dry-run >output &&
1660        test_i18ngrep "Initial commit" output
1661'
1662
1663test_expect_success '"Initial commit" should not be noted in commit template' '
1664        git checkout --orphan empty-branch-4 &&
1665        test_commit test-commit-2 &&
1666        touch to_be_committed_2 &&
1667        git add to_be_committed_2 &&
1668        git commit --dry-run >output &&
1669        test_i18ngrep ! "Initial commit" output
1670'
1671
1672test_expect_success '--no-optional-locks prevents index update' '
1673        test-tool chmtime =1234567890 .git/index &&
1674        git --no-optional-locks status &&
1675        test-tool chmtime --get .git/index >out &&
1676        grep ^1234567890 out &&
1677        git status &&
1678        test-tool chmtime --get .git/index >out &&
1679        ! grep ^1234567890 out
1680'
1681
1682test_done