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 test_i18ngrep "[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 test_i18ngrep "[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)' '
59 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
64 # Changes to be committed:
65 # (use "git reset HEAD <file>..." to unstage)
67 # new file: dir2/added
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)
73 # modified: dir1/modified
76 # (use "git add <file>..." to include in what will be committed)
86 test_expect_success
'status (2)' '
88 test_i18ncmp expect output
93 # Changes to be committed:
94 # new file: dir2/added
96 # Changes not staged for commit:
97 # modified: dir1/modified
108 test_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
127 test_expect_success
'status -s' '
129 git status -s >output &&
130 test_cmp expect output
146 test_expect_success
'status -s -b' '
148 git status -s -b >output &&
149 test_cmp expect output
153 test_expect_success
'setup dir3' '
155 : >dir3/untracked1 &&
161 # Changes to be committed:
162 # (use "git reset HEAD <file>..." to unstage)
164 # new file: dir2/added
166 # Changes not staged for commit:
167 # (use "git add <file>..." to update what will be committed)
168 # (use "git checkout -- <file>..." to discard changes in working directory)
170 # modified: dir1/modified
172 # Untracked files not listed (use -u option to show untracked files)
174 test_expect_success
'status -uno' '
175 git status -uno >output &&
176 test_i18ncmp expect output
179 test_expect_success
'status (status.showUntrackedFiles no)' '
180 git config status.showuntrackedfiles no
181 test_when_finished "git config --unset status.showuntrackedfiles" &&
182 git status >output &&
183 test_i18ncmp expect output
188 # Changes to be committed:
189 # new file: dir2/added
191 # Changes not staged for commit:
192 # modified: dir1/modified
194 # Untracked files not listed
196 git config advice.statusHints false
197 test_expect_success
'status -uno (advice.statusHints false)' '
198 git status -uno >output &&
199 test_i18ncmp expect output
201 git config
--unset advice.statusHints
207 test_expect_success
'status -s -uno' '
208 git status -s -uno >output &&
209 test_cmp expect output
212 test_expect_success
'status -s (status.showUntrackedFiles no)' '
213 git config status.showuntrackedfiles no
214 git status -s >output &&
215 test_cmp expect output
220 # Changes to be committed:
221 # (use "git reset HEAD <file>..." to unstage)
223 # new file: dir2/added
225 # Changes not staged for commit:
226 # (use "git add <file>..." to update what will be committed)
227 # (use "git checkout -- <file>..." to discard changes in working directory)
229 # modified: dir1/modified
232 # (use "git add <file>..." to include in what will be committed)
242 test_expect_success
'status -unormal' '
243 git status -unormal >output &&
244 test_i18ncmp expect output
247 test_expect_success
'status (status.showUntrackedFiles normal)' '
248 git config status.showuntrackedfiles normal
249 test_when_finished "git config --unset status.showuntrackedfiles" &&
250 git status >output &&
251 test_i18ncmp expect output
265 test_expect_success
'status -s -unormal' '
266 git status -s -unormal >output &&
267 test_cmp expect output
270 test_expect_success
'status -s (status.showUntrackedFiles normal)' '
271 git config status.showuntrackedfiles normal
272 git status -s >output &&
273 test_cmp expect output
278 # Changes to be committed:
279 # (use "git reset HEAD <file>..." to unstage)
281 # new file: dir2/added
283 # Changes not staged for commit:
284 # (use "git add <file>..." to update what will be committed)
285 # (use "git checkout -- <file>..." to discard changes in working directory)
287 # modified: dir1/modified
290 # (use "git add <file>..." to include in what will be committed)
301 test_expect_success
'status -uall' '
302 git status -uall >output &&
303 test_i18ncmp expect output
306 test_expect_success
'status (status.showUntrackedFiles all)' '
307 git config status.showuntrackedfiles all
308 test_when_finished "git config --unset status.showuntrackedfiles" &&
309 git status >output &&
310 test_i18ncmp expect output
313 test_expect_success
'teardown dir3' '
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' '
365 (cd dir1 && git status) >output &&
366 test_i18ncmp expect output
379 test_expect_success
'status -s with relative paths' '
381 (cd dir1 && git status -s) >output &&
382 test_cmp expect output
397 test_expect_success
'status --porcelain ignores relative paths setting' '
399 (cd dir1 && git status --porcelain) >output &&
400 test_cmp expect output
404 test_expect_success
'setup unique colors' '
406 git config status.color.untracked blue &&
407 git config status.color.branch green
412 # On branch <GREEN>master<RESET>
413 # Changes to be committed:
414 # (use "git reset HEAD <file>..." to unstage)
416 # <GREEN>new file: dir2/added<RESET>
418 # Changes not staged for commit:
419 # (use "git add <file>..." to update what will be committed)
420 # (use "git checkout -- <file>..." to discard changes in working directory)
422 # <RED>modified: dir1/modified<RESET>
425 # (use "git add <file>..." to include in what will be committed)
427 # <BLUE>dir1/untracked<RESET>
428 # <BLUE>dir2/modified<RESET>
429 # <BLUE>dir2/untracked<RESET>
430 # <BLUE>expect<RESET>
431 # <BLUE>output<RESET>
432 # <BLUE>untracked<RESET>
435 test_expect_success
'status with color.ui' '
436 git config color.ui always &&
437 test_when_finished "git config --unset color.ui" &&
438 git status | test_decode_color >output &&
439 test_i18ncmp expect output
442 test_expect_success
'status with color.status' '
443 git config color.status always &&
444 test_when_finished "git config --unset color.status" &&
445 git status | test_decode_color >output &&
446 test_i18ncmp expect output
450 <RED
>M
<RESET
> dir
1/modified
451 <GREEN
>A
<RESET
> dir
2/added
452 <BLUE
>??
<RESET
> dir
1/untracked
453 <BLUE
>??
<RESET
> dir
2/modified
454 <BLUE
>??
<RESET
> dir
2/untracked
455 <BLUE
>??
<RESET
> expect
456 <BLUE
>??
<RESET
> output
457 <BLUE
>??
<RESET
> untracked
460 test_expect_success
'status -s with color.ui' '
462 git config color.ui always &&
463 git status -s | test_decode_color >output &&
464 test_cmp expect output
468 test_expect_success
'status -s with color.status' '
470 git config --unset color.ui &&
471 git config color.status always &&
472 git status -s | test_decode_color >output &&
473 test_cmp expect output
478 ## <GREEN>master<RESET>
479 <RED
>M
<RESET
> dir
1/modified
480 <GREEN
>A
<RESET
> dir
2/added
481 <BLUE
>??
<RESET
> dir
1/untracked
482 <BLUE
>??
<RESET
> dir
2/modified
483 <BLUE
>??
<RESET
> dir
2/untracked
484 <BLUE
>??
<RESET
> expect
485 <BLUE
>??
<RESET
> output
486 <BLUE
>??
<RESET
> untracked
489 test_expect_success
'status -s -b with color.status' '
491 git status -s -b | test_decode_color >output &&
492 test_cmp expect output
507 test_expect_success
'status --porcelain ignores color.ui' '
509 git config --unset color.status &&
510 git config color.ui always &&
511 git status --porcelain | test_decode_color >output &&
512 test_cmp expect output
516 test_expect_success
'status --porcelain ignores color.status' '
518 git config --unset color.ui &&
519 git config color.status always &&
520 git status --porcelain | test_decode_color >output &&
521 test_cmp expect output
525 # recover unconditionally from color tests
526 git config
--unset color.status
527 git config
--unset color.ui
529 test_expect_success
'status --porcelain ignores -b' '
531 git status --porcelain -b >output &&
532 test_cmp expect output
538 # Changes to be committed:
539 # (use "git reset HEAD <file>..." to unstage)
541 # new file: dir2/added
543 # Changes not staged for commit:
544 # (use "git add <file>..." to update what will be committed)
545 # (use "git checkout -- <file>..." to discard changes in working directory)
547 # modified: dir1/modified
550 # (use "git add <file>..." to include in what will be committed)
561 test_expect_success
'status without relative paths' '
563 git config status.relativePaths false &&
564 test_when_finished "git config --unset status.relativePaths" &&
565 (cd dir1 && git status) >output &&
566 test_i18ncmp expect output
581 test_expect_success
'status -s without relative paths' '
583 git config status.relativePaths false &&
584 test_when_finished "git config --unset status.relativePaths" &&
585 (cd dir1 && git status -s) >output &&
586 test_cmp expect output
592 # Changes to be committed:
593 # (use "git reset HEAD <file>..." to unstage)
595 # modified: dir1/modified
598 # (use "git add <file>..." to include in what will be committed)
606 test_expect_success
'dry-run of partial commit excluding new file in index' '
607 git commit --dry-run dir1/modified >output &&
608 test_i18ncmp expect output
612 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
614 test_expect_success
'status refreshes the index' '
617 git diff-files >output &&
618 test_cmp expect output
621 test_expect_success
'setup status submodule summary' '
622 test_create_repo sm && (
626 git commit -m "Add foo"
633 # Changes to be committed:
634 # (use "git reset HEAD <file>..." to unstage)
636 # new file: dir2/added
639 # Changes not staged for commit:
640 # (use "git add <file>..." to update what will be committed)
641 # (use "git checkout -- <file>..." to discard changes in working directory)
643 # modified: dir1/modified
646 # (use "git add <file>..." to include in what will be committed)
655 test_expect_success
'status submodule summary is disabled by default' '
656 git status >output &&
657 test_i18ncmp expect output
660 # we expect the same as the previous test
661 test_expect_success
'status --untracked-files=all does not show submodule' '
662 git status --untracked-files=all >output &&
663 test_i18ncmp expect output
677 test_expect_success
'status -s submodule summary is disabled by default' '
678 git status -s >output &&
679 test_cmp expect output
682 # we expect the same as the previous test
683 test_expect_success
'status -s --untracked-files=all does not show submodule' '
684 git status -s --untracked-files=all >output &&
685 test_cmp expect output
688 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
692 # Changes to be committed:
693 # (use "git reset HEAD <file>..." to unstage)
695 # new file: dir2/added
698 # Changes not staged for commit:
699 # (use "git add <file>..." to update what will be committed)
700 # (use "git checkout -- <file>..." to discard changes in working directory)
702 # modified: dir1/modified
704 # Submodule changes to be committed:
706 # * sm 0000000...$head (1):
710 # (use "git add <file>..." to include in what will be committed)
719 test_expect_success
'status submodule summary' '
720 git config status.submodulesummary 10 &&
721 git status >output &&
722 if test_have_prereq MINGW
726 test_i18ncmp expect output
740 test_expect_success
'status -s submodule summary' '
741 git status -s >output &&
742 if test_have_prereq MINGW
746 test_cmp expect output
751 # Changes not staged for commit:
752 # (use "git add <file>..." to update what will be committed)
753 # (use "git checkout -- <file>..." to discard changes in working directory)
755 # modified: dir1/modified
758 # (use "git add <file>..." to include in what will be committed)
766 no changes added to commit (use "git add" and/or "git commit -a")
768 test_expect_success
'status submodule summary (clean submodule): commit' '
769 git commit -m "commit submodule" &&
770 git config status.submodulesummary 10 &&
771 test_must_fail git commit --dry-run >output &&
772 if test_have_prereq MINGW
776 test_i18ncmp expect output &&
777 git status >output &&
778 if test_have_prereq MINGW
782 test_i18ncmp expect output
794 test_expect_success
'status -s submodule summary (clean submodule)' '
795 git status -s >output &&
796 if test_have_prereq MINGW
800 test_cmp expect output
805 # Changes to be committed:
806 # (use "git reset HEAD^1 <file>..." to unstage)
808 # new file: dir2/added
811 # Changes not staged for commit:
812 # (use "git add <file>..." to update what will be committed)
813 # (use "git checkout -- <file>..." to discard changes in working directory)
815 # modified: dir1/modified
817 # Submodule changes to be committed:
819 # * sm 0000000...$head (1):
823 # (use "git add <file>..." to include in what will be committed)
832 test_expect_success
'commit --dry-run submodule summary (--amend)' '
833 git config status.submodulesummary 10 &&
834 git commit --dry-run --amend >output &&
835 if test_have_prereq MINGW
839 test_i18ncmp expect output
842 test_expect_success POSIXPERM
,SANITY
'status succeeds in a read-only repository' '
845 # make dir1/tracked stat-dirty
846 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
847 git status -s >output &&
848 ! grep dir1/tracked output &&
849 # make sure "status" succeeded without writing index out
850 git diff-files | grep dir1/tracked
857 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar') && git add sm
858 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
863 # Changes to be committed:
864 # (use "git reset HEAD <file>..." to unstage)
868 # Changes not staged for commit:
869 # (use "git add <file>..." to update what will be committed)
870 # (use "git checkout -- <file>..." to discard changes in working directory)
872 # modified: dir1/modified
874 # Submodule changes to be committed:
876 # * sm $head...$new_head (1):
880 # (use "git add <file>..." to include in what will be committed)
891 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
892 echo modified sm/untracked &&
893 git status --ignore-submodules=untracked >output &&
894 test_i18ncmp expect output
897 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
898 git config diff.ignoreSubmodules dirty &&
899 git status >output &&
900 test_i18ncmp expect output &&
901 git config --add -f .gitmodules submodule.subname.ignore untracked &&
902 git config --add -f .gitmodules submodule.subname.path sm &&
903 git status >output &&
904 test_i18ncmp expect output &&
905 git config -f .gitmodules --remove-section submodule.subname &&
906 git config --unset diff.ignoreSubmodules
909 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
910 git config --add -f .gitmodules submodule.subname.ignore none &&
911 git config --add -f .gitmodules submodule.subname.path sm &&
912 git config --add submodule.subname.ignore untracked &&
913 git config --add submodule.subname.path sm &&
914 git status >output &&
915 test_i18ncmp expect output &&
916 git config --remove-section submodule.subname &&
917 git config --remove-section -f .gitmodules submodule.subname
920 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
921 git status --ignore-submodules=dirty >output &&
922 test_i18ncmp expect output
925 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
926 git config diff.ignoreSubmodules dirty &&
927 git status >output &&
929 git config --add -f .gitmodules submodule.subname.ignore dirty &&
930 git config --add -f .gitmodules submodule.subname.path sm &&
931 git status >output &&
932 test_i18ncmp expect output &&
933 git config -f .gitmodules --remove-section submodule.subname &&
934 git config --unset diff.ignoreSubmodules
937 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
938 git config --add -f .gitmodules submodule.subname.ignore none &&
939 git config --add -f .gitmodules submodule.subname.path sm &&
940 git config --add submodule.subname.ignore dirty &&
941 git config --add submodule.subname.path sm &&
942 git status >output &&
943 test_i18ncmp expect output &&
944 git config --remove-section submodule.subname &&
945 git config -f .gitmodules --remove-section submodule.subname
948 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
949 echo modified >sm/foo &&
950 git status --ignore-submodules=dirty >output &&
951 test_i18ncmp expect output
954 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
955 git config --add -f .gitmodules submodule.subname.ignore dirty &&
956 git config --add -f .gitmodules submodule.subname.path sm &&
957 git status >output &&
958 test_i18ncmp expect output &&
959 git config -f .gitmodules --remove-section submodule.subname
962 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
963 git config --add -f .gitmodules submodule.subname.ignore none &&
964 git config --add -f .gitmodules submodule.subname.path sm &&
965 git config --add submodule.subname.ignore dirty &&
966 git config --add submodule.subname.path sm &&
967 git status >output &&
968 test_i18ncmp expect output &&
969 git config --remove-section submodule.subname &&
970 git config -f .gitmodules --remove-section submodule.subname
975 # Changes to be committed:
976 # (use "git reset HEAD <file>..." to unstage)
980 # Changes not staged for commit:
981 # (use "git add <file>..." to update what will be committed)
982 # (use "git checkout -- <file>..." to discard changes in working directory)
983 # (commit or discard the untracked or modified content in submodules)
985 # modified: dir1/modified
986 # modified: sm (modified content)
988 # Submodule changes to be committed:
990 # * sm $head...$new_head (1):
994 # (use "git add <file>..." to include in what will be committed)
1005 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1006 git status --ignore-submodules=untracked > output &&
1007 test_i18ncmp expect output
1010 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1011 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1012 git config --add -f .gitmodules submodule.subname.path sm &&
1013 git status >output &&
1014 test_i18ncmp expect output &&
1015 git config -f .gitmodules --remove-section submodule.subname
1018 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
1019 git config --add -f .gitmodules submodule.subname.ignore none &&
1020 git config --add -f .gitmodules submodule.subname.path sm &&
1021 git config --add submodule.subname.ignore untracked &&
1022 git config --add submodule.subname.path sm &&
1023 git status >output &&
1024 test_i18ncmp expect output &&
1025 git config --remove-section submodule.subname &&
1026 git config -f .gitmodules --remove-section submodule.subname
1029 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
1033 # Changes to be committed:
1034 # (use "git reset HEAD <file>..." to unstage)
1038 # Changes not staged for commit:
1039 # (use "git add <file>..." to update what will be committed)
1040 # (use "git checkout -- <file>..." to discard changes in working directory)
1042 # modified: dir1/modified
1043 # modified: sm (new commits)
1045 # Submodule changes to be committed:
1047 # * sm $head...$new_head (1):
1050 # Submodules changed but not updated:
1052 # * sm $new_head...$head2 (1):
1056 # (use "git add <file>..." to include in what will be committed)
1067 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1068 git status --ignore-submodules=untracked > output &&
1069 test_i18ncmp expect output
1072 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1073 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1074 git config --add -f .gitmodules submodule.subname.path sm &&
1075 git status >output &&
1076 test_i18ncmp expect output &&
1077 git config -f .gitmodules --remove-section submodule.subname
1080 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
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 untracked &&
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
1091 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1092 git status --ignore-submodules=dirty > output &&
1093 test_i18ncmp expect output
1095 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1096 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1097 git config --add -f .gitmodules submodule.subname.path sm &&
1098 git status >output &&
1099 test_i18ncmp expect output &&
1100 git config -f .gitmodules --remove-section submodule.subname
1103 test_expect_success
".git/config ignore=dirty doesn't suppress submodule summary" '
1104 git config --add -f .gitmodules submodule.subname.ignore none &&
1105 git config --add -f .gitmodules submodule.subname.path sm &&
1106 git config --add submodule.subname.ignore dirty &&
1107 git config --add submodule.subname.path sm &&
1108 git status >output &&
1109 test_i18ncmp expect output &&
1110 git config --remove-section submodule.subname &&
1111 git config -f .gitmodules --remove-section submodule.subname
1116 # Changes not staged for commit:
1117 # (use "git add <file>..." to update what will be committed)
1118 # (use "git checkout -- <file>..." to discard changes in working directory)
1120 # modified: dir1/modified
1123 # (use "git add <file>..." to include in what will be committed)
1132 no changes added to commit (use "git add" and/or "git commit -a")
1135 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1136 git status --ignore-submodules=all > output &&
1137 test_i18ncmp expect output
1140 test_expect_failure
'.gitmodules ignore=all suppresses submodule summary' '
1141 git config --add -f .gitmodules submodule.subname.ignore all &&
1142 git config --add -f .gitmodules submodule.subname.path sm &&
1143 git status > output &&
1144 test_cmp expect output &&
1145 git config -f .gitmodules --remove-section submodule.subname
1148 test_expect_failure
'.git/config ignore=all suppresses submodule summary' '
1149 git config --add -f .gitmodules submodule.subname.ignore none &&
1150 git config --add -f .gitmodules submodule.subname.path sm &&
1151 git config --add submodule.subname.ignore all &&
1152 git config --add submodule.subname.path sm &&
1153 git status > output &&
1154 test_cmp expect output &&
1155 git config --remove-section submodule.subname &&
1156 git config -f .gitmodules --remove-section submodule.subname