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