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