3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='git status'
10 test_expect_success
'setup' '
24 git commit -m initial &&
28 echo 1 >dir1/modified &&
29 echo 2 >dir2/modified &&
34 test_expect_success
'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
42 # Changes to be committed:
43 # (use "git reset HEAD <file>..." to unstage)
45 # new file: dir2/added
47 # Changes not staged for commit:
48 # (use "git add <file>..." to update what will be committed)
49 # (use "git checkout -- <file>..." to discard changes in working directory)
51 # modified: dir1/modified
54 # (use "git add <file>..." to include in what will be committed)
64 test_expect_success
'status (2)' '
67 test_cmp expect output
73 # Changes to be committed:
74 # new file: dir2/added
76 # Changes not staged for commit:
77 # modified: dir1/modified
88 git config advice.statusHints false
90 test_expect_success
'status (advice.statusHints false)' '
93 test_cmp expect output
97 git config
--unset advice.statusHints
110 test_expect_success
'status -s' '
112 git status -s >output &&
113 test_cmp expect output
129 test_expect_success
'status -s -b' '
131 git status -s -b >output &&
132 test_cmp expect output
138 # Changes to be committed:
139 # (use "git reset HEAD <file>..." to unstage)
141 # new file: dir2/added
143 # Changes not staged for commit:
144 # (use "git add <file>..." to update what will be committed)
145 # (use "git checkout -- <file>..." to discard changes in working directory)
147 # modified: dir1/modified
149 # Untracked files not listed (use -u option to show untracked files)
151 test_expect_success
'status -uno' '
153 : >dir3/untracked1 &&
154 : >dir3/untracked2 &&
155 git status -uno >output &&
156 test_cmp expect output
159 test_expect_success
'status (status.showUntrackedFiles no)' '
160 git config status.showuntrackedfiles no
161 git status >output &&
162 test_cmp expect output
167 # Changes to be committed:
168 # new file: dir2/added
170 # Changes not staged for commit:
171 # modified: dir1/modified
173 # Untracked files not listed
175 git config advice.statusHints false
176 test_expect_success
'status -uno (advice.statusHints false)' '
177 git status -uno >output &&
178 test_cmp expect output
180 git config
--unset advice.statusHints
186 test_expect_success
'status -s -uno' '
187 git config --unset status.showuntrackedfiles
188 git status -s -uno >output &&
189 test_cmp expect output
192 test_expect_success
'status -s (status.showUntrackedFiles no)' '
193 git config status.showuntrackedfiles no
194 git status -s >output &&
195 test_cmp expect output
200 # Changes to be committed:
201 # (use "git reset HEAD <file>..." to unstage)
203 # new file: dir2/added
205 # Changes not staged for commit:
206 # (use "git add <file>..." to update what will be committed)
207 # (use "git checkout -- <file>..." to discard changes in working directory)
209 # modified: dir1/modified
212 # (use "git add <file>..." to include in what will be committed)
222 test_expect_success
'status -unormal' '
223 git status -unormal >output &&
224 test_cmp expect output
227 test_expect_success
'status (status.showUntrackedFiles normal)' '
228 git config status.showuntrackedfiles normal
229 git status >output &&
230 test_cmp expect output
244 test_expect_success
'status -s -unormal' '
245 git config --unset status.showuntrackedfiles
246 git status -s -unormal >output &&
247 test_cmp expect output
250 test_expect_success
'status -s (status.showUntrackedFiles normal)' '
251 git config status.showuntrackedfiles normal
252 git status -s >output &&
253 test_cmp expect output
258 # Changes to be committed:
259 # (use "git reset HEAD <file>..." to unstage)
261 # new file: dir2/added
263 # Changes not staged for commit:
264 # (use "git add <file>..." to update what will be committed)
265 # (use "git checkout -- <file>..." to discard changes in working directory)
267 # modified: dir1/modified
270 # (use "git add <file>..." to include in what will be committed)
281 test_expect_success
'status -uall' '
282 git status -uall >output &&
283 test_cmp expect output
285 test_expect_success
'status (status.showUntrackedFiles all)' '
286 git config status.showuntrackedfiles all
287 git status >output &&
289 git config --unset status.showuntrackedfiles &&
290 test_cmp expect output
303 test_expect_success
'status -s -uall' '
304 git config --unset status.showuntrackedfiles
305 git status -s -uall >output &&
306 test_cmp expect output
308 test_expect_success
'status -s (status.showUntrackedFiles all)' '
309 git config status.showuntrackedfiles all
310 git status -s >output &&
312 git config --unset status.showuntrackedfiles &&
313 test_cmp expect output
318 # Changes to be committed:
319 # (use "git reset HEAD <file>..." to unstage)
321 # new file: ../dir2/added
323 # Changes not staged for commit:
324 # (use "git add <file>..." to update what will be committed)
325 # (use "git checkout -- <file>..." to discard changes in working directory)
330 # (use "git add <file>..." to include in what will be committed)
340 test_expect_success
'status with relative paths' '
342 (cd dir1 && git status) >output &&
343 test_cmp expect output
357 test_expect_success
'status -s with relative paths' '
359 (cd dir1 && git status -s) >output &&
360 test_cmp expect output
375 test_expect_success
'status --porcelain ignores relative paths setting' '
377 (cd dir1 && git status --porcelain) >output &&
378 test_cmp expect output
382 test_expect_success
'setup unique colors' '
384 git config status.color.untracked blue &&
385 git config status.color.branch green
390 # On branch <GREEN>master<RESET>
391 # Changes to be committed:
392 # (use "git reset HEAD <file>..." to unstage)
394 # <GREEN>new file: dir2/added<RESET>
396 # Changes not staged for commit:
397 # (use "git add <file>..." to update what will be committed)
398 # (use "git checkout -- <file>..." to discard changes in working directory)
400 # <RED>modified: dir1/modified<RESET>
403 # (use "git add <file>..." to include in what will be committed)
405 # <BLUE>dir1/untracked<RESET>
406 # <BLUE>dir2/modified<RESET>
407 # <BLUE>dir2/untracked<RESET>
408 # <BLUE>expect<RESET>
409 # <BLUE>output<RESET>
410 # <BLUE>untracked<RESET>
413 test_expect_success
'status with color.ui' '
415 git config color.ui always &&
416 git status | test_decode_color >output &&
417 test_cmp expect output
421 test_expect_success
'status with color.status' '
423 git config --unset color.ui &&
424 git config color.status always &&
425 git status | test_decode_color >output &&
426 test_cmp expect output
431 <RED
>M
<RESET
> dir
1/modified
432 <GREEN
>A
<RESET
> dir
2/added
433 <BLUE
>??
<RESET
> dir
1/untracked
434 <BLUE
>??
<RESET
> dir
2/modified
435 <BLUE
>??
<RESET
> dir
2/untracked
436 <BLUE
>??
<RESET
> expect
437 <BLUE
>??
<RESET
> output
438 <BLUE
>??
<RESET
> untracked
441 test_expect_success
'status -s with color.ui' '
443 git config --unset color.status &&
444 git config color.ui always &&
445 git status -s | test_decode_color >output &&
446 test_cmp expect output
450 test_expect_success
'status -s with color.status' '
452 git config --unset color.ui &&
453 git config color.status always &&
454 git status -s | test_decode_color >output &&
455 test_cmp expect output
460 ## <GREEN>master<RESET>
461 <RED
>M
<RESET
> dir
1/modified
462 <GREEN
>A
<RESET
> dir
2/added
463 <BLUE
>??
<RESET
> dir
1/untracked
464 <BLUE
>??
<RESET
> dir
2/modified
465 <BLUE
>??
<RESET
> dir
2/untracked
466 <BLUE
>??
<RESET
> expect
467 <BLUE
>??
<RESET
> output
468 <BLUE
>??
<RESET
> untracked
471 test_expect_success
'status -s -b with color.status' '
473 git status -s -b | test_decode_color >output &&
474 test_cmp expect output
489 test_expect_success
'status --porcelain ignores color.ui' '
491 git config --unset color.status &&
492 git config color.ui always &&
493 git status --porcelain | test_decode_color >output &&
494 test_cmp expect output
498 test_expect_success
'status --porcelain ignores color.status' '
500 git config --unset color.ui &&
501 git config color.status always &&
502 git status --porcelain | test_decode_color >output &&
503 test_cmp expect output
507 # recover unconditionally from color tests
508 git config
--unset color.status
509 git config
--unset color.ui
511 test_expect_success
'status --porcelain ignores -b' '
513 git status --porcelain -b >output &&
514 test_cmp expect output
520 # Changes to be committed:
521 # (use "git reset HEAD <file>..." to unstage)
523 # new file: dir2/added
525 # Changes not staged for commit:
526 # (use "git add <file>..." to update what will be committed)
527 # (use "git checkout -- <file>..." to discard changes in working directory)
529 # modified: dir1/modified
532 # (use "git add <file>..." to include in what will be committed)
543 test_expect_success
'status without relative paths' '
545 git config status.relativePaths false
546 (cd dir1 && git status) >output &&
547 test_cmp expect output
562 test_expect_success
'status -s without relative paths' '
564 (cd dir1 && git status -s) >output &&
565 test_cmp expect output
571 # Changes to be committed:
572 # (use "git reset HEAD <file>..." to unstage)
574 # modified: dir1/modified
577 # (use "git add <file>..." to include in what will be committed)
585 test_expect_success
'dry-run of partial commit excluding new file in index' '
586 git commit --dry-run dir1/modified >output &&
587 test_cmp expect output
591 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
593 test_expect_success
'status refreshes the index' '
596 git diff-files >output &&
597 test_cmp expect output
600 test_expect_success
'setup status submodule summary' '
601 test_create_repo sm && (
605 git commit -m "Add foo"
612 # Changes to be committed:
613 # (use "git reset HEAD <file>..." to unstage)
615 # new file: dir2/added
618 # Changes not staged for commit:
619 # (use "git add <file>..." to update what will be committed)
620 # (use "git checkout -- <file>..." to discard changes in working directory)
622 # modified: dir1/modified
625 # (use "git add <file>..." to include in what will be committed)
634 test_expect_success
'status submodule summary is disabled by default' '
635 git status >output &&
636 test_cmp expect output
639 # we expect the same as the previous test
640 test_expect_success
'status --untracked-files=all does not show submodule' '
641 git status --untracked-files=all >output &&
642 test_cmp expect output
656 test_expect_success
'status -s submodule summary is disabled by default' '
657 git status -s >output &&
658 test_cmp expect output
661 # we expect the same as the previous test
662 test_expect_success
'status -s --untracked-files=all does not show submodule' '
663 git status -s --untracked-files=all >output &&
664 test_cmp expect output
667 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
671 # Changes to be committed:
672 # (use "git reset HEAD <file>..." to unstage)
674 # new file: dir2/added
677 # Changes not staged for commit:
678 # (use "git add <file>..." to update what will be committed)
679 # (use "git checkout -- <file>..." to discard changes in working directory)
681 # modified: dir1/modified
683 # Submodule changes to be committed:
685 # * sm 0000000...$head (1):
689 # (use "git add <file>..." to include in what will be committed)
698 test_expect_success
'status submodule summary' '
699 git config status.submodulesummary 10 &&
700 git status >output &&
701 test_cmp expect output
715 test_expect_success
'status -s submodule summary' '
716 git status -s >output &&
717 test_cmp expect output
722 # Changes not staged for commit:
723 # (use "git add <file>..." to update what will be committed)
724 # (use "git checkout -- <file>..." to discard changes in working directory)
726 # modified: dir1/modified
729 # (use "git add <file>..." to include in what will be committed)
737 no changes added to commit (use "git add" and/or "git commit -a")
739 test_expect_success
'status submodule summary (clean submodule)' '
740 git commit -m "commit submodule" &&
741 git config status.submodulesummary 10 &&
742 test_must_fail git commit --dry-run >output &&
743 test_cmp expect output &&
744 git status >output &&
745 test_cmp expect output
757 test_expect_success
'status -s submodule summary (clean submodule)' '
758 git status -s >output &&
759 test_cmp expect output
764 # Changes to be committed:
765 # (use "git reset HEAD^1 <file>..." to unstage)
767 # new file: dir2/added
770 # Changes not staged for commit:
771 # (use "git add <file>..." to update what will be committed)
772 # (use "git checkout -- <file>..." to discard changes in working directory)
774 # modified: dir1/modified
776 # Submodule changes to be committed:
778 # * sm 0000000...$head (1):
782 # (use "git add <file>..." to include in what will be committed)
791 test_expect_success
'commit --dry-run submodule summary (--amend)' '
792 git config status.submodulesummary 10 &&
793 git commit --dry-run --amend >output &&
794 test_cmp expect output
797 test_expect_success POSIXPERM
,SANITY
'status succeeds in a read-only repository' '
800 # make dir1/tracked stat-dirty
801 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
802 git status -s >output &&
803 ! grep dir1/tracked output &&
804 # make sure "status" succeeded without writing index out
805 git diff-files | grep dir1/tracked
812 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar') && git add sm
813 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
818 # Changes to be committed:
819 # (use "git reset HEAD <file>..." to unstage)
823 # Changes not staged for commit:
824 # (use "git add <file>..." to update what will be committed)
825 # (use "git checkout -- <file>..." to discard changes in working directory)
827 # modified: dir1/modified
829 # Submodule changes to be committed:
831 # * sm $head...$new_head (1):
835 # (use "git add <file>..." to include in what will be committed)
846 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
847 echo modified > sm/untracked &&
848 git status --ignore-submodules=untracked > output &&
849 test_cmp expect output
852 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
853 git config diff.ignoreSubmodules dirty &&
854 git status >output &&
855 test_cmp expect output &&
856 git config --add -f .gitmodules submodule.subname.ignore untracked &&
857 git config --add -f .gitmodules submodule.subname.path sm &&
858 git status > output &&
859 test_cmp expect output &&
860 git config -f .gitmodules --remove-section submodule.subname &&
861 git config --unset diff.ignoreSubmodules
864 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
865 git config --add -f .gitmodules submodule.subname.ignore none &&
866 git config --add -f .gitmodules submodule.subname.path sm &&
867 git config --add submodule.subname.ignore untracked &&
868 git config --add submodule.subname.path sm &&
869 git status > output &&
870 test_cmp expect output &&
871 git config --remove-section submodule.subname &&
872 git config --remove-section -f .gitmodules submodule.subname
875 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
876 git status --ignore-submodules=dirty > output &&
877 test_cmp expect output
880 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
881 git config diff.ignoreSubmodules dirty &&
882 git status >output &&
884 git config --add -f .gitmodules submodule.subname.ignore dirty &&
885 git config --add -f .gitmodules submodule.subname.path sm &&
886 git status > output &&
887 test_cmp expect output &&
888 git config -f .gitmodules --remove-section submodule.subname &&
889 git config --unset diff.ignoreSubmodules
892 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
893 git config --add -f .gitmodules submodule.subname.ignore none &&
894 git config --add -f .gitmodules submodule.subname.path sm &&
895 git config --add submodule.subname.ignore dirty &&
896 git config --add submodule.subname.path sm &&
897 git status > output &&
898 test_cmp expect output &&
899 git config --remove-section submodule.subname &&
900 git config -f .gitmodules --remove-section submodule.subname
903 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
904 echo modified > sm/foo &&
905 git status --ignore-submodules=dirty > output &&
906 test_cmp expect output
909 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
910 git config --add -f .gitmodules submodule.subname.ignore dirty &&
911 git config --add -f .gitmodules submodule.subname.path sm &&
912 git status > output &&
913 test_cmp expect output &&
914 git config -f .gitmodules --remove-section submodule.subname
917 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
918 git config --add -f .gitmodules submodule.subname.ignore none &&
919 git config --add -f .gitmodules submodule.subname.path sm &&
920 git config --add submodule.subname.ignore dirty &&
921 git config --add submodule.subname.path sm &&
922 git status > output &&
923 test_cmp expect output &&
924 git config --remove-section submodule.subname &&
925 git config -f .gitmodules --remove-section submodule.subname
930 # Changes to be committed:
931 # (use "git reset HEAD <file>..." to unstage)
935 # Changes not staged for commit:
936 # (use "git add <file>..." to update what will be committed)
937 # (use "git checkout -- <file>..." to discard changes in working directory)
938 # (commit or discard the untracked or modified content in submodules)
940 # modified: dir1/modified
941 # modified: sm (modified content)
943 # Submodule changes to be committed:
945 # * sm $head...$new_head (1):
949 # (use "git add <file>..." to include in what will be committed)
960 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
961 git status --ignore-submodules=untracked > output &&
962 test_cmp expect output
965 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
966 git config --add -f .gitmodules submodule.subname.ignore untracked &&
967 git config --add -f .gitmodules submodule.subname.path sm &&
968 git status > output &&
969 test_cmp expect output &&
970 git config -f .gitmodules --remove-section submodule.subname
973 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
974 git config --add -f .gitmodules submodule.subname.ignore none &&
975 git config --add -f .gitmodules submodule.subname.path sm &&
976 git config --add submodule.subname.ignore untracked &&
977 git config --add submodule.subname.path sm &&
978 git status > output &&
979 test_cmp expect output &&
980 git config --remove-section submodule.subname &&
981 git config -f .gitmodules --remove-section submodule.subname
984 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
988 # Changes to be committed:
989 # (use "git reset HEAD <file>..." to unstage)
993 # Changes not staged for commit:
994 # (use "git add <file>..." to update what will be committed)
995 # (use "git checkout -- <file>..." to discard changes in working directory)
997 # modified: dir1/modified
998 # modified: sm (new commits)
1000 # Submodule changes to be committed:
1002 # * sm $head...$new_head (1):
1005 # Submodules changed but not updated:
1007 # * sm $new_head...$head2 (1):
1011 # (use "git add <file>..." to include in what will be committed)
1022 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1023 git status --ignore-submodules=untracked > output &&
1024 test_cmp expect output
1027 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1028 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1029 git config --add -f .gitmodules submodule.subname.path sm &&
1030 git status > output &&
1031 test_cmp expect output &&
1032 git config -f .gitmodules --remove-section submodule.subname
1035 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
1036 git config --add -f .gitmodules submodule.subname.ignore none &&
1037 git config --add -f .gitmodules submodule.subname.path sm &&
1038 git config --add submodule.subname.ignore untracked &&
1039 git config --add submodule.subname.path sm &&
1040 git status > output &&
1041 test_cmp expect output &&
1042 git config --remove-section submodule.subname &&
1043 git config -f .gitmodules --remove-section submodule.subname
1046 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1047 git status --ignore-submodules=dirty > output &&
1048 test_cmp expect output
1050 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1051 git config --add -f .gitmodules submodule.subname.ignore dirty &&
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=dirty 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 dirty &&
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
1071 # Changes not staged for commit:
1072 # (use "git add <file>..." to update what will be committed)
1073 # (use "git checkout -- <file>..." to discard changes in working directory)
1075 # modified: dir1/modified
1078 # (use "git add <file>..." to include in what will be committed)
1087 no changes added to commit (use "git add" and/or "git commit -a")
1090 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1091 git status --ignore-submodules=all > output &&
1092 test_cmp expect output
1095 test_expect_failure
'.gitmodules ignore=all suppresses submodule summary' '
1096 git config --add -f .gitmodules submodule.subname.ignore all &&
1097 git config --add -f .gitmodules submodule.subname.path sm &&
1098 git status > output &&
1099 test_cmp expect output &&
1100 git config -f .gitmodules --remove-section submodule.subname
1103 test_expect_failure
'.git/config ignore=all suppresses 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 all &&
1107 git config --add submodule.subname.path sm &&
1108 git status > output &&
1109 test_cmp expect output &&
1110 git config --remove-section submodule.subname &&
1111 git config -f .gitmodules --remove-section submodule.subname