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