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