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