3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git status'
10 test_expect_success 'status -h in broken repository' '
12 test_when_finished "rm -fr broken" &&
16 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
17 test_expect_code 129 git status -h >usage 2>&1
19 grep "[Uu]sage" broken/usage
22 test_expect_success 'commit -h in broken repository' '
24 test_when_finished "rm -fr broken" &&
28 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
29 test_expect_code 129 git commit -h >usage 2>&1
31 grep "[Uu]sage" broken/usage
34 test_expect_success 'setup' '
48 git commit -m initial &&
52 echo 1 >dir1/modified &&
53 echo 2 >dir2/modified &&
58 test_expect_success 'status (1)' '
60 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
66 # Changes to be committed:
67 # (use "git reset HEAD <file>..." to unstage)
69 # new file: dir2/added
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)
75 # modified: dir1/modified
78 # (use "git add <file>..." to include in what will be committed)
88 test_expect_success 'status (2)' '
91 test_cmp expect output
97 # Changes to be committed:
98 # new file: dir2/added
100 # Changes not staged for commit:
101 # modified: dir1/modified
112 git config advice.statusHints false
114 test_expect_success 'status (advice.statusHints false)' '
116 git status >output &&
117 test_cmp expect output
121 git config --unset advice.statusHints
134 test_expect_success 'status -s' '
136 git status -s >output &&
137 test_cmp expect output
153 test_expect_success 'status -s -b' '
155 git status -s -b >output &&
156 test_cmp expect output
162 # Changes to be committed:
163 # (use "git reset HEAD <file>..." to unstage)
165 # new file: dir2/added
167 # Changes not staged for commit:
168 # (use "git add <file>..." to update what will be committed)
169 # (use "git checkout -- <file>..." to discard changes in working directory)
171 # modified: dir1/modified
173 # Untracked files not listed (use -u option to show untracked files)
175 test_expect_success 'status -uno' '
177 : >dir3/untracked1 &&
178 : >dir3/untracked2 &&
179 git status -uno >output &&
180 test_cmp expect output
183 test_expect_success 'status (status.showUntrackedFiles no)' '
184 git config status.showuntrackedfiles no
185 git status >output &&
186 test_cmp expect output
191 # Changes to be committed:
192 # new file: dir2/added
194 # Changes not staged for commit:
195 # modified: dir1/modified
197 # Untracked files not listed
199 git config advice.statusHints false
200 test_expect_success 'status -uno (advice.statusHints false)' '
201 git status -uno >output &&
202 test_cmp expect output
204 git config --unset advice.statusHints
210 test_expect_success 'status -s -uno' '
211 git config --unset status.showuntrackedfiles
212 git status -s -uno >output &&
213 test_cmp expect output
216 test_expect_success 'status -s (status.showUntrackedFiles no)' '
217 git config status.showuntrackedfiles no
218 git status -s >output &&
219 test_cmp expect output
224 # Changes to be committed:
225 # (use "git reset HEAD <file>..." to unstage)
227 # new file: dir2/added
229 # Changes not staged for commit:
230 # (use "git add <file>..." to update what will be committed)
231 # (use "git checkout -- <file>..." to discard changes in working directory)
233 # modified: dir1/modified
236 # (use "git add <file>..." to include in what will be committed)
246 test_expect_success 'status -unormal' '
247 git status -unormal >output &&
248 test_cmp expect output
251 test_expect_success 'status (status.showUntrackedFiles normal)' '
252 git config status.showuntrackedfiles normal
253 git status >output &&
254 test_cmp expect output
268 test_expect_success 'status -s -unormal' '
269 git config --unset status.showuntrackedfiles
270 git status -s -unormal >output &&
271 test_cmp expect output
274 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
275 git config status.showuntrackedfiles normal
276 git status -s >output &&
277 test_cmp expect output
282 # Changes to be committed:
283 # (use "git reset HEAD <file>..." to unstage)
285 # new file: dir2/added
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)
291 # modified: dir1/modified
294 # (use "git add <file>..." to include in what will be committed)
305 test_expect_success 'status -uall' '
306 git status -uall >output &&
307 test_cmp expect output
309 test_expect_success 'status (status.showUntrackedFiles all)' '
310 git config status.showuntrackedfiles all
311 git status >output &&
313 git config --unset status.showuntrackedfiles &&
314 test_cmp expect output
327 test_expect_success 'status -s -uall' '
328 git config --unset status.showuntrackedfiles
329 git status -s -uall >output &&
330 test_cmp expect output
332 test_expect_success 'status -s (status.showUntrackedFiles all)' '
333 git config status.showuntrackedfiles all
334 git status -s >output &&
336 git config --unset status.showuntrackedfiles &&
337 test_cmp expect output
342 # Changes to be committed:
343 # (use "git reset HEAD <file>..." to unstage)
345 # new file: ../dir2/added
347 # Changes not staged for commit:
348 # (use "git add <file>..." to update what will be committed)
349 # (use "git checkout -- <file>..." to discard changes in working directory)
354 # (use "git add <file>..." to include in what will be committed)
364 test_expect_success 'status with relative paths' '
366 (cd dir1 && git status) >output &&
367 test_cmp expect output
381 test_expect_success 'status -s with relative paths' '
383 (cd dir1 && git status -s) >output &&
384 test_cmp expect output
399 test_expect_success 'status --porcelain ignores relative paths setting' '
401 (cd dir1 && git status --porcelain) >output &&
402 test_cmp expect output
406 test_expect_success 'setup unique colors' '
408 git config status.color.untracked blue
414 # Changes to be committed:
415 # (use "git reset HEAD <file>..." to unstage)
417 # <GREEN>new file: dir2/added<RESET>
419 # Changes not staged for commit:
420 # (use "git add <file>..." to update what will be committed)
421 # (use "git checkout -- <file>..." to discard changes in working directory)
423 # <RED>modified: dir1/modified<RESET>
426 # (use "git add <file>..." to include in what will be committed)
428 # <BLUE>dir1/untracked<RESET>
429 # <BLUE>dir2/modified<RESET>
430 # <BLUE>dir2/untracked<RESET>
431 # <BLUE>expect<RESET>
432 # <BLUE>output<RESET>
433 # <BLUE>untracked<RESET>
436 test_expect_success 'status with color.ui' '
438 git config color.ui always &&
439 git status | test_decode_color >output &&
440 test_cmp expect output
444 test_expect_success 'status with color.status' '
446 git config --unset color.ui &&
447 git config color.status always &&
448 git status | test_decode_color >output &&
449 test_cmp expect output
454 <RED>M<RESET> dir1/modified
455 <GREEN>A<RESET> dir2/added
456 <BLUE>??<RESET> dir1/untracked
457 <BLUE>??<RESET> dir2/modified
458 <BLUE>??<RESET> dir2/untracked
459 <BLUE>??<RESET> expect
460 <BLUE>??<RESET> output
461 <BLUE>??<RESET> untracked
464 test_expect_success 'status -s with color.ui' '
466 git config --unset color.status &&
467 git config color.ui always &&
468 git status -s | test_decode_color >output &&
469 test_cmp expect output
473 test_expect_success 'status -s with color.status' '
475 git config --unset color.ui &&
476 git config color.status always &&
477 git status -s | test_decode_color >output &&
478 test_cmp expect output
483 ## <GREEN>master<RESET>
484 <RED>M<RESET> dir1/modified
485 <GREEN>A<RESET> dir2/added
486 <BLUE>??<RESET> dir1/untracked
487 <BLUE>??<RESET> dir2/modified
488 <BLUE>??<RESET> dir2/untracked
489 <BLUE>??<RESET> expect
490 <BLUE>??<RESET> output
491 <BLUE>??<RESET> untracked
494 test_expect_success 'status -s -b with color.status' '
496 git status -s -b | test_decode_color >output &&
497 test_cmp expect output
512 test_expect_success 'status --porcelain ignores color.ui' '
514 git config --unset color.status &&
515 git config color.ui always &&
516 git status --porcelain | test_decode_color >output &&
517 test_cmp expect output
521 test_expect_success 'status --porcelain ignores color.status' '
523 git config --unset color.ui &&
524 git config color.status always &&
525 git status --porcelain | test_decode_color >output &&
526 test_cmp expect output
530 # recover unconditionally from color tests
531 git config --unset color.status
532 git config --unset color.ui
534 test_expect_success 'status --porcelain ignores -b' '
536 git status --porcelain -b >output &&
537 test_cmp expect output
543 # Changes to be committed:
544 # (use "git reset HEAD <file>..." to unstage)
546 # new file: dir2/added
548 # Changes not staged for commit:
549 # (use "git add <file>..." to update what will be committed)
550 # (use "git checkout -- <file>..." to discard changes in working directory)
552 # modified: dir1/modified
555 # (use "git add <file>..." to include in what will be committed)
566 test_expect_success 'status without relative paths' '
568 git config status.relativePaths false
569 (cd dir1 && git status) >output &&
570 test_cmp expect output
585 test_expect_success 'status -s without relative paths' '
587 (cd dir1 && git status -s) >output &&
588 test_cmp expect output
594 # Changes to be committed:
595 # (use "git reset HEAD <file>..." to unstage)
597 # modified: dir1/modified
600 # (use "git add <file>..." to include in what will be committed)
608 test_expect_success 'dry-run of partial commit excluding new file in index' '
609 git commit --dry-run dir1/modified >output &&
610 test_cmp expect output
614 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
616 test_expect_success 'status refreshes the index' '
619 git diff-files >output &&
620 test_cmp expect output
623 test_expect_success 'setup status submodule summary' '
624 test_create_repo sm && (
628 git commit -m "Add foo"
635 # Changes to be committed:
636 # (use "git reset HEAD <file>..." to unstage)
638 # new file: dir2/added
641 # Changes not staged for commit:
642 # (use "git add <file>..." to update what will be committed)
643 # (use "git checkout -- <file>..." to discard changes in working directory)
645 # modified: dir1/modified
648 # (use "git add <file>..." to include in what will be committed)
657 test_expect_success 'status submodule summary is disabled by default' '
658 git status >output &&
659 test_cmp expect output
662 # we expect the same as the previous test
663 test_expect_success 'status --untracked-files=all does not show submodule' '
664 git status --untracked-files=all >output &&
665 test_cmp expect output
679 test_expect_success 'status -s submodule summary is disabled by default' '
680 git status -s >output &&
681 test_cmp expect output
684 # we expect the same as the previous test
685 test_expect_success 'status -s --untracked-files=all does not show submodule' '
686 git status -s --untracked-files=all >output &&
687 test_cmp expect output
690 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
694 # Changes to be committed:
695 # (use "git reset HEAD <file>..." to unstage)
697 # new file: dir2/added
700 # Changes not staged for commit:
701 # (use "git add <file>..." to update what will be committed)
702 # (use "git checkout -- <file>..." to discard changes in working directory)
704 # modified: dir1/modified
706 # Submodule changes to be committed:
708 # * sm 0000000...$head (1):
712 # (use "git add <file>..." to include in what will be committed)
721 test_expect_success 'status submodule summary' '
722 git config status.submodulesummary 10 &&
723 git status >output &&
724 test_cmp expect output
738 test_expect_success 'status -s submodule summary' '
739 git status -s >output &&
740 test_cmp expect output
745 # Changes not staged for commit:
746 # (use "git add <file>..." to update what will be committed)
747 # (use "git checkout -- <file>..." to discard changes in working directory)
749 # modified: dir1/modified
752 # (use "git add <file>..." to include in what will be committed)
760 no changes added to commit (use "git add" and/or "git commit -a")
762 test_expect_success 'status submodule summary (clean submodule)' '
763 git commit -m "commit submodule" &&
764 git config status.submodulesummary 10 &&
765 test_must_fail git commit --dry-run >output &&
766 test_cmp expect output &&
767 git status >output &&
768 test_cmp expect output
780 test_expect_success 'status -s submodule summary (clean submodule)' '
781 git status -s >output &&
782 test_cmp expect output
787 # Changes to be committed:
788 # (use "git reset HEAD^1 <file>..." to unstage)
790 # new file: dir2/added
793 # Changes not staged for commit:
794 # (use "git add <file>..." to update what will be committed)
795 # (use "git checkout -- <file>..." to discard changes in working directory)
797 # modified: dir1/modified
799 # Submodule changes to be committed:
801 # * sm 0000000...$head (1):
805 # (use "git add <file>..." to include in what will be committed)
814 test_expect_success 'commit --dry-run submodule summary (--amend)' '
815 git config status.submodulesummary 10 &&
816 git commit --dry-run --amend >output &&
817 test_cmp expect output
820 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
823 # make dir1/tracked stat-dirty
824 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
825 git status -s >output &&
826 ! grep dir1/tracked output &&
827 # make sure "status" succeeded without writing index out
828 git diff-files | grep dir1/tracked
835 (cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
836 new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
841 # Changes to be committed:
842 # (use "git reset HEAD <file>..." to unstage)
846 # Changes not staged for commit:
847 # (use "git add <file>..." to update what will be committed)
848 # (use "git checkout -- <file>..." to discard changes in working directory)
850 # modified: dir1/modified
852 # Submodule changes to be committed:
854 # * sm $head...$new_head (1):
858 # (use "git add <file>..." to include in what will be committed)
869 test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
870 echo modified > sm/untracked &&
871 git status --ignore-submodules=untracked > output &&
872 test_cmp expect output
875 test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
876 git config diff.ignoreSubmodules dirty &&
877 git status >output &&
878 test_cmp expect output &&
879 git config --add -f .gitmodules submodule.subname.ignore untracked &&
880 git config --add -f .gitmodules submodule.subname.path sm &&
881 git status > output &&
882 test_cmp expect output &&
883 git config -f .gitmodules --remove-section submodule.subname &&
884 git config --unset diff.ignoreSubmodules
887 test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
888 git config --add -f .gitmodules submodule.subname.ignore none &&
889 git config --add -f .gitmodules submodule.subname.path sm &&
890 git config --add submodule.subname.ignore untracked &&
891 git config --add submodule.subname.path sm &&
892 git status > output &&
893 test_cmp expect output &&
894 git config --remove-section submodule.subname &&
895 git config --remove-section -f .gitmodules submodule.subname
898 test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
899 git status --ignore-submodules=dirty > output &&
900 test_cmp expect output
903 test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
904 git config diff.ignoreSubmodules dirty &&
905 git status >output &&
907 git config --add -f .gitmodules submodule.subname.ignore dirty &&
908 git config --add -f .gitmodules submodule.subname.path sm &&
909 git status > output &&
910 test_cmp expect output &&
911 git config -f .gitmodules --remove-section submodule.subname &&
912 git config --unset diff.ignoreSubmodules
915 test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
916 git config --add -f .gitmodules submodule.subname.ignore none &&
917 git config --add -f .gitmodules submodule.subname.path sm &&
918 git config --add submodule.subname.ignore dirty &&
919 git config --add submodule.subname.path sm &&
920 git status > output &&
921 test_cmp expect output &&
922 git config --remove-section submodule.subname &&
923 git config -f .gitmodules --remove-section submodule.subname
926 test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
927 echo modified > sm/foo &&
928 git status --ignore-submodules=dirty > output &&
929 test_cmp expect output
932 test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
933 git config --add -f .gitmodules submodule.subname.ignore dirty &&
934 git config --add -f .gitmodules submodule.subname.path sm &&
935 git status > output &&
936 test_cmp expect output &&
937 git config -f .gitmodules --remove-section submodule.subname
940 test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
941 git config --add -f .gitmodules submodule.subname.ignore none &&
942 git config --add -f .gitmodules submodule.subname.path sm &&
943 git config --add submodule.subname.ignore dirty &&
944 git config --add submodule.subname.path sm &&
945 git status > output &&
946 test_cmp expect output &&
947 git config --remove-section submodule.subname &&
948 git config -f .gitmodules --remove-section submodule.subname
953 # Changes to be committed:
954 # (use "git reset HEAD <file>..." to unstage)
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 # (commit or discard the untracked or modified content in submodules)
963 # modified: dir1/modified
964 # modified: sm (modified content)
966 # Submodule changes to be committed:
968 # * sm $head...$new_head (1):
972 # (use "git add <file>..." to include in what will be committed)
983 test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
984 git status --ignore-submodules=untracked > output &&
985 test_cmp expect output
988 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
989 git config --add -f .gitmodules submodule.subname.ignore untracked &&
990 git config --add -f .gitmodules submodule.subname.path sm &&
991 git status > output &&
992 test_cmp expect output &&
993 git config -f .gitmodules --remove-section submodule.subname
996 test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
997 git config --add -f .gitmodules submodule.subname.ignore none &&
998 git config --add -f .gitmodules submodule.subname.path sm &&
999 git config --add submodule.subname.ignore untracked &&
1000 git config --add submodule.subname.path sm &&
1001 git status > output &&
1002 test_cmp expect output &&
1003 git config --remove-section submodule.subname &&
1004 git config -f .gitmodules --remove-section submodule.subname
1007 head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1011 # Changes to be committed:
1012 # (use "git reset HEAD <file>..." to unstage)
1016 # Changes not staged for commit:
1017 # (use "git add <file>..." to update what will be committed)
1018 # (use "git checkout -- <file>..." to discard changes in working directory)
1020 # modified: dir1/modified
1021 # modified: sm (new commits)
1023 # Submodule changes to be committed:
1025 # * sm $head...$new_head (1):
1028 # Submodules changed but not updated:
1030 # * sm $new_head...$head2 (1):
1034 # (use "git add <file>..." to include in what will be committed)
1045 test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1046 git status --ignore-submodules=untracked > output &&
1047 test_cmp expect output
1050 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
1051 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1052 git config --add -f .gitmodules submodule.subname.path sm &&
1053 git status > output &&
1054 test_cmp expect output &&
1055 git config -f .gitmodules --remove-section submodule.subname
1058 test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
1059 git config --add -f .gitmodules submodule.subname.ignore none &&
1060 git config --add -f .gitmodules submodule.subname.path sm &&
1061 git config --add submodule.subname.ignore untracked &&
1062 git config --add submodule.subname.path sm &&
1063 git status > output &&
1064 test_cmp expect output &&
1065 git config --remove-section submodule.subname &&
1066 git config -f .gitmodules --remove-section submodule.subname
1069 test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
1070 git status --ignore-submodules=dirty > output &&
1071 test_cmp expect output
1073 test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
1074 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1075 git config --add -f .gitmodules submodule.subname.path sm &&
1076 git status > output &&
1077 test_cmp expect output &&
1078 git config -f .gitmodules --remove-section submodule.subname
1081 test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
1082 git config --add -f .gitmodules submodule.subname.ignore none &&
1083 git config --add -f .gitmodules submodule.subname.path sm &&
1084 git config --add submodule.subname.ignore dirty &&
1085 git config --add submodule.subname.path sm &&
1086 git status > output &&
1087 test_cmp expect output &&
1088 git config --remove-section submodule.subname &&
1089 git config -f .gitmodules --remove-section submodule.subname
1094 # Changes not staged for commit:
1095 # (use "git add <file>..." to update what will be committed)
1096 # (use "git checkout -- <file>..." to discard changes in working directory)
1098 # modified: dir1/modified
1101 # (use "git add <file>..." to include in what will be committed)
1110 no changes added to commit (use "git add" and/or "git commit -a")
1113 test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1114 git status --ignore-submodules=all > output &&
1115 test_cmp expect output
1118 test_expect_failure '.gitmodules ignore=all suppresses submodule summary' '
1119 git config --add -f .gitmodules submodule.subname.ignore all &&
1120 git config --add -f .gitmodules submodule.subname.path sm &&
1121 git status > output &&
1122 test_cmp expect output &&
1123 git config -f .gitmodules --remove-section submodule.subname
1126 test_expect_failure '.git/config ignore=all suppresses submodule summary' '
1127 git config --add -f .gitmodules submodule.subname.ignore none &&
1128 git config --add -f .gitmodules submodule.subname.path sm &&
1129 git config --add submodule.subname.ignore all &&
1130 git config --add submodule.subname.path sm &&
1131 git status > output &&
1132 test_cmp expect output &&
1133 git config --remove-section submodule.subname &&
1134 git config -f .gitmodules --remove-section submodule.subname