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 # Changed but not updated:
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 # Changed but not updated:
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 # Changed but not updated:
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 # Changed but not updated:
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 # Changed but not updated:
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 # Changed but not updated:
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 # Changed but not updated:
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
390 # Changes to be committed:
391 # (use "git reset HEAD <file>..." to unstage)
393 # <GREEN>new file: dir2/added<RESET>
395 # Changed but not updated:
396 # (use "git add <file>..." to update what will be committed)
397 # (use "git checkout -- <file>..." to discard changes in working directory)
399 # <RED>modified: dir1/modified<RESET>
402 # (use "git add <file>..." to include in what will be committed)
404 # <BLUE>dir1/untracked<RESET>
405 # <BLUE>dir2/modified<RESET>
406 # <BLUE>dir2/untracked<RESET>
407 # <BLUE>expect<RESET>
408 # <BLUE>output<RESET>
409 # <BLUE>untracked<RESET>
412 test_expect_success
'status with color.ui' '
414 git config color.ui always &&
415 git status | test_decode_color >output &&
416 test_cmp expect output
420 test_expect_success
'status with color.status' '
422 git config --unset color.ui &&
423 git config color.status always &&
424 git status | test_decode_color >output &&
425 test_cmp expect output
430 <RED
>M
<RESET
> dir
1/modified
431 <GREEN
>A
<RESET
> dir
2/added
432 <BLUE
>??
<RESET
> dir
1/untracked
433 <BLUE
>??
<RESET
> dir
2/modified
434 <BLUE
>??
<RESET
> dir
2/untracked
435 <BLUE
>??
<RESET
> expect
436 <BLUE
>??
<RESET
> output
437 <BLUE
>??
<RESET
> untracked
440 test_expect_success
'status -s with color.ui' '
442 git config --unset color.status &&
443 git config color.ui always &&
444 git status -s | test_decode_color >output &&
445 test_cmp expect output
449 test_expect_success
'status -s with color.status' '
451 git config --unset color.ui &&
452 git config color.status always &&
453 git status -s | test_decode_color >output &&
454 test_cmp expect output
459 ## <GREEN>master<RESET>
460 <RED
>M
<RESET
> dir
1/modified
461 <GREEN
>A
<RESET
> dir
2/added
462 <BLUE
>??
<RESET
> dir
1/untracked
463 <BLUE
>??
<RESET
> dir
2/modified
464 <BLUE
>??
<RESET
> dir
2/untracked
465 <BLUE
>??
<RESET
> expect
466 <BLUE
>??
<RESET
> output
467 <BLUE
>??
<RESET
> untracked
470 test_expect_success
'status -s -b with color.status' '
472 git status -s -b | test_decode_color >output &&
473 test_cmp expect output
488 test_expect_success
'status --porcelain ignores color.ui' '
490 git config --unset color.status &&
491 git config color.ui always &&
492 git status --porcelain | test_decode_color >output &&
493 test_cmp expect output
497 test_expect_success
'status --porcelain ignores color.status' '
499 git config --unset color.ui &&
500 git config color.status always &&
501 git status --porcelain | test_decode_color >output &&
502 test_cmp expect output
506 # recover unconditionally from color tests
507 git config
--unset color.status
508 git config
--unset color.ui
510 test_expect_success
'status --porcelain ignores -b' '
512 git status --porcelain -b >output &&
513 test_cmp expect output
519 # Changes to be committed:
520 # (use "git reset HEAD <file>..." to unstage)
522 # new file: dir2/added
524 # Changed but not updated:
525 # (use "git add <file>..." to update what will be committed)
526 # (use "git checkout -- <file>..." to discard changes in working directory)
528 # modified: dir1/modified
531 # (use "git add <file>..." to include in what will be committed)
542 test_expect_success
'status without relative paths' '
544 git config status.relativePaths false
545 (cd dir1 && git status) >output &&
546 test_cmp expect output
561 test_expect_success
'status -s without relative paths' '
563 (cd dir1 && git status -s) >output &&
564 test_cmp expect output
570 # Changes to be committed:
571 # (use "git reset HEAD <file>..." to unstage)
573 # modified: dir1/modified
576 # (use "git add <file>..." to include in what will be committed)
584 test_expect_success
'dry-run of partial commit excluding new file in index' '
585 git commit --dry-run dir1/modified >output &&
586 test_cmp expect output
590 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
592 test_expect_success
'status refreshes the index' '
595 git diff-files >output &&
596 test_cmp expect output
599 test_expect_success
'setup status submodule summary' '
600 test_create_repo sm && (
604 git commit -m "Add foo"
611 # Changes to be committed:
612 # (use "git reset HEAD <file>..." to unstage)
614 # new file: dir2/added
617 # Changed but not updated:
618 # (use "git add <file>..." to update what will be committed)
619 # (use "git checkout -- <file>..." to discard changes in working directory)
621 # modified: dir1/modified
624 # (use "git add <file>..." to include in what will be committed)
633 test_expect_success
'status submodule summary is disabled by default' '
634 git status >output &&
635 test_cmp expect output
638 # we expect the same as the previous test
639 test_expect_success
'status --untracked-files=all does not show submodule' '
640 git status --untracked-files=all >output &&
641 test_cmp expect output
655 test_expect_success
'status -s submodule summary is disabled by default' '
656 git status -s >output &&
657 test_cmp expect output
660 # we expect the same as the previous test
661 test_expect_success
'status -s --untracked-files=all does not show submodule' '
662 git status -s --untracked-files=all >output &&
663 test_cmp expect output
666 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
670 # Changes to be committed:
671 # (use "git reset HEAD <file>..." to unstage)
673 # new file: dir2/added
676 # Changed but not updated:
677 # (use "git add <file>..." to update what will be committed)
678 # (use "git checkout -- <file>..." to discard changes in working directory)
680 # modified: dir1/modified
682 # Submodule changes to be committed:
684 # * sm 0000000...$head (1):
688 # (use "git add <file>..." to include in what will be committed)
697 test_expect_success
'status submodule summary' '
698 git config status.submodulesummary 10 &&
699 git status >output &&
700 test_cmp expect output
714 test_expect_success
'status -s submodule summary' '
715 git status -s >output &&
716 test_cmp expect output
721 # Changed but not updated:
722 # (use "git add <file>..." to update what will be committed)
723 # (use "git checkout -- <file>..." to discard changes in working directory)
725 # modified: dir1/modified
728 # (use "git add <file>..." to include in what will be committed)
736 no changes added to commit (use "git add" and/or "git commit -a")
738 test_expect_success
'status submodule summary (clean submodule)' '
739 git commit -m "commit submodule" &&
740 git config status.submodulesummary 10 &&
741 test_must_fail git commit --dry-run >output &&
742 test_cmp expect output &&
743 git status >output &&
744 test_cmp expect output
756 test_expect_success
'status -s submodule summary (clean submodule)' '
757 git status -s >output &&
758 test_cmp expect output
763 # Changes to be committed:
764 # (use "git reset HEAD^1 <file>..." to unstage)
766 # new file: dir2/added
769 # Changed but not updated:
770 # (use "git add <file>..." to update what will be committed)
771 # (use "git checkout -- <file>..." to discard changes in working directory)
773 # modified: dir1/modified
775 # Submodule changes to be committed:
777 # * sm 0000000...$head (1):
781 # (use "git add <file>..." to include in what will be committed)
790 test_expect_success
'commit --dry-run submodule summary (--amend)' '
791 git config status.submodulesummary 10 &&
792 git commit --dry-run --amend >output &&
793 test_cmp expect output
796 test_expect_success POSIXPERM
'status succeeds in a read-only repository' '
799 # make dir1/tracked stat-dirty
800 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
801 git status -s >output &&
802 ! grep dir1/tracked output &&
803 # make sure "status" succeeded without writing index out
804 git diff-files | grep dir1/tracked
811 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar' && cd ..
&& git add sm
)
812 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
817 # Changes to be committed:
818 # (use "git reset HEAD <file>..." to unstage)
822 # Changed but not updated:
823 # (use "git add <file>..." to update what will be committed)
824 # (use "git checkout -- <file>..." to discard changes in working directory)
826 # modified: dir1/modified
828 # Submodule changes to be committed:
830 # * sm $head...$new_head (1):
834 # (use "git add <file>..." to include in what will be committed)
845 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
846 echo modified > sm/untracked &&
847 git status --ignore-submodules=untracked > output &&
848 test_cmp expect output
851 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
852 git config --add -f .gitmodules submodule.subname.ignore untracked &&
853 git config --add -f .gitmodules submodule.subname.path sm &&
854 git status > output &&
855 test_cmp expect output &&
856 git config -f .gitmodules --remove-section submodule.subname
859 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
860 git config --add -f .gitmodules submodule.subname.ignore none &&
861 git config --add -f .gitmodules submodule.subname.path sm &&
862 git config --add submodule.subname.ignore untracked &&
863 git config --add submodule.subname.path sm &&
864 git status > output &&
865 test_cmp expect output &&
866 git config --remove-section submodule.subname &&
867 git config --remove-section -f .gitmodules submodule.subname
870 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
871 git status --ignore-submodules=dirty > output &&
872 test_cmp expect output
875 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
876 git config --add -f .gitmodules submodule.subname.ignore dirty &&
877 git config --add -f .gitmodules submodule.subname.path sm &&
878 git status > output &&
879 test_cmp expect output &&
880 git config -f .gitmodules --remove-section submodule.subname
883 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
884 git config --add -f .gitmodules submodule.subname.ignore none &&
885 git config --add -f .gitmodules submodule.subname.path sm &&
886 git config --add submodule.subname.ignore dirty &&
887 git config --add submodule.subname.path sm &&
888 git status > output &&
889 test_cmp expect output &&
890 git config --remove-section submodule.subname &&
891 git config -f .gitmodules --remove-section submodule.subname
894 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
895 echo modified > sm/foo &&
896 git status --ignore-submodules=dirty > output &&
897 test_cmp expect output
900 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
901 git config --add -f .gitmodules submodule.subname.ignore dirty &&
902 git config --add -f .gitmodules submodule.subname.path sm &&
903 git status > output &&
904 test_cmp expect output &&
905 git config -f .gitmodules --remove-section submodule.subname
908 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
909 git config --add -f .gitmodules submodule.subname.ignore none &&
910 git config --add -f .gitmodules submodule.subname.path sm &&
911 git config --add submodule.subname.ignore dirty &&
912 git config --add submodule.subname.path sm &&
913 git status > output &&
914 test_cmp expect output &&
915 git config --remove-section submodule.subname &&
916 git config -f .gitmodules --remove-section submodule.subname
921 # Changes to be committed:
922 # (use "git reset HEAD <file>..." to unstage)
926 # Changed but not updated:
927 # (use "git add <file>..." to update what will be committed)
928 # (use "git checkout -- <file>..." to discard changes in working directory)
929 # (commit or discard the untracked or modified content in submodules)
931 # modified: dir1/modified
932 # modified: sm (modified content)
934 # Submodule changes to be committed:
936 # * sm $head...$new_head (1):
940 # (use "git add <file>..." to include in what will be committed)
951 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
952 git status --ignore-submodules=untracked > output &&
953 test_cmp expect output
956 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
957 git config --add -f .gitmodules submodule.subname.ignore untracked &&
958 git config --add -f .gitmodules submodule.subname.path sm &&
959 git status > output &&
960 test_cmp expect output &&
961 git config -f .gitmodules --remove-section submodule.subname
964 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
965 git config --add -f .gitmodules submodule.subname.ignore none &&
966 git config --add -f .gitmodules submodule.subname.path sm &&
967 git config --add submodule.subname.ignore untracked &&
968 git config --add submodule.subname.path sm &&
969 git status > output &&
970 test_cmp expect output &&
971 git config --remove-section submodule.subname &&
972 git config -f .gitmodules --remove-section submodule.subname
975 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
979 # Changes to be committed:
980 # (use "git reset HEAD <file>..." to unstage)
984 # Changed but not updated:
985 # (use "git add <file>..." to update what will be committed)
986 # (use "git checkout -- <file>..." to discard changes in working directory)
988 # modified: dir1/modified
989 # modified: sm (new commits)
991 # Submodule changes to be committed:
993 # * sm $head...$new_head (1):
996 # Submodules changed but not updated:
998 # * sm $new_head...$head2 (1):
1002 # (use "git add <file>..." to include in what will be committed)
1013 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1014 git status --ignore-submodules=untracked > output &&
1015 test_cmp expect output
1018 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1019 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1020 git config --add -f .gitmodules submodule.subname.path sm &&
1021 git status > output &&
1022 test_cmp expect output &&
1023 git config -f .gitmodules --remove-section submodule.subname
1026 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
1027 git config --add -f .gitmodules submodule.subname.ignore none &&
1028 git config --add -f .gitmodules submodule.subname.path sm &&
1029 git config --add submodule.subname.ignore untracked &&
1030 git config --add submodule.subname.path sm &&
1031 git status > output &&
1032 test_cmp expect output &&
1033 git config --remove-section submodule.subname &&
1034 git config -f .gitmodules --remove-section submodule.subname
1037 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1038 git status --ignore-submodules=dirty > output &&
1039 test_cmp expect output
1041 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1042 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1043 git config --add -f .gitmodules submodule.subname.path sm &&
1044 git status > output &&
1045 test_cmp expect output &&
1046 git config -f .gitmodules --remove-section submodule.subname
1049 test_expect_success
".git/config ignore=dirty doesn't suppress submodule summary" '
1050 git config --add -f .gitmodules submodule.subname.ignore none &&
1051 git config --add -f .gitmodules submodule.subname.path sm &&
1052 git config --add submodule.subname.ignore dirty &&
1053 git config --add submodule.subname.path sm &&
1054 git status > output &&
1055 test_cmp expect output &&
1056 git config --remove-section submodule.subname &&
1057 git config -f .gitmodules --remove-section submodule.subname
1062 # Changed but not updated:
1063 # (use "git add <file>..." to update what will be committed)
1064 # (use "git checkout -- <file>..." to discard changes in working directory)
1066 # modified: dir1/modified
1069 # (use "git add <file>..." to include in what will be committed)
1078 no changes added to commit (use "git add" and/or "git commit -a")
1081 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1082 git status --ignore-submodules=all > output &&
1083 test_cmp expect output
1086 test_expect_failure
'.gitmodules ignore=all suppresses submodule summary' '
1087 git config --add -f .gitmodules submodule.subname.ignore all &&
1088 git config --add -f .gitmodules submodule.subname.path sm &&
1089 git status > output &&
1090 test_cmp expect output &&
1091 git config -f .gitmodules --remove-section submodule.subname
1094 test_expect_failure
'.git/config ignore=all suppresses submodule summary' '
1095 git config --add -f .gitmodules submodule.subname.ignore none &&
1096 git config --add -f .gitmodules submodule.subname.path sm &&
1097 git config --add submodule.subname.ignore all &&
1098 git config --add submodule.subname.path sm &&
1099 git status > output &&
1100 test_cmp expect output &&
1101 git config --remove-section submodule.subname &&
1102 git config -f .gitmodules --remove-section submodule.subname