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