3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='git status'
8 TEST_PASSES_SANITIZE_LEAK
=true
10 .
"$TEST_DIRECTORY"/lib-terminal.sh
12 test_expect_success
'status -h in broken repository' '
13 git config --global advice.statusuoption false &&
15 test_when_finished "rm -fr broken" &&
19 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
20 test_expect_code 129 git status -h >usage 2>&1
22 test_grep "[Uu]sage" broken/usage
25 test_expect_success
'commit -h in broken repository' '
27 test_when_finished "rm -fr broken" &&
31 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
32 test_expect_code 129 git commit -h >usage 2>&1
34 test_grep "[Uu]sage" broken/usage
37 test_expect_success
'create upstream branch' '
38 git checkout -b upstream &&
39 test_commit upstream1 &&
40 test_commit upstream2 &&
41 # leave the first commit on main as root because several
42 # tests depend on this case; for our upstream we only
43 # care about commit counts anyway, so a totally divergent
45 git checkout --orphan main
48 test_expect_success
'setup' '
62 git commit -m initial &&
66 echo 1 >dir1/modified &&
67 echo 2 >dir2/modified &&
71 git branch --set-upstream-to=upstream
74 test_expect_success
'status (1)' '
75 test_grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
80 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp
&&
81 rm "$1" && mv "$1".tmp
"$1"
84 cat >.gitignore
<<\EOF
90 test_expect_success
'status --column' '
93 # Your branch and '\''upstream'\'' have diverged,
94 # and have 1 and 2 different commits each, respectively.
95 # (use "git pull" if you want to integrate the remote branch with yours)
97 # Changes to be committed:
98 # (use "git restore --staged <file>..." to unstage)
99 # new file: dir2/added
101 # Changes not staged for commit:
102 # (use "git add <file>..." to update what will be committed)
103 # (use "git restore <file>..." to discard changes in working directory)
104 # modified: dir1/modified
107 # (use "git add <file>..." to include in what will be committed)
108 # dir1/untracked dir2/untracked
109 # dir2/modified untracked
112 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
113 test_cmp expect output
116 test_expect_success
'status --column status.displayCommentPrefix=false' '
117 strip_comments expect &&
118 COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
119 test_cmp expect output
124 # Your branch and 'upstream' have diverged,
125 # and have 1 and 2 different commits each, respectively.
126 # (use "git pull" if you want to integrate the remote branch with yours)
128 # Changes to be committed:
129 # (use "git restore --staged <file>..." to unstage)
130 # new file: dir2/added
132 # Changes not staged for commit:
133 # (use "git add <file>..." to update what will be committed)
134 # (use "git restore <file>..." to discard changes in working directory)
135 # modified: dir1/modified
138 # (use "git add <file>..." to include in what will be committed)
146 test_expect_success
'status with status.displayCommentPrefix=true' '
147 git -c status.displayCommentPrefix=true status >output &&
148 test_cmp expect output
151 test_expect_success
'status with status.displayCommentPrefix=false' '
152 strip_comments expect &&
153 git -c status.displayCommentPrefix=false status >output &&
154 test_cmp expect output
157 test_expect_success
'status -v' '
158 (cat expect && git diff --cached) >expect-with-v &&
159 git status -v >output &&
160 test_cmp expect-with-v output
163 test_expect_success
'status -v -v' '
165 echo "Changes to be committed:" &&
166 git -c diff.mnemonicprefix=true diff --cached &&
167 echo "--------------------------------------------------" &&
168 echo "Changes not staged for commit:" &&
169 git -c diff.mnemonicprefix=true diff) >expect-with-v &&
170 git status -v -v >output &&
171 test_cmp expect-with-v output
174 test_expect_success
'setup fake editor' '
175 cat >.git/editor <<-\EOF &&
179 chmod 755 .git/editor
182 commit_template_commented
() {
184 EDITOR
=.git
/editor
&&
186 # Fails due to empty message
187 test_must_fail git commit
189 ! grep '^[^#]' output
192 test_expect_success
'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
193 commit_template_commented
198 Your branch and
'upstream' have diverged
,
199 and have
1 and
2 different commits each
, respectively.
201 Changes to be committed
:
204 Changes not staged
for commit
:
205 modified
: dir
1/modified
215 test_expect_success
'status (advice.statusHints false)' '
216 test_config advice.statusHints false &&
217 git status >output &&
218 test_cmp expect output
231 test_expect_success
'status -s' '
233 git status -s >output &&
234 test_cmp expect output
238 test_expect_success
'status with gitignore' '
246 cat >expect <<-\EOF &&
251 git status -s >output &&
252 test_cmp expect output &&
254 cat >expect <<-\EOF &&
266 git status -s --ignored >output &&
267 test_cmp expect output &&
269 cat >expect <<\EOF &&
271 Your branch and '\''upstream'\'' have diverged,
272 and have 1 and 2 different commits each, respectively.
273 (use "git pull" if you want to integrate the remote branch with yours)
275 Changes to be committed:
276 (use "git restore --staged <file>..." to unstage)
279 Changes not staged for commit:
280 (use "git add <file>..." to update what will be committed)
281 (use "git restore <file>..." to discard changes in working directory)
282 modified: dir1/modified
285 (use "git add <file>..." to include in what will be committed)
289 (use "git add -f <file>..." to include in what will be committed)
299 git status --ignored >output &&
300 test_cmp expect output
303 test_expect_success
'status with gitignore (nothing untracked)' '
307 echo "dir2/modified" &&
312 cat >expect <<-\EOF &&
316 git status -s >output &&
317 test_cmp expect output &&
319 cat >expect <<-\EOF &&
331 git status -s --ignored >output &&
332 test_cmp expect output &&
334 cat >expect <<\EOF &&
336 Your branch and '\''upstream'\'' have diverged,
337 and have 1 and 2 different commits each, respectively.
338 (use "git pull" if you want to integrate the remote branch with yours)
340 Changes to be committed:
341 (use "git restore --staged <file>..." to unstage)
344 Changes not staged for commit:
345 (use "git add <file>..." to update what will be committed)
346 (use "git restore <file>..." to discard changes in working directory)
347 modified: dir1/modified
350 (use "git add -f <file>..." to include in what will be committed)
361 git status --ignored >output &&
362 test_cmp expect output
365 cat >.gitignore
<<\EOF
372 ## main...upstream [ahead 1, behind 2]
381 test_expect_success
'status -s -b' '
383 git status -s -b >output &&
384 test_cmp expect output
388 test_expect_success
'status -s -z -b' '
389 tr "\\n" Q <expect >expect.q &&
390 mv expect.q expect &&
391 git status -s -z -b >output &&
392 nul_to_q <output >output.q &&
393 mv output.q output &&
394 test_cmp expect output
397 test_expect_success
'setup dir3' '
399 : >dir3/untracked1 &&
403 test_expect_success
'status -uno' '
406 Your branch and '\''upstream'\'' have diverged,
407 and have 1 and 2 different commits each, respectively.
408 (use "git pull" if you want to integrate the remote branch with yours)
410 Changes to be committed:
411 (use "git restore --staged <file>..." to unstage)
414 Changes not staged for commit:
415 (use "git add <file>..." to update what will be committed)
416 (use "git restore <file>..." to discard changes in working directory)
417 modified: dir1/modified
419 Untracked files not listed (use -u option to show untracked files)
421 git status -uno >output &&
422 test_cmp expect output &&
423 git status -ufalse >output &&
424 test_cmp expect output
429 test_expect_success
"status (status.showUntrackedFiles $no)" '
430 test_config status.showuntrackedfiles "$no" &&
431 git status >output &&
432 test_cmp expect output
436 test_expect_success
'status -uno (advice.statusHints false)' '
439 Your branch and '\''upstream'\'' have diverged,
440 and have 1 and 2 different commits each, respectively.
442 Changes to be committed:
445 Changes not staged for commit:
446 modified: dir1/modified
448 Untracked files not listed
450 test_config advice.statusHints false &&
451 git status -uno >output &&
452 test_cmp expect output
459 test_expect_success
'status -s -uno' '
460 git status -s -uno >output &&
461 test_cmp expect output
464 test_expect_success
'status -s (status.showUntrackedFiles no)' '
465 git config status.showuntrackedfiles no &&
466 git status -s >output &&
467 test_cmp expect output
470 test_expect_success
'status -unormal' '
473 Your branch and '\''upstream'\'' have diverged,
474 and have 1 and 2 different commits each, respectively.
475 (use "git pull" if you want to integrate the remote branch with yours)
477 Changes to be committed:
478 (use "git restore --staged <file>..." to unstage)
481 Changes not staged for commit:
482 (use "git add <file>..." to update what will be committed)
483 (use "git restore <file>..." to discard changes in working directory)
484 modified: dir1/modified
487 (use "git add <file>..." to include in what will be committed)
495 git status -unormal >output &&
496 test_cmp expect output &&
497 git status -utrue >output &&
498 test_cmp expect output &&
499 git status -uyes >output &&
500 test_cmp expect output
503 for normal
in normal true
1
505 test_expect_success
"status (status.showUntrackedFiles $normal)" '
506 test_config status.showuntrackedfiles $normal &&
507 git status >output &&
508 test_cmp expect output
521 test_expect_success
'status -s -unormal' '
522 git status -s -unormal >output &&
523 test_cmp expect output
526 test_expect_success
'status -s (status.showUntrackedFiles normal)' '
527 git config status.showuntrackedfiles normal &&
528 git status -s >output &&
529 test_cmp expect output
532 test_expect_success
'status -uall' '
535 Your branch and '\''upstream'\'' have diverged,
536 and have 1 and 2 different commits each, respectively.
537 (use "git pull" if you want to integrate the remote branch with yours)
539 Changes to be committed:
540 (use "git restore --staged <file>..." to unstage)
543 Changes not staged for commit:
544 (use "git add <file>..." to update what will be committed)
545 (use "git restore <file>..." to discard changes in working directory)
546 modified: dir1/modified
549 (use "git add <file>..." to include in what will be committed)
558 git status -uall >output &&
559 test_cmp expect output
562 test_expect_success
'status (status.showUntrackedFiles all)' '
563 test_config status.showuntrackedfiles all &&
564 git status >output &&
565 test_cmp expect output
568 test_expect_success
'teardown dir3' '
580 test_expect_success
'status -s -uall' '
581 test_unconfig status.showuntrackedfiles &&
582 git status -s -uall >output &&
583 test_cmp expect output
585 test_expect_success
'status -s (status.showUntrackedFiles all)' '
586 test_config status.showuntrackedfiles all &&
587 git status -s >output &&
589 test_cmp expect output
592 test_expect_success
'status with relative paths' '
593 cat >expect <<\EOF &&
595 Your branch and '\''upstream'\'' have diverged,
596 and have 1 and 2 different commits each, respectively.
597 (use "git pull" if you want to integrate the remote branch with yours)
599 Changes to be committed:
600 (use "git restore --staged <file>..." to unstage)
601 new file: ../dir2/added
603 Changes not staged for commit:
604 (use "git add <file>..." to update what will be committed)
605 (use "git restore <file>..." to discard changes in working directory)
609 (use "git add <file>..." to include in what will be committed)
616 (cd dir1 && git status) >output &&
617 test_cmp expect output
628 test_expect_success
'status -s with relative paths' '
630 (cd dir1 && git status -s) >output &&
631 test_cmp expect output
644 test_expect_success
'status --porcelain ignores relative paths setting' '
646 (cd dir1 && git status --porcelain) >output &&
647 test_cmp expect output
651 test_expect_success
'setup unique colors' '
653 git config status.color.untracked blue &&
654 git config status.color.branch green &&
655 git config status.color.localBranch yellow &&
656 git config status.color.remoteBranch cyan
660 test_expect_success TTY
'status with color.ui' '
661 cat >expect <<\EOF &&
662 On branch <GREEN>main<RESET>
663 Your branch and '\''upstream'\'' have diverged,
664 and have 1 and 2 different commits each, respectively.
665 (use "git pull" if you want to integrate the remote branch with yours)
667 Changes to be committed:
668 (use "git restore --staged <file>..." to unstage)
669 <GREEN>new file: dir2/added<RESET>
671 Changes not staged for commit:
672 (use "git add <file>..." to update what will be committed)
673 (use "git restore <file>..." to discard changes in working directory)
674 <RED>modified: dir1/modified<RESET>
677 (use "git add <file>..." to include in what will be committed)
678 <BLUE>dir1/untracked<RESET>
679 <BLUE>dir2/modified<RESET>
680 <BLUE>dir2/untracked<RESET>
681 <BLUE>untracked<RESET>
684 test_config color.ui auto &&
685 test_terminal git status | test_decode_color >output &&
686 test_cmp expect output
689 test_expect_success TTY
'status with color.status' '
690 test_config color.status auto &&
691 test_terminal git status | test_decode_color >output &&
692 test_cmp expect output
696 <RED
>M
<RESET
> dir
1/modified
697 <GREEN
>A
<RESET
> dir
2/added
698 <BLUE
>??
<RESET
> dir
1/untracked
699 <BLUE
>??
<RESET
> dir
2/modified
700 <BLUE
>??
<RESET
> dir
2/untracked
701 <BLUE
>??
<RESET
> untracked
704 test_expect_success TTY
'status -s with color.ui' '
706 git config color.ui auto &&
707 test_terminal git status -s | test_decode_color >output &&
708 test_cmp expect output
712 test_expect_success TTY
'status -s with color.status' '
714 git config --unset color.ui &&
715 git config color.status auto &&
716 test_terminal git status -s | test_decode_color >output &&
717 test_cmp expect output
722 ## <YELLOW>main<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
723 <RED
>M
<RESET
> dir
1/modified
724 <GREEN
>A
<RESET
> dir
2/added
725 <BLUE
>??
<RESET
> dir
1/untracked
726 <BLUE
>??
<RESET
> dir
2/modified
727 <BLUE
>??
<RESET
> dir
2/untracked
728 <BLUE
>??
<RESET
> untracked
731 test_expect_success TTY
'status -s -b with color.status' '
733 test_terminal git status -s -b | test_decode_color >output &&
734 test_cmp expect output
747 test_expect_success TTY
'status --porcelain ignores color.ui' '
749 git config --unset color.status &&
750 git config color.ui auto &&
751 test_terminal git status --porcelain | test_decode_color >output &&
752 test_cmp expect output
756 test_expect_success TTY
'status --porcelain ignores color.status' '
758 git config --unset color.ui &&
759 git config color.status auto &&
760 test_terminal git status --porcelain | test_decode_color >output &&
761 test_cmp expect output
765 # recover unconditionally from color tests
766 git config
--unset color.status
767 git config
--unset color.ui
769 test_expect_success
'status --porcelain respects -b' '
771 git status --porcelain -b >output &&
773 echo "## main...upstream [ahead 1, behind 2]" &&
777 test_cmp expect output
783 test_expect_success
'status without relative paths' '
784 cat >expect <<\EOF &&
786 Your branch and '\''upstream'\'' have diverged,
787 and have 1 and 2 different commits each, respectively.
788 (use "git pull" if you want to integrate the remote branch with yours)
790 Changes to be committed:
791 (use "git restore --staged <file>..." to unstage)
794 Changes not staged for commit:
795 (use "git add <file>..." to update what will be committed)
796 (use "git restore <file>..." to discard changes in working directory)
797 modified: dir1/modified
800 (use "git add <file>..." to include in what will be committed)
807 test_config status.relativePaths false &&
808 (cd dir1 && git status) >output &&
809 test_cmp expect output
822 test_expect_success
'status -s without relative paths' '
824 test_config status.relativePaths false &&
825 (cd dir1 && git status -s) >output &&
826 test_cmp expect output
837 ??
"file with spaces 2"
841 test_expect_success
'status -s without relative paths' '
842 test_when_finished "git rm --cached \"file with spaces\"; rm -f file*" &&
843 >"file with spaces" &&
844 >"file with spaces 2" &&
845 >"expect with spaces" &&
846 git add "file with spaces" &&
848 git status -s >output &&
849 test_cmp expect output &&
851 git status -s --ignored >output &&
852 grep "^!! \"expect with spaces\"$" output &&
853 grep -v "^!! " output >output-wo-ignored &&
854 test_cmp expect output-wo-ignored
857 test_expect_success
'dry-run of partial commit excluding new file in index' '
860 Your branch and '\''upstream'\'' have diverged,
861 and have 1 and 2 different commits each, respectively.
863 Changes to be committed:
864 (use "git restore --staged <file>..." to unstage)
865 modified: dir1/modified
868 (use "git add <file>..." to include in what will be committed)
874 git commit --dry-run dir1/modified >output &&
875 test_cmp expect output
879 :100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified
881 test_expect_success
'status refreshes the index' '
884 git diff-files >output &&
885 test_cmp expect output
888 test_expect_success
'status shows detached HEAD properly after checking out non-local upstream branch' '
889 test_when_finished rm -rf upstream downstream actual &&
891 test_create_repo upstream &&
892 test_commit -C upstream foo &&
894 git clone upstream downstream &&
895 git -C downstream checkout @{u} &&
896 git -C downstream status >actual &&
897 grep -E "HEAD detached at [0-9a-f]+" actual
900 test_expect_success
'setup status submodule summary' '
901 test_create_repo sm && (
905 git commit -m "Add foo"
910 test_expect_success
'status submodule summary is disabled by default' '
913 Your branch and '\''upstream'\'' have diverged,
914 and have 1 and 2 different commits each, respectively.
915 (use "git pull" if you want to integrate the remote branch with yours)
917 Changes to be committed:
918 (use "git restore --staged <file>..." to unstage)
922 Changes not staged for commit:
923 (use "git add <file>..." to update what will be committed)
924 (use "git restore <file>..." to discard changes in working directory)
925 modified: dir1/modified
928 (use "git add <file>..." to include in what will be committed)
935 git status >output &&
936 test_cmp expect output
939 # we expect the same as the previous test
940 test_expect_success
'status --untracked-files=all does not show submodule' '
941 git status --untracked-files=all >output &&
942 test_cmp expect output
954 test_expect_success
'status -s submodule summary is disabled by default' '
955 git status -s >output &&
956 test_cmp expect output
959 # we expect the same as the previous test
960 test_expect_success
'status -s --untracked-files=all does not show submodule' '
961 git status -s --untracked-files=all >output &&
962 test_cmp expect output
965 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
967 test_expect_success
'status submodule summary' '
970 Your branch and '\''upstream'\'' have diverged,
971 and have 1 and 2 different commits each, respectively.
972 (use "git pull" if you want to integrate the remote branch with yours)
974 Changes to be committed:
975 (use "git restore --staged <file>..." to unstage)
979 Changes not staged for commit:
980 (use "git add <file>..." to update what will be committed)
981 (use "git restore <file>..." to discard changes in working directory)
982 modified: dir1/modified
984 Submodule changes to be committed:
986 * sm 0000000...$head (1):
990 (use "git add <file>..." to include in what will be committed)
997 git config status.submodulesummary 10 &&
998 git status >output &&
999 test_cmp expect output
1002 test_expect_success
'status submodule summary with status.displayCommentPrefix=false' '
1003 strip_comments expect &&
1004 git -c status.displayCommentPrefix=false status >output &&
1005 test_cmp expect output
1008 test_expect_success
'commit with submodule summary ignores status.displayCommentPrefix' '
1009 commit_template_commented
1021 test_expect_success
'status -s submodule summary' '
1022 git status -s >output &&
1023 test_cmp expect output
1026 test_expect_success
'status submodule summary (clean submodule): commit' '
1027 cat >expect-status <<EOF &&
1029 Your branch and '\''upstream'\'' have diverged,
1030 and have 2 and 2 different commits each, respectively.
1031 (use "git pull" if you want to integrate the remote branch with yours)
1033 Changes not staged for commit:
1034 (use "git add <file>..." to update what will be committed)
1035 (use "git restore <file>..." to discard changes in working directory)
1036 modified: dir1/modified
1039 (use "git add <file>..." to include in what will be committed)
1045 no changes added to commit (use "git add" and/or "git commit -a")
1047 sed "/git pull/d" expect-status > expect-commit &&
1048 git commit -m "commit submodule" &&
1049 git config status.submodulesummary 10 &&
1050 test_must_fail git commit --dry-run >output &&
1051 test_cmp expect-commit output &&
1052 git status >output &&
1053 test_cmp expect-status output
1063 test_expect_success
'status -s submodule summary (clean submodule)' '
1064 git status -s >output &&
1065 test_cmp expect output
1068 test_expect_success
'status -z implies porcelain' '
1069 git status --porcelain |
1070 perl -pe "s/\012/\000/g" >expect &&
1071 git status -z >output &&
1072 test_cmp expect output
1075 test_expect_success
'commit --dry-run submodule summary (--amend)' '
1076 cat >expect <<EOF &&
1078 Your branch and '\''upstream'\'' have diverged,
1079 and have 2 and 2 different commits each, respectively.
1081 Changes to be committed:
1082 (use "git restore --source=HEAD^1 --staged <file>..." to unstage)
1083 new file: dir2/added
1086 Changes not staged for commit:
1087 (use "git add <file>..." to update what will be committed)
1088 (use "git restore <file>..." to discard changes in working directory)
1089 modified: dir1/modified
1091 Submodule changes to be committed:
1093 * sm 0000000...$head (1):
1097 (use "git add <file>..." to include in what will be committed)
1104 git config status.submodulesummary 10 &&
1105 git commit --dry-run --amend >output &&
1106 test_cmp expect output
1109 test_expect_success POSIXPERM
,SANITY
'status succeeds in a read-only repository' '
1110 test_when_finished "chmod 775 .git" &&
1113 # make dir1/tracked stat-dirty
1114 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1115 git status -s >output &&
1116 ! grep dir1/tracked output &&
1117 # make sure "status" succeeded without writing index out
1118 git diff-files | grep dir1/tracked
1122 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar') && git add sm
1123 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
1126 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
1127 cat > expect << EOF &&
1129 Your branch and '\''upstream'\'' have diverged,
1130 and have 2 and 2 different commits each, respectively.
1131 (use "git pull" if you want to integrate the remote branch with yours)
1133 Changes to be committed:
1134 (use "git restore --staged <file>..." to unstage)
1137 Changes not staged for commit:
1138 (use "git add <file>..." to update what will be committed)
1139 (use "git restore <file>..." to discard changes in working directory)
1140 modified: dir1/modified
1142 Submodule changes to be committed:
1144 * sm $head...$new_head (1):
1148 (use "git add <file>..." to include in what will be committed)
1156 echo modified sm/untracked &&
1157 git status --ignore-submodules=untracked >output &&
1158 test_cmp expect output
1161 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
1162 test_config diff.ignoreSubmodules dirty &&
1163 git status >output &&
1164 test_cmp expect output &&
1165 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1166 git config --add -f .gitmodules submodule.subname.path sm &&
1167 git status >output &&
1168 test_cmp expect output &&
1169 git config -f .gitmodules --remove-section submodule.subname
1172 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
1173 git config --add -f .gitmodules submodule.subname.ignore none &&
1174 git config --add -f .gitmodules submodule.subname.path sm &&
1175 git config --add submodule.subname.ignore untracked &&
1176 git config --add submodule.subname.path sm &&
1177 git status >output &&
1178 test_cmp expect output &&
1179 git config --remove-section submodule.subname &&
1180 git config --remove-section -f .gitmodules submodule.subname
1183 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
1184 git status --ignore-submodules=dirty >output &&
1185 test_cmp expect output
1188 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
1189 test_config diff.ignoreSubmodules dirty &&
1190 git status >output &&
1192 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1193 git config --add -f .gitmodules submodule.subname.path sm &&
1194 git status >output &&
1195 test_cmp expect output &&
1196 git config -f .gitmodules --remove-section submodule.subname
1199 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
1200 git config --add -f .gitmodules submodule.subname.ignore none &&
1201 git config --add -f .gitmodules submodule.subname.path sm &&
1202 git config --add submodule.subname.ignore dirty &&
1203 git config --add submodule.subname.path sm &&
1204 git status >output &&
1205 test_cmp expect output &&
1206 git config --remove-section submodule.subname &&
1207 git config -f .gitmodules --remove-section submodule.subname
1210 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
1211 echo modified >sm/foo &&
1212 git status --ignore-submodules=dirty >output &&
1213 test_cmp expect output
1216 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
1217 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1218 git config --add -f .gitmodules submodule.subname.path sm &&
1219 git status >output &&
1220 test_cmp expect output &&
1221 git config -f .gitmodules --remove-section submodule.subname
1224 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
1225 git config --add -f .gitmodules submodule.subname.ignore none &&
1226 git config --add -f .gitmodules submodule.subname.path sm &&
1227 git config --add submodule.subname.ignore dirty &&
1228 git config --add submodule.subname.path sm &&
1229 git status >output &&
1230 test_cmp expect output &&
1231 git config --remove-section submodule.subname &&
1232 git config -f .gitmodules --remove-section submodule.subname
1235 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1236 cat > expect << EOF &&
1238 Your branch and '\''upstream'\'' have diverged,
1239 and have 2 and 2 different commits each, respectively.
1240 (use "git pull" if you want to integrate the remote branch with yours)
1242 Changes to be committed:
1243 (use "git restore --staged <file>..." to unstage)
1246 Changes not staged for commit:
1247 (use "git add <file>..." to update what will be committed)
1248 (use "git restore <file>..." to discard changes in working directory)
1249 (commit or discard the untracked or modified content in submodules)
1250 modified: dir1/modified
1251 modified: sm (modified content)
1253 Submodule changes to be committed:
1255 * sm $head...$new_head (1):
1259 (use "git add <file>..." to include in what will be committed)
1267 git status --ignore-submodules=untracked > output &&
1268 test_cmp expect output
1271 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1272 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1273 git config --add -f .gitmodules submodule.subname.path sm &&
1274 git status >output &&
1275 test_cmp expect output &&
1276 git config -f .gitmodules --remove-section submodule.subname
1279 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
1280 git config --add -f .gitmodules submodule.subname.ignore none &&
1281 git config --add -f .gitmodules submodule.subname.path sm &&
1282 git config --add submodule.subname.ignore untracked &&
1283 git config --add submodule.subname.path sm &&
1284 git status >output &&
1285 test_cmp expect output &&
1286 git config --remove-section submodule.subname &&
1287 git config -f .gitmodules --remove-section submodule.subname
1290 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
1292 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1293 cat > expect << EOF &&
1295 Your branch and '\''upstream'\'' have diverged,
1296 and have 2 and 2 different commits each, respectively.
1297 (use "git pull" if you want to integrate the remote branch with yours)
1299 Changes to be committed:
1300 (use "git restore --staged <file>..." to unstage)
1303 Changes not staged for commit:
1304 (use "git add <file>..." to update what will be committed)
1305 (use "git restore <file>..." to discard changes in working directory)
1306 modified: dir1/modified
1307 modified: sm (new commits)
1309 Submodule changes to be committed:
1311 * sm $head...$new_head (1):
1314 Submodules changed but not updated:
1316 * sm $new_head...$head2 (1):
1320 (use "git add <file>..." to include in what will be committed)
1328 git status --ignore-submodules=untracked > output &&
1329 test_cmp expect output
1332 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1333 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1334 git config --add -f .gitmodules submodule.subname.path sm &&
1335 git status >output &&
1336 test_cmp expect output &&
1337 git config -f .gitmodules --remove-section submodule.subname
1340 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
1341 git config --add -f .gitmodules submodule.subname.ignore none &&
1342 git config --add -f .gitmodules submodule.subname.path sm &&
1343 git config --add submodule.subname.ignore untracked &&
1344 git config --add submodule.subname.path sm &&
1345 git status >output &&
1346 test_cmp expect output &&
1347 git config --remove-section submodule.subname &&
1348 git config -f .gitmodules --remove-section submodule.subname
1351 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1352 git status --ignore-submodules=dirty > output &&
1353 test_cmp expect output
1355 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1356 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1357 git config --add -f .gitmodules submodule.subname.path sm &&
1358 git status >output &&
1359 test_cmp expect output &&
1360 git config -f .gitmodules --remove-section submodule.subname
1363 test_expect_success
".git/config ignore=dirty doesn't suppress submodule summary" '
1364 git config --add -f .gitmodules submodule.subname.ignore none &&
1365 git config --add -f .gitmodules submodule.subname.path sm &&
1366 git config --add submodule.subname.ignore dirty &&
1367 git config --add submodule.subname.path sm &&
1368 git status >output &&
1369 test_cmp expect output &&
1370 git config --remove-section submodule.subname &&
1371 git config -f .gitmodules --remove-section submodule.subname
1376 ; Your branch and 'upstream' have diverged,
1377 ; and have 2 and 2 different commits each, respectively.
1378 ; (use "git pull" if you want to integrate the remote branch with yours)
1380 ; Changes to be committed:
1381 ; (use "git restore --staged <file>..." to unstage)
1384 ; Changes not staged for commit:
1385 ; (use "git add <file>..." to update what will be committed)
1386 ; (use "git restore <file>..." to discard changes in working directory)
1387 ; modified: dir1/modified
1388 ; modified: sm (new commits)
1390 ; Submodule changes to be committed:
1392 ; * sm $head...$new_head (1):
1395 ; Submodules changed but not updated:
1397 ; * sm $new_head...$head2 (1):
1401 ; (use "git add <file>..." to include in what will be committed)
1410 test_expect_success
"status (core.commentchar with submodule summary)" '
1411 test_config core.commentchar ";" &&
1412 git -c status.displayCommentPrefix=true status >output &&
1413 test_cmp expect output
1416 test_expect_success
"status (core.commentchar with two chars with submodule summary)" '
1417 test_config core.commentchar ";;" &&
1418 sed "s/^/;/" <expect >expect.double &&
1419 git -c status.displayCommentPrefix=true status >output &&
1420 test_cmp expect.double output
1423 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1424 cat > expect << EOF &&
1426 Your branch and '\''upstream'\'' have diverged,
1427 and have 2 and 2 different commits each, respectively.
1428 (use "git pull" if you want to integrate the remote branch with yours)
1430 Changes not staged for commit:
1431 (use "git add <file>..." to update what will be committed)
1432 (use "git restore <file>..." to discard changes in working directory)
1433 modified: dir1/modified
1436 (use "git add <file>..." to include in what will be committed)
1443 no changes added to commit (use "git add" and/or "git commit -a")
1445 git status --ignore-submodules=all > output &&
1446 test_cmp expect output
1449 test_expect_success
'.gitmodules ignore=all suppresses unstaged submodule summary' '
1450 cat > expect << EOF &&
1452 Your branch and '\''upstream'\'' have diverged,
1453 and have 2 and 2 different commits each, respectively.
1454 (use "git pull" if you want to integrate the remote branch with yours)
1456 Changes to be committed:
1457 (use "git restore --staged <file>..." to unstage)
1460 Changes not staged for commit:
1461 (use "git add <file>..." to update what will be committed)
1462 (use "git restore <file>..." to discard changes in working directory)
1463 modified: dir1/modified
1466 (use "git add <file>..." to include in what will be committed)
1474 git config --add -f .gitmodules submodule.subname.ignore all &&
1475 git config --add -f .gitmodules submodule.subname.path sm &&
1476 git status > output &&
1477 test_cmp expect output &&
1478 git config -f .gitmodules --remove-section submodule.subname
1481 test_expect_success
'.git/config ignore=all suppresses unstaged submodule summary' '
1482 git config --add -f .gitmodules submodule.subname.ignore none &&
1483 git config --add -f .gitmodules submodule.subname.path sm &&
1484 git config --add submodule.subname.ignore all &&
1485 git config --add submodule.subname.path sm &&
1486 git status > output &&
1487 test_cmp expect output &&
1488 git config --remove-section submodule.subname &&
1489 git config -f .gitmodules --remove-section submodule.subname
1492 test_expect_success
'setup of test environment' '
1493 git config status.showUntrackedFiles no &&
1494 git status -s >expected_short &&
1495 git status --no-short >expected_noshort
1498 test_expect_success
'"status.short=true" same as "-s"' '
1499 git -c status.short=true status >actual &&
1500 test_cmp expected_short actual
1503 test_expect_success
'"status.short=true" weaker than "--no-short"' '
1504 git -c status.short=true status --no-short >actual &&
1505 test_cmp expected_noshort actual
1508 test_expect_success
'"status.short=false" same as "--no-short"' '
1509 git -c status.short=false status >actual &&
1510 test_cmp expected_noshort actual
1513 test_expect_success
'"status.short=false" weaker than "-s"' '
1514 git -c status.short=false status -s >actual &&
1515 test_cmp expected_short actual
1518 test_expect_success
'"status.branch=true" same as "-b"' '
1519 git status -sb >expected_branch &&
1520 git -c status.branch=true status -s >actual &&
1521 test_cmp expected_branch actual
1524 test_expect_success
'"status.branch=true" different from "--no-branch"' '
1525 git status -s --no-branch >expected_nobranch &&
1526 git -c status.branch=true status -s >actual &&
1527 ! test_cmp expected_nobranch actual
1530 test_expect_success
'"status.branch=true" weaker than "--no-branch"' '
1531 git -c status.branch=true status -s --no-branch >actual &&
1532 test_cmp expected_nobranch actual
1535 test_expect_success
'"status.branch=true" weaker than "--porcelain"' '
1536 git -c status.branch=true status --porcelain >actual &&
1537 test_cmp expected_nobranch actual
1540 test_expect_success
'"status.branch=false" same as "--no-branch"' '
1541 git -c status.branch=false status -s >actual &&
1542 test_cmp expected_nobranch actual
1545 test_expect_success
'"status.branch=false" weaker than "-b"' '
1546 git -c status.branch=false status -sb >actual &&
1547 test_cmp expected_branch actual
1550 test_expect_success
'Restore default test environment' '
1551 git config --unset status.showUntrackedFiles
1554 test_expect_success
'git commit will commit a staged but ignored submodule' '
1555 git config --add -f .gitmodules submodule.subname.ignore all &&
1556 git config --add -f .gitmodules submodule.subname.path sm &&
1557 git config --add submodule.subname.ignore all &&
1558 git status -s --ignore-submodules=dirty >output &&
1559 test_grep "^M. sm" output &&
1560 GIT_EDITOR="echo hello >>\"\$1\"" &&
1561 export GIT_EDITOR &&
1563 git status -s --ignore-submodules=dirty >output &&
1564 test_grep ! "^M. sm" output
1567 test_expect_success
'git commit --dry-run will show a staged but ignored submodule' '
1570 cat >expect << EOF &&
1572 Your branch and '\''upstream'\'' have diverged,
1573 and have 2 and 2 different commits each, respectively.
1575 Changes to be committed:
1576 (use "git restore --staged <file>..." to unstage)
1579 Changes not staged for commit:
1580 (use "git add <file>..." to update what will be committed)
1581 (use "git restore <file>..." to discard changes in working directory)
1582 modified: dir1/modified
1584 Untracked files not listed (use -u option to show untracked files)
1586 git commit -uno --dry-run >output &&
1587 test_cmp expect output &&
1588 git status -s --ignore-submodules=dirty >output &&
1589 test_grep "^M. sm" output
1592 test_expect_success
'git commit -m will commit a staged but ignored submodule' '
1593 git commit -uno -m message &&
1594 git status -s --ignore-submodules=dirty >output &&
1595 test_grep ! "^M. sm" output &&
1596 git config --remove-section submodule.subname &&
1597 git config -f .gitmodules --remove-section submodule.subname
1600 test_expect_success
'show stash info with "--show-stash"' '
1606 git status >expected_default &&
1607 git status --show-stash >expected_with_stash &&
1608 test_grep "^Your stash currently has 1 entry$" expected_with_stash
1611 test_expect_success
'no stash info with "--show-stash --no-show-stash"' '
1612 git status --show-stash --no-show-stash >expected_without_stash &&
1613 test_cmp expected_default expected_without_stash
1616 test_expect_success
'"status.showStash=false" weaker than "--show-stash"' '
1617 git -c status.showStash=false status --show-stash >actual &&
1618 test_cmp expected_with_stash actual
1621 test_expect_success
'"status.showStash=true" weaker than "--no-show-stash"' '
1622 git -c status.showStash=true status --no-show-stash >actual &&
1623 test_cmp expected_without_stash actual
1626 test_expect_success
'no additional info if no stash entries' '
1628 git -c status.showStash=true status >actual &&
1629 test_cmp expected_without_stash actual
1632 test_expect_success
'"No commits yet" should be noted in status output' '
1633 git checkout --orphan empty-branch-1 &&
1634 git status >output &&
1635 test_grep "No commits yet" output
1638 test_expect_success
'"No commits yet" should not be noted in status output' '
1639 git checkout --orphan empty-branch-2 &&
1640 test_commit test-commit-1 &&
1641 git status >output &&
1642 test_grep ! "No commits yet" output
1645 test_expect_success
'"Initial commit" should be noted in commit template' '
1646 git checkout --orphan empty-branch-3 &&
1647 touch to_be_committed_1 &&
1648 git add to_be_committed_1 &&
1649 git commit --dry-run >output &&
1650 test_grep "Initial commit" output
1653 test_expect_success
'"Initial commit" should not be noted in commit template' '
1654 git checkout --orphan empty-branch-4 &&
1655 test_commit test-commit-2 &&
1656 touch to_be_committed_2 &&
1657 git add to_be_committed_2 &&
1658 git commit --dry-run >output &&
1659 test_grep ! "Initial commit" output
1662 test_expect_success
'--no-optional-locks prevents index update' '
1663 test_set_magic_mtime .git/index &&
1664 git --no-optional-locks status &&
1665 test_is_magic_mtime .git/index &&
1667 ! test_is_magic_mtime .git/index
1670 test_expect_success
'racy timestamps will be fixed for clean worktree' '
1671 echo content >racy-dirty &&
1672 echo content >racy-racy &&
1674 git commit -m "racy test files" &&
1675 # let status rewrite the index, if necessary; after that we expect
1676 # no more index writes unless caused by racy timestamps; note that
1677 # timestamps may already be racy now (depending on previous tests)
1679 test_set_magic_mtime .git/index &&
1681 ! test_is_magic_mtime .git/index
1684 test_expect_success
'racy timestamps will be fixed for dirty worktree' '
1685 echo content2 >racy-dirty &&
1687 test_set_magic_mtime .git/index &&
1689 ! test_is_magic_mtime .git/index
1692 test_expect_success
'setup slow status advice' '
1693 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main git init slowstatus &&
1696 cat >.gitignore <<-\EOF &&
1701 git add .gitignore &&
1702 git commit -m "Add .gitignore" &&
1703 git config advice.statusuoption true
1707 test_expect_success
'slow status advice when core.untrackedCache and fsmonitor are unset' '
1710 git config core.untrackedCache false &&
1711 git config core.fsmonitor false &&
1712 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1713 cat >expected <<-\EOF &&
1716 It took 3.25 seconds to enumerate untracked files.
1717 See '\''git help status'\'' for information on how to improve this.
1719 nothing to commit, working tree clean
1721 test_cmp expected actual
1725 test_expect_success
'slow status advice when core.untrackedCache true, but not fsmonitor' '
1728 git config core.untrackedCache true &&
1729 git config core.fsmonitor false &&
1730 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1731 cat >expected <<-\EOF &&
1734 It took 3.25 seconds to enumerate untracked files.
1735 See '\''git help status'\'' for information on how to improve this.
1737 nothing to commit, working tree clean
1739 test_cmp expected actual
1743 test_expect_success
'slow status advice when core.untrackedCache true, and fsmonitor' '
1746 git config core.untrackedCache true &&
1747 git config core.fsmonitor true &&
1748 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1749 cat >expected <<-\EOF &&
1752 It took 3.25 seconds to enumerate untracked files,
1753 but the results were cached, and subsequent runs may be faster.
1754 See '\''git help status'\'' for information on how to improve this.
1756 nothing to commit, working tree clean
1758 test_cmp expected actual
1762 test_expect_success EXPENSIVE
'status does not re-read unchanged 4 or 8 GiB file' '
1766 # Files are 2 GiB, 4 GiB, and 8 GiB sparse files.
1767 test-tool truncate file-a 0x080000000 &&
1768 test-tool truncate file-b 0x100000000 &&
1769 test-tool truncate file-c 0x200000000 &&
1770 # This will be slow.
1771 git add file-a file-b file-c &&
1772 git commit -m "add large files" &&
1773 git diff-index HEAD file-a file-b file-c >actual &&
1774 test_must_be_empty actual