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 &&
409 git config status.color.branch green
414 # On branch <GREEN>master<RESET>
415 # Changes to be committed:
416 # (use "git reset HEAD <file>..." to unstage)
418 # <GREEN>new file: dir2/added<RESET>
420 # Changes not staged for commit:
421 # (use "git add <file>..." to update what will be committed)
422 # (use "git checkout -- <file>..." to discard changes in working directory)
424 # <RED>modified: dir1/modified<RESET>
427 # (use "git add <file>..." to include in what will be committed)
429 # <BLUE>dir1/untracked<RESET>
430 # <BLUE>dir2/modified<RESET>
431 # <BLUE>dir2/untracked<RESET>
432 # <BLUE>expect<RESET>
433 # <BLUE>output<RESET>
434 # <BLUE>untracked<RESET>
437 test_expect_success
'status with color.ui' '
439 git config color.ui always &&
440 git status | test_decode_color >output &&
441 test_cmp expect output
445 test_expect_success
'status with color.status' '
447 git config --unset color.ui &&
448 git config color.status always &&
449 git status | test_decode_color >output &&
450 test_cmp expect output
455 <RED
>M
<RESET
> dir
1/modified
456 <GREEN
>A
<RESET
> dir
2/added
457 <BLUE
>??
<RESET
> dir
1/untracked
458 <BLUE
>??
<RESET
> dir
2/modified
459 <BLUE
>??
<RESET
> dir
2/untracked
460 <BLUE
>??
<RESET
> expect
461 <BLUE
>??
<RESET
> output
462 <BLUE
>??
<RESET
> untracked
465 test_expect_success
'status -s with color.ui' '
467 git config --unset color.status &&
468 git config color.ui always &&
469 git status -s | test_decode_color >output &&
470 test_cmp expect output
474 test_expect_success
'status -s with color.status' '
476 git config --unset color.ui &&
477 git config color.status always &&
478 git status -s | test_decode_color >output &&
479 test_cmp expect output
484 ## <GREEN>master<RESET>
485 <RED
>M
<RESET
> dir
1/modified
486 <GREEN
>A
<RESET
> dir
2/added
487 <BLUE
>??
<RESET
> dir
1/untracked
488 <BLUE
>??
<RESET
> dir
2/modified
489 <BLUE
>??
<RESET
> dir
2/untracked
490 <BLUE
>??
<RESET
> expect
491 <BLUE
>??
<RESET
> output
492 <BLUE
>??
<RESET
> untracked
495 test_expect_success
'status -s -b with color.status' '
497 git status -s -b | test_decode_color >output &&
498 test_cmp expect output
513 test_expect_success
'status --porcelain ignores color.ui' '
515 git config --unset color.status &&
516 git config color.ui always &&
517 git status --porcelain | test_decode_color >output &&
518 test_cmp expect output
522 test_expect_success
'status --porcelain ignores color.status' '
524 git config --unset color.ui &&
525 git config color.status always &&
526 git status --porcelain | test_decode_color >output &&
527 test_cmp expect output
531 # recover unconditionally from color tests
532 git config
--unset color.status
533 git config
--unset color.ui
535 test_expect_success
'status --porcelain ignores -b' '
537 git status --porcelain -b >output &&
538 test_cmp expect output
544 # Changes to be committed:
545 # (use "git reset HEAD <file>..." to unstage)
547 # new file: dir2/added
549 # Changes not staged for commit:
550 # (use "git add <file>..." to update what will be committed)
551 # (use "git checkout -- <file>..." to discard changes in working directory)
553 # modified: dir1/modified
556 # (use "git add <file>..." to include in what will be committed)
567 test_expect_success
'status without relative paths' '
569 git config status.relativePaths false
570 (cd dir1 && git status) >output &&
571 test_cmp expect output
586 test_expect_success
'status -s without relative paths' '
588 (cd dir1 && git status -s) >output &&
589 test_cmp expect output
595 # Changes to be committed:
596 # (use "git reset HEAD <file>..." to unstage)
598 # modified: dir1/modified
601 # (use "git add <file>..." to include in what will be committed)
609 test_expect_success
'dry-run of partial commit excluding new file in index' '
610 git commit --dry-run dir1/modified >output &&
611 test_cmp expect output
615 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
617 test_expect_success
'status refreshes the index' '
620 git diff-files >output &&
621 test_cmp expect output
624 test_expect_success
'setup status submodule summary' '
625 test_create_repo sm && (
629 git commit -m "Add foo"
636 # Changes to be committed:
637 # (use "git reset HEAD <file>..." to unstage)
639 # new file: dir2/added
642 # Changes not staged for commit:
643 # (use "git add <file>..." to update what will be committed)
644 # (use "git checkout -- <file>..." to discard changes in working directory)
646 # modified: dir1/modified
649 # (use "git add <file>..." to include in what will be committed)
658 test_expect_success
'status submodule summary is disabled by default' '
659 git status >output &&
660 test_cmp expect output
663 # we expect the same as the previous test
664 test_expect_success
'status --untracked-files=all does not show submodule' '
665 git status --untracked-files=all >output &&
666 test_cmp expect output
680 test_expect_success
'status -s submodule summary is disabled by default' '
681 git status -s >output &&
682 test_cmp expect output
685 # we expect the same as the previous test
686 test_expect_success
'status -s --untracked-files=all does not show submodule' '
687 git status -s --untracked-files=all >output &&
688 test_cmp expect output
691 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
695 # Changes to be committed:
696 # (use "git reset HEAD <file>..." to unstage)
698 # new file: dir2/added
701 # Changes not staged for commit:
702 # (use "git add <file>..." to update what will be committed)
703 # (use "git checkout -- <file>..." to discard changes in working directory)
705 # modified: dir1/modified
707 # Submodule changes to be committed:
709 # * sm 0000000...$head (1):
713 # (use "git add <file>..." to include in what will be committed)
722 test_expect_success
'status submodule summary' '
723 git config status.submodulesummary 10 &&
724 git status >output &&
725 test_cmp expect output
739 test_expect_success
'status -s submodule summary' '
740 git status -s >output &&
741 test_cmp expect output
746 # Changes not staged for commit:
747 # (use "git add <file>..." to update what will be committed)
748 # (use "git checkout -- <file>..." to discard changes in working directory)
750 # modified: dir1/modified
753 # (use "git add <file>..." to include in what will be committed)
761 no changes added to commit (use "git add" and/or "git commit -a")
763 test_expect_success
'status submodule summary (clean submodule)' '
764 git commit -m "commit submodule" &&
765 git config status.submodulesummary 10 &&
766 test_must_fail git commit --dry-run >output &&
767 test_cmp expect output &&
768 git status >output &&
769 test_cmp expect output
781 test_expect_success
'status -s submodule summary (clean submodule)' '
782 git status -s >output &&
783 test_cmp expect output
788 # Changes to be committed:
789 # (use "git reset HEAD^1 <file>..." to unstage)
791 # new file: dir2/added
794 # Changes not staged for commit:
795 # (use "git add <file>..." to update what will be committed)
796 # (use "git checkout -- <file>..." to discard changes in working directory)
798 # modified: dir1/modified
800 # Submodule changes to be committed:
802 # * sm 0000000...$head (1):
806 # (use "git add <file>..." to include in what will be committed)
815 test_expect_success
'commit --dry-run submodule summary (--amend)' '
816 git config status.submodulesummary 10 &&
817 git commit --dry-run --amend >output &&
818 test_cmp expect output
821 test_expect_success POSIXPERM
,SANITY
'status succeeds in a read-only repository' '
824 # make dir1/tracked stat-dirty
825 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
826 git status -s >output &&
827 ! grep dir1/tracked output &&
828 # make sure "status" succeeded without writing index out
829 git diff-files | grep dir1/tracked
836 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar') && git add sm
837 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
842 # Changes to be committed:
843 # (use "git reset HEAD <file>..." to unstage)
847 # Changes not staged for commit:
848 # (use "git add <file>..." to update what will be committed)
849 # (use "git checkout -- <file>..." to discard changes in working directory)
851 # modified: dir1/modified
853 # Submodule changes to be committed:
855 # * sm $head...$new_head (1):
859 # (use "git add <file>..." to include in what will be committed)
870 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
871 echo modified > sm/untracked &&
872 git status --ignore-submodules=untracked > output &&
873 test_cmp expect output
876 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
877 git config diff.ignoreSubmodules dirty &&
878 git status >output &&
879 test_cmp expect output &&
880 git config --add -f .gitmodules submodule.subname.ignore untracked &&
881 git config --add -f .gitmodules submodule.subname.path sm &&
882 git status > output &&
883 test_cmp expect output &&
884 git config -f .gitmodules --remove-section submodule.subname &&
885 git config --unset diff.ignoreSubmodules
888 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
889 git config --add -f .gitmodules submodule.subname.ignore none &&
890 git config --add -f .gitmodules submodule.subname.path sm &&
891 git config --add submodule.subname.ignore untracked &&
892 git config --add submodule.subname.path sm &&
893 git status > output &&
894 test_cmp expect output &&
895 git config --remove-section submodule.subname &&
896 git config --remove-section -f .gitmodules submodule.subname
899 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
900 git status --ignore-submodules=dirty > output &&
901 test_cmp expect output
904 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
905 git config diff.ignoreSubmodules dirty &&
906 git status >output &&
908 git config --add -f .gitmodules submodule.subname.ignore dirty &&
909 git config --add -f .gitmodules submodule.subname.path sm &&
910 git status > output &&
911 test_cmp expect output &&
912 git config -f .gitmodules --remove-section submodule.subname &&
913 git config --unset diff.ignoreSubmodules
916 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
917 git config --add -f .gitmodules submodule.subname.ignore none &&
918 git config --add -f .gitmodules submodule.subname.path sm &&
919 git config --add submodule.subname.ignore dirty &&
920 git config --add submodule.subname.path sm &&
921 git status > output &&
922 test_cmp expect output &&
923 git config --remove-section submodule.subname &&
924 git config -f .gitmodules --remove-section submodule.subname
927 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
928 echo modified > sm/foo &&
929 git status --ignore-submodules=dirty > output &&
930 test_cmp expect output
933 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
934 git config --add -f .gitmodules submodule.subname.ignore dirty &&
935 git config --add -f .gitmodules submodule.subname.path sm &&
936 git status > output &&
937 test_cmp expect output &&
938 git config -f .gitmodules --remove-section submodule.subname
941 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
942 git config --add -f .gitmodules submodule.subname.ignore none &&
943 git config --add -f .gitmodules submodule.subname.path sm &&
944 git config --add submodule.subname.ignore dirty &&
945 git config --add submodule.subname.path sm &&
946 git status > output &&
947 test_cmp expect output &&
948 git config --remove-section submodule.subname &&
949 git config -f .gitmodules --remove-section submodule.subname
954 # Changes to be committed:
955 # (use "git reset HEAD <file>..." to unstage)
959 # Changes not staged for commit:
960 # (use "git add <file>..." to update what will be committed)
961 # (use "git checkout -- <file>..." to discard changes in working directory)
962 # (commit or discard the untracked or modified content in submodules)
964 # modified: dir1/modified
965 # modified: sm (modified content)
967 # Submodule changes to be committed:
969 # * sm $head...$new_head (1):
973 # (use "git add <file>..." to include in what will be committed)
984 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
985 git status --ignore-submodules=untracked > output &&
986 test_cmp expect output
989 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
990 git config --add -f .gitmodules submodule.subname.ignore untracked &&
991 git config --add -f .gitmodules submodule.subname.path sm &&
992 git status > output &&
993 test_cmp expect output &&
994 git config -f .gitmodules --remove-section submodule.subname
997 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
998 git config --add -f .gitmodules submodule.subname.ignore none &&
999 git config --add -f .gitmodules submodule.subname.path sm &&
1000 git config --add submodule.subname.ignore untracked &&
1001 git config --add submodule.subname.path sm &&
1002 git status > output &&
1003 test_cmp expect output &&
1004 git config --remove-section submodule.subname &&
1005 git config -f .gitmodules --remove-section submodule.subname
1008 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
1012 # Changes to be committed:
1013 # (use "git reset HEAD <file>..." to unstage)
1017 # Changes not staged for commit:
1018 # (use "git add <file>..." to update what will be committed)
1019 # (use "git checkout -- <file>..." to discard changes in working directory)
1021 # modified: dir1/modified
1022 # modified: sm (new commits)
1024 # Submodule changes to be committed:
1026 # * sm $head...$new_head (1):
1029 # Submodules changed but not updated:
1031 # * sm $new_head...$head2 (1):
1035 # (use "git add <file>..." to include in what will be committed)
1046 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1047 git status --ignore-submodules=untracked > output &&
1048 test_cmp expect output
1051 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1052 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1053 git config --add -f .gitmodules submodule.subname.path sm &&
1054 git status > output &&
1055 test_cmp expect output &&
1056 git config -f .gitmodules --remove-section submodule.subname
1059 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
1060 git config --add -f .gitmodules submodule.subname.ignore none &&
1061 git config --add -f .gitmodules submodule.subname.path sm &&
1062 git config --add submodule.subname.ignore untracked &&
1063 git config --add submodule.subname.path sm &&
1064 git status > output &&
1065 test_cmp expect output &&
1066 git config --remove-section submodule.subname &&
1067 git config -f .gitmodules --remove-section submodule.subname
1070 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1071 git status --ignore-submodules=dirty > output &&
1072 test_cmp expect output
1074 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1075 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1076 git config --add -f .gitmodules submodule.subname.path sm &&
1077 git status > output &&
1078 test_cmp expect output &&
1079 git config -f .gitmodules --remove-section submodule.subname
1082 test_expect_success
".git/config ignore=dirty doesn't suppress submodule summary" '
1083 git config --add -f .gitmodules submodule.subname.ignore none &&
1084 git config --add -f .gitmodules submodule.subname.path sm &&
1085 git config --add submodule.subname.ignore dirty &&
1086 git config --add submodule.subname.path sm &&
1087 git status > output &&
1088 test_cmp expect output &&
1089 git config --remove-section submodule.subname &&
1090 git config -f .gitmodules --remove-section submodule.subname
1095 # Changes not staged for commit:
1096 # (use "git add <file>..." to update what will be committed)
1097 # (use "git checkout -- <file>..." to discard changes in working directory)
1099 # modified: dir1/modified
1102 # (use "git add <file>..." to include in what will be committed)
1111 no changes added to commit (use "git add" and/or "git commit -a")
1114 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1115 git status --ignore-submodules=all > output &&
1116 test_cmp expect output
1119 test_expect_failure
'.gitmodules ignore=all suppresses submodule summary' '
1120 git config --add -f .gitmodules submodule.subname.ignore all &&
1121 git config --add -f .gitmodules submodule.subname.path sm &&
1122 git status > output &&
1123 test_cmp expect output &&
1124 git config -f .gitmodules --remove-section submodule.subname
1127 test_expect_failure
'.git/config ignore=all suppresses submodule summary' '
1128 git config --add -f .gitmodules submodule.subname.ignore none &&
1129 git config --add -f .gitmodules submodule.subname.path sm &&
1130 git config --add submodule.subname.ignore all &&
1131 git config --add submodule.subname.path sm &&
1132 git status > output &&
1133 test_cmp expect output &&
1134 git config --remove-section submodule.subname &&
1135 git config -f .gitmodules --remove-section submodule.subname