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_i18ngrep "[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_i18ngrep "[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_i18ngrep "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
425 test_expect_success
'status (status.showUntrackedFiles no)' '
426 test_config status.showuntrackedfiles no &&
427 git status >output &&
428 test_cmp expect output
431 test_expect_success
'status -uno (advice.statusHints false)' '
434 Your branch and '\''upstream'\'' have diverged,
435 and have 1 and 2 different commits each, respectively.
437 Changes to be committed:
440 Changes not staged for commit:
441 modified: dir1/modified
443 Untracked files not listed
445 test_config advice.statusHints false &&
446 git status -uno >output &&
447 test_cmp expect output
454 test_expect_success
'status -s -uno' '
455 git status -s -uno >output &&
456 test_cmp expect output
459 test_expect_success
'status -s (status.showUntrackedFiles no)' '
460 git config status.showuntrackedfiles no &&
461 git status -s >output &&
462 test_cmp expect output
465 test_expect_success
'status -unormal' '
468 Your branch and '\''upstream'\'' have diverged,
469 and have 1 and 2 different commits each, respectively.
470 (use "git pull" if you want to integrate the remote branch with yours)
472 Changes to be committed:
473 (use "git restore --staged <file>..." to unstage)
476 Changes not staged for commit:
477 (use "git add <file>..." to update what will be committed)
478 (use "git restore <file>..." to discard changes in working directory)
479 modified: dir1/modified
482 (use "git add <file>..." to include in what will be committed)
490 git status -unormal >output &&
491 test_cmp expect output
494 test_expect_success
'status (status.showUntrackedFiles normal)' '
495 test_config status.showuntrackedfiles normal &&
496 git status >output &&
497 test_cmp expect output
509 test_expect_success
'status -s -unormal' '
510 git status -s -unormal >output &&
511 test_cmp expect output
514 test_expect_success
'status -s (status.showUntrackedFiles normal)' '
515 git config status.showuntrackedfiles normal &&
516 git status -s >output &&
517 test_cmp expect output
520 test_expect_success
'status -uall' '
523 Your branch and '\''upstream'\'' have diverged,
524 and have 1 and 2 different commits each, respectively.
525 (use "git pull" if you want to integrate the remote branch with yours)
527 Changes to be committed:
528 (use "git restore --staged <file>..." to unstage)
531 Changes not staged for commit:
532 (use "git add <file>..." to update what will be committed)
533 (use "git restore <file>..." to discard changes in working directory)
534 modified: dir1/modified
537 (use "git add <file>..." to include in what will be committed)
546 git status -uall >output &&
547 test_cmp expect output
550 test_expect_success
'status (status.showUntrackedFiles all)' '
551 test_config status.showuntrackedfiles all &&
552 git status >output &&
553 test_cmp expect output
556 test_expect_success
'teardown dir3' '
568 test_expect_success
'status -s -uall' '
569 test_unconfig status.showuntrackedfiles &&
570 git status -s -uall >output &&
571 test_cmp expect output
573 test_expect_success
'status -s (status.showUntrackedFiles all)' '
574 test_config status.showuntrackedfiles all &&
575 git status -s >output &&
577 test_cmp expect output
580 test_expect_success
'status with relative paths' '
581 cat >expect <<\EOF &&
583 Your branch and '\''upstream'\'' have diverged,
584 and have 1 and 2 different commits each, respectively.
585 (use "git pull" if you want to integrate the remote branch with yours)
587 Changes to be committed:
588 (use "git restore --staged <file>..." to unstage)
589 new file: ../dir2/added
591 Changes not staged for commit:
592 (use "git add <file>..." to update what will be committed)
593 (use "git restore <file>..." to discard changes in working directory)
597 (use "git add <file>..." to include in what will be committed)
604 (cd dir1 && git status) >output &&
605 test_cmp expect output
616 test_expect_success
'status -s with relative paths' '
618 (cd dir1 && git status -s) >output &&
619 test_cmp expect output
632 test_expect_success
'status --porcelain ignores relative paths setting' '
634 (cd dir1 && git status --porcelain) >output &&
635 test_cmp expect output
639 test_expect_success
'setup unique colors' '
641 git config status.color.untracked blue &&
642 git config status.color.branch green &&
643 git config status.color.localBranch yellow &&
644 git config status.color.remoteBranch cyan
648 test_expect_success TTY
'status with color.ui' '
649 cat >expect <<\EOF &&
650 On branch <GREEN>main<RESET>
651 Your branch and '\''upstream'\'' have diverged,
652 and have 1 and 2 different commits each, respectively.
653 (use "git pull" if you want to integrate the remote branch with yours)
655 Changes to be committed:
656 (use "git restore --staged <file>..." to unstage)
657 <GREEN>new file: dir2/added<RESET>
659 Changes not staged for commit:
660 (use "git add <file>..." to update what will be committed)
661 (use "git restore <file>..." to discard changes in working directory)
662 <RED>modified: dir1/modified<RESET>
665 (use "git add <file>..." to include in what will be committed)
666 <BLUE>dir1/untracked<RESET>
667 <BLUE>dir2/modified<RESET>
668 <BLUE>dir2/untracked<RESET>
669 <BLUE>untracked<RESET>
672 test_config color.ui auto &&
673 test_terminal git status | test_decode_color >output &&
674 test_cmp expect output
677 test_expect_success TTY
'status with color.status' '
678 test_config color.status auto &&
679 test_terminal git status | test_decode_color >output &&
680 test_cmp expect output
684 <RED
>M
<RESET
> dir
1/modified
685 <GREEN
>A
<RESET
> dir
2/added
686 <BLUE
>??
<RESET
> dir
1/untracked
687 <BLUE
>??
<RESET
> dir
2/modified
688 <BLUE
>??
<RESET
> dir
2/untracked
689 <BLUE
>??
<RESET
> untracked
692 test_expect_success TTY
'status -s with color.ui' '
694 git config color.ui auto &&
695 test_terminal git status -s | test_decode_color >output &&
696 test_cmp expect output
700 test_expect_success TTY
'status -s with color.status' '
702 git config --unset color.ui &&
703 git config color.status auto &&
704 test_terminal git status -s | test_decode_color >output &&
705 test_cmp expect output
710 ## <YELLOW>main<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
711 <RED
>M
<RESET
> dir
1/modified
712 <GREEN
>A
<RESET
> dir
2/added
713 <BLUE
>??
<RESET
> dir
1/untracked
714 <BLUE
>??
<RESET
> dir
2/modified
715 <BLUE
>??
<RESET
> dir
2/untracked
716 <BLUE
>??
<RESET
> untracked
719 test_expect_success TTY
'status -s -b with color.status' '
721 test_terminal git status -s -b | test_decode_color >output &&
722 test_cmp expect output
735 test_expect_success TTY
'status --porcelain ignores color.ui' '
737 git config --unset color.status &&
738 git config color.ui auto &&
739 test_terminal git status --porcelain | test_decode_color >output &&
740 test_cmp expect output
744 test_expect_success TTY
'status --porcelain ignores color.status' '
746 git config --unset color.ui &&
747 git config color.status auto &&
748 test_terminal git status --porcelain | test_decode_color >output &&
749 test_cmp expect output
753 # recover unconditionally from color tests
754 git config
--unset color.status
755 git config
--unset color.ui
757 test_expect_success
'status --porcelain respects -b' '
759 git status --porcelain -b >output &&
761 echo "## main...upstream [ahead 1, behind 2]" &&
765 test_cmp expect output
771 test_expect_success
'status without relative paths' '
772 cat >expect <<\EOF &&
774 Your branch and '\''upstream'\'' have diverged,
775 and have 1 and 2 different commits each, respectively.
776 (use "git pull" if you want to integrate the remote branch with yours)
778 Changes to be committed:
779 (use "git restore --staged <file>..." to unstage)
782 Changes not staged for commit:
783 (use "git add <file>..." to update what will be committed)
784 (use "git restore <file>..." to discard changes in working directory)
785 modified: dir1/modified
788 (use "git add <file>..." to include in what will be committed)
795 test_config status.relativePaths false &&
796 (cd dir1 && git status) >output &&
797 test_cmp expect output
810 test_expect_success
'status -s without relative paths' '
812 test_config status.relativePaths false &&
813 (cd dir1 && git status -s) >output &&
814 test_cmp expect output
825 ??
"file with spaces 2"
829 test_expect_success
'status -s without relative paths' '
830 test_when_finished "git rm --cached \"file with spaces\"; rm -f file*" &&
831 >"file with spaces" &&
832 >"file with spaces 2" &&
833 >"expect with spaces" &&
834 git add "file with spaces" &&
836 git status -s >output &&
837 test_cmp expect output &&
839 git status -s --ignored >output &&
840 grep "^!! \"expect with spaces\"$" output &&
841 grep -v "^!! " output >output-wo-ignored &&
842 test_cmp expect output-wo-ignored
845 test_expect_success
'dry-run of partial commit excluding new file in index' '
848 Your branch and '\''upstream'\'' have diverged,
849 and have 1 and 2 different commits each, respectively.
851 Changes to be committed:
852 (use "git restore --staged <file>..." to unstage)
853 modified: dir1/modified
856 (use "git add <file>..." to include in what will be committed)
862 git commit --dry-run dir1/modified >output &&
863 test_cmp expect output
867 :100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified
869 test_expect_success
'status refreshes the index' '
872 git diff-files >output &&
873 test_cmp expect output
876 test_expect_success
'status shows detached HEAD properly after checking out non-local upstream branch' '
877 test_when_finished rm -rf upstream downstream actual &&
879 test_create_repo upstream &&
880 test_commit -C upstream foo &&
882 git clone upstream downstream &&
883 git -C downstream checkout @{u} &&
884 git -C downstream status >actual &&
885 grep -E "HEAD detached at [0-9a-f]+" actual
888 test_expect_success
'setup status submodule summary' '
889 test_create_repo sm && (
893 git commit -m "Add foo"
898 test_expect_success
'status submodule summary is disabled by default' '
901 Your branch and '\''upstream'\'' have diverged,
902 and have 1 and 2 different commits each, respectively.
903 (use "git pull" if you want to integrate the remote branch with yours)
905 Changes to be committed:
906 (use "git restore --staged <file>..." to unstage)
910 Changes not staged for commit:
911 (use "git add <file>..." to update what will be committed)
912 (use "git restore <file>..." to discard changes in working directory)
913 modified: dir1/modified
916 (use "git add <file>..." to include in what will be committed)
923 git status >output &&
924 test_cmp expect output
927 # we expect the same as the previous test
928 test_expect_success
'status --untracked-files=all does not show submodule' '
929 git status --untracked-files=all >output &&
930 test_cmp expect output
942 test_expect_success
'status -s submodule summary is disabled by default' '
943 git status -s >output &&
944 test_cmp expect output
947 # we expect the same as the previous test
948 test_expect_success
'status -s --untracked-files=all does not show submodule' '
949 git status -s --untracked-files=all >output &&
950 test_cmp expect output
953 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
955 test_expect_success
'status submodule summary' '
958 Your branch and '\''upstream'\'' have diverged,
959 and have 1 and 2 different commits each, respectively.
960 (use "git pull" if you want to integrate the remote branch with yours)
962 Changes to be committed:
963 (use "git restore --staged <file>..." to unstage)
967 Changes not staged for commit:
968 (use "git add <file>..." to update what will be committed)
969 (use "git restore <file>..." to discard changes in working directory)
970 modified: dir1/modified
972 Submodule changes to be committed:
974 * sm 0000000...$head (1):
978 (use "git add <file>..." to include in what will be committed)
985 git config status.submodulesummary 10 &&
986 git status >output &&
987 test_cmp expect output
990 test_expect_success
'status submodule summary with status.displayCommentPrefix=false' '
991 strip_comments expect &&
992 git -c status.displayCommentPrefix=false status >output &&
993 test_cmp expect output
996 test_expect_success
'commit with submodule summary ignores status.displayCommentPrefix' '
997 commit_template_commented
1009 test_expect_success
'status -s submodule summary' '
1010 git status -s >output &&
1011 test_cmp expect output
1014 test_expect_success
'status submodule summary (clean submodule): commit' '
1015 cat >expect-status <<EOF &&
1017 Your branch and '\''upstream'\'' have diverged,
1018 and have 2 and 2 different commits each, respectively.
1019 (use "git pull" if you want to integrate the remote branch with yours)
1021 Changes not staged for commit:
1022 (use "git add <file>..." to update what will be committed)
1023 (use "git restore <file>..." to discard changes in working directory)
1024 modified: dir1/modified
1027 (use "git add <file>..." to include in what will be committed)
1033 no changes added to commit (use "git add" and/or "git commit -a")
1035 sed "/git pull/d" expect-status > expect-commit &&
1036 git commit -m "commit submodule" &&
1037 git config status.submodulesummary 10 &&
1038 test_must_fail git commit --dry-run >output &&
1039 test_cmp expect-commit output &&
1040 git status >output &&
1041 test_cmp expect-status output
1051 test_expect_success
'status -s submodule summary (clean submodule)' '
1052 git status -s >output &&
1053 test_cmp expect output
1056 test_expect_success
'status -z implies porcelain' '
1057 git status --porcelain |
1058 perl -pe "s/\012/\000/g" >expect &&
1059 git status -z >output &&
1060 test_cmp expect output
1063 test_expect_success
'commit --dry-run submodule summary (--amend)' '
1064 cat >expect <<EOF &&
1066 Your branch and '\''upstream'\'' have diverged,
1067 and have 2 and 2 different commits each, respectively.
1069 Changes to be committed:
1070 (use "git restore --source=HEAD^1 --staged <file>..." to unstage)
1071 new file: dir2/added
1074 Changes not staged for commit:
1075 (use "git add <file>..." to update what will be committed)
1076 (use "git restore <file>..." to discard changes in working directory)
1077 modified: dir1/modified
1079 Submodule changes to be committed:
1081 * sm 0000000...$head (1):
1085 (use "git add <file>..." to include in what will be committed)
1092 git config status.submodulesummary 10 &&
1093 git commit --dry-run --amend >output &&
1094 test_cmp expect output
1097 test_expect_success POSIXPERM
,SANITY
'status succeeds in a read-only repository' '
1098 test_when_finished "chmod 775 .git" &&
1101 # make dir1/tracked stat-dirty
1102 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1103 git status -s >output &&
1104 ! grep dir1/tracked output &&
1105 # make sure "status" succeeded without writing index out
1106 git diff-files | grep dir1/tracked
1110 (cd sm
&& echo > bar
&& git add bar
&& git commit
-q -m 'Add bar') && git add sm
1111 new_head
=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
1114 test_expect_success
'--ignore-submodules=untracked suppresses submodules with untracked content' '
1115 cat > expect << EOF &&
1117 Your branch and '\''upstream'\'' have diverged,
1118 and have 2 and 2 different commits each, respectively.
1119 (use "git pull" if you want to integrate the remote branch with yours)
1121 Changes to be committed:
1122 (use "git restore --staged <file>..." to unstage)
1125 Changes not staged for commit:
1126 (use "git add <file>..." to update what will be committed)
1127 (use "git restore <file>..." to discard changes in working directory)
1128 modified: dir1/modified
1130 Submodule changes to be committed:
1132 * sm $head...$new_head (1):
1136 (use "git add <file>..." to include in what will be committed)
1144 echo modified sm/untracked &&
1145 git status --ignore-submodules=untracked >output &&
1146 test_cmp expect output
1149 test_expect_success
'.gitmodules ignore=untracked suppresses submodules with untracked content' '
1150 test_config diff.ignoreSubmodules dirty &&
1151 git status >output &&
1152 test_cmp expect output &&
1153 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1154 git config --add -f .gitmodules submodule.subname.path sm &&
1155 git status >output &&
1156 test_cmp expect output &&
1157 git config -f .gitmodules --remove-section submodule.subname
1160 test_expect_success
'.git/config ignore=untracked suppresses submodules with untracked content' '
1161 git config --add -f .gitmodules submodule.subname.ignore none &&
1162 git config --add -f .gitmodules submodule.subname.path sm &&
1163 git config --add submodule.subname.ignore untracked &&
1164 git config --add submodule.subname.path sm &&
1165 git status >output &&
1166 test_cmp expect output &&
1167 git config --remove-section submodule.subname &&
1168 git config --remove-section -f .gitmodules submodule.subname
1171 test_expect_success
'--ignore-submodules=dirty suppresses submodules with untracked content' '
1172 git status --ignore-submodules=dirty >output &&
1173 test_cmp expect output
1176 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with untracked content' '
1177 test_config diff.ignoreSubmodules dirty &&
1178 git status >output &&
1180 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1181 git config --add -f .gitmodules submodule.subname.path sm &&
1182 git status >output &&
1183 test_cmp expect output &&
1184 git config -f .gitmodules --remove-section submodule.subname
1187 test_expect_success
'.git/config ignore=dirty suppresses submodules with untracked content' '
1188 git config --add -f .gitmodules submodule.subname.ignore none &&
1189 git config --add -f .gitmodules submodule.subname.path sm &&
1190 git config --add submodule.subname.ignore dirty &&
1191 git config --add submodule.subname.path sm &&
1192 git status >output &&
1193 test_cmp expect output &&
1194 git config --remove-section submodule.subname &&
1195 git config -f .gitmodules --remove-section submodule.subname
1198 test_expect_success
'--ignore-submodules=dirty suppresses submodules with modified content' '
1199 echo modified >sm/foo &&
1200 git status --ignore-submodules=dirty >output &&
1201 test_cmp expect output
1204 test_expect_success
'.gitmodules ignore=dirty suppresses submodules with modified content' '
1205 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1206 git config --add -f .gitmodules submodule.subname.path sm &&
1207 git status >output &&
1208 test_cmp expect output &&
1209 git config -f .gitmodules --remove-section submodule.subname
1212 test_expect_success
'.git/config ignore=dirty suppresses submodules with modified content' '
1213 git config --add -f .gitmodules submodule.subname.ignore none &&
1214 git config --add -f .gitmodules submodule.subname.path sm &&
1215 git config --add submodule.subname.ignore dirty &&
1216 git config --add submodule.subname.path sm &&
1217 git status >output &&
1218 test_cmp expect output &&
1219 git config --remove-section submodule.subname &&
1220 git config -f .gitmodules --remove-section submodule.subname
1223 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1224 cat > expect << EOF &&
1226 Your branch and '\''upstream'\'' have diverged,
1227 and have 2 and 2 different commits each, respectively.
1228 (use "git pull" if you want to integrate the remote branch with yours)
1230 Changes to be committed:
1231 (use "git restore --staged <file>..." to unstage)
1234 Changes not staged for commit:
1235 (use "git add <file>..." to update what will be committed)
1236 (use "git restore <file>..." to discard changes in working directory)
1237 (commit or discard the untracked or modified content in submodules)
1238 modified: dir1/modified
1239 modified: sm (modified content)
1241 Submodule changes to be committed:
1243 * sm $head...$new_head (1):
1247 (use "git add <file>..." to include in what will be committed)
1255 git status --ignore-submodules=untracked > output &&
1256 test_cmp expect output
1259 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1260 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1261 git config --add -f .gitmodules submodule.subname.path sm &&
1262 git status >output &&
1263 test_cmp expect output &&
1264 git config -f .gitmodules --remove-section submodule.subname
1267 test_expect_success
".git/config ignore=untracked doesn't suppress submodules with modified content" '
1268 git config --add -f .gitmodules submodule.subname.ignore none &&
1269 git config --add -f .gitmodules submodule.subname.path sm &&
1270 git config --add submodule.subname.ignore untracked &&
1271 git config --add submodule.subname.path sm &&
1272 git status >output &&
1273 test_cmp expect output &&
1274 git config --remove-section submodule.subname &&
1275 git config -f .gitmodules --remove-section submodule.subname
1278 head2
=$
(cd sm
&& git commit
-q -m "2nd commit" foo
&& git rev-parse
--short=7 --verify HEAD
)
1280 test_expect_success
"--ignore-submodules=untracked doesn't suppress submodule summary" '
1281 cat > expect << EOF &&
1283 Your branch and '\''upstream'\'' have diverged,
1284 and have 2 and 2 different commits each, respectively.
1285 (use "git pull" if you want to integrate the remote branch with yours)
1287 Changes to be committed:
1288 (use "git restore --staged <file>..." to unstage)
1291 Changes not staged for commit:
1292 (use "git add <file>..." to update what will be committed)
1293 (use "git restore <file>..." to discard changes in working directory)
1294 modified: dir1/modified
1295 modified: sm (new commits)
1297 Submodule changes to be committed:
1299 * sm $head...$new_head (1):
1302 Submodules changed but not updated:
1304 * sm $new_head...$head2 (1):
1308 (use "git add <file>..." to include in what will be committed)
1316 git status --ignore-submodules=untracked > output &&
1317 test_cmp expect output
1320 test_expect_success
".gitmodules ignore=untracked doesn't suppress submodule summary" '
1321 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1322 git config --add -f .gitmodules submodule.subname.path sm &&
1323 git status >output &&
1324 test_cmp expect output &&
1325 git config -f .gitmodules --remove-section submodule.subname
1328 test_expect_success
".git/config ignore=untracked doesn't suppress submodule summary" '
1329 git config --add -f .gitmodules submodule.subname.ignore none &&
1330 git config --add -f .gitmodules submodule.subname.path sm &&
1331 git config --add submodule.subname.ignore untracked &&
1332 git config --add submodule.subname.path sm &&
1333 git status >output &&
1334 test_cmp expect output &&
1335 git config --remove-section submodule.subname &&
1336 git config -f .gitmodules --remove-section submodule.subname
1339 test_expect_success
"--ignore-submodules=dirty doesn't suppress submodule summary" '
1340 git status --ignore-submodules=dirty > output &&
1341 test_cmp expect output
1343 test_expect_success
".gitmodules ignore=dirty doesn't suppress submodule summary" '
1344 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1345 git config --add -f .gitmodules submodule.subname.path sm &&
1346 git status >output &&
1347 test_cmp expect output &&
1348 git config -f .gitmodules --remove-section submodule.subname
1351 test_expect_success
".git/config ignore=dirty doesn't suppress submodule summary" '
1352 git config --add -f .gitmodules submodule.subname.ignore none &&
1353 git config --add -f .gitmodules submodule.subname.path sm &&
1354 git config --add submodule.subname.ignore dirty &&
1355 git config --add submodule.subname.path sm &&
1356 git status >output &&
1357 test_cmp expect output &&
1358 git config --remove-section submodule.subname &&
1359 git config -f .gitmodules --remove-section submodule.subname
1364 ; Your branch and 'upstream' have diverged,
1365 ; and have 2 and 2 different commits each, respectively.
1366 ; (use "git pull" if you want to integrate the remote branch with yours)
1368 ; Changes to be committed:
1369 ; (use "git restore --staged <file>..." to unstage)
1372 ; Changes not staged for commit:
1373 ; (use "git add <file>..." to update what will be committed)
1374 ; (use "git restore <file>..." to discard changes in working directory)
1375 ; modified: dir1/modified
1376 ; modified: sm (new commits)
1378 ; Submodule changes to be committed:
1380 ; * sm $head...$new_head (1):
1383 ; Submodules changed but not updated:
1385 ; * sm $new_head...$head2 (1):
1389 ; (use "git add <file>..." to include in what will be committed)
1398 test_expect_success
"status (core.commentchar with submodule summary)" '
1399 test_config core.commentchar ";" &&
1400 git -c status.displayCommentPrefix=true status >output &&
1401 test_cmp expect output
1404 test_expect_success
"status (core.commentchar with two chars with submodule summary)" '
1405 test_config core.commentchar ";;" &&
1406 test_must_fail git -c status.displayCommentPrefix=true status
1409 test_expect_success
"--ignore-submodules=all suppresses submodule summary" '
1410 cat > expect << EOF &&
1412 Your branch and '\''upstream'\'' have diverged,
1413 and have 2 and 2 different commits each, respectively.
1414 (use "git pull" if you want to integrate the remote branch with yours)
1416 Changes not staged for commit:
1417 (use "git add <file>..." to update what will be committed)
1418 (use "git restore <file>..." to discard changes in working directory)
1419 modified: dir1/modified
1422 (use "git add <file>..." to include in what will be committed)
1429 no changes added to commit (use "git add" and/or "git commit -a")
1431 git status --ignore-submodules=all > output &&
1432 test_cmp expect output
1435 test_expect_success
'.gitmodules ignore=all suppresses unstaged submodule summary' '
1436 cat > expect << EOF &&
1438 Your branch and '\''upstream'\'' have diverged,
1439 and have 2 and 2 different commits each, respectively.
1440 (use "git pull" if you want to integrate the remote branch with yours)
1442 Changes to be committed:
1443 (use "git restore --staged <file>..." to unstage)
1446 Changes not staged for commit:
1447 (use "git add <file>..." to update what will be committed)
1448 (use "git restore <file>..." to discard changes in working directory)
1449 modified: dir1/modified
1452 (use "git add <file>..." to include in what will be committed)
1460 git config --add -f .gitmodules submodule.subname.ignore all &&
1461 git config --add -f .gitmodules submodule.subname.path sm &&
1462 git status > output &&
1463 test_cmp expect output &&
1464 git config -f .gitmodules --remove-section submodule.subname
1467 test_expect_success
'.git/config ignore=all suppresses unstaged submodule summary' '
1468 git config --add -f .gitmodules submodule.subname.ignore none &&
1469 git config --add -f .gitmodules submodule.subname.path sm &&
1470 git config --add submodule.subname.ignore all &&
1471 git config --add submodule.subname.path sm &&
1472 git status > output &&
1473 test_cmp expect output &&
1474 git config --remove-section submodule.subname &&
1475 git config -f .gitmodules --remove-section submodule.subname
1478 test_expect_success
'setup of test environment' '
1479 git config status.showUntrackedFiles no &&
1480 git status -s >expected_short &&
1481 git status --no-short >expected_noshort
1484 test_expect_success
'"status.short=true" same as "-s"' '
1485 git -c status.short=true status >actual &&
1486 test_cmp expected_short actual
1489 test_expect_success
'"status.short=true" weaker than "--no-short"' '
1490 git -c status.short=true status --no-short >actual &&
1491 test_cmp expected_noshort actual
1494 test_expect_success
'"status.short=false" same as "--no-short"' '
1495 git -c status.short=false status >actual &&
1496 test_cmp expected_noshort actual
1499 test_expect_success
'"status.short=false" weaker than "-s"' '
1500 git -c status.short=false status -s >actual &&
1501 test_cmp expected_short actual
1504 test_expect_success
'"status.branch=true" same as "-b"' '
1505 git status -sb >expected_branch &&
1506 git -c status.branch=true status -s >actual &&
1507 test_cmp expected_branch actual
1510 test_expect_success
'"status.branch=true" different from "--no-branch"' '
1511 git status -s --no-branch >expected_nobranch &&
1512 git -c status.branch=true status -s >actual &&
1513 ! test_cmp expected_nobranch actual
1516 test_expect_success
'"status.branch=true" weaker than "--no-branch"' '
1517 git -c status.branch=true status -s --no-branch >actual &&
1518 test_cmp expected_nobranch actual
1521 test_expect_success
'"status.branch=true" weaker than "--porcelain"' '
1522 git -c status.branch=true status --porcelain >actual &&
1523 test_cmp expected_nobranch actual
1526 test_expect_success
'"status.branch=false" same as "--no-branch"' '
1527 git -c status.branch=false status -s >actual &&
1528 test_cmp expected_nobranch actual
1531 test_expect_success
'"status.branch=false" weaker than "-b"' '
1532 git -c status.branch=false status -sb >actual &&
1533 test_cmp expected_branch actual
1536 test_expect_success
'Restore default test environment' '
1537 git config --unset status.showUntrackedFiles
1540 test_expect_success
'git commit will commit a staged but ignored submodule' '
1541 git config --add -f .gitmodules submodule.subname.ignore all &&
1542 git config --add -f .gitmodules submodule.subname.path sm &&
1543 git config --add submodule.subname.ignore all &&
1544 git status -s --ignore-submodules=dirty >output &&
1545 test_i18ngrep "^M. sm" output &&
1546 GIT_EDITOR="echo hello >>\"\$1\"" &&
1547 export GIT_EDITOR &&
1549 git status -s --ignore-submodules=dirty >output &&
1550 test_i18ngrep ! "^M. sm" output
1553 test_expect_success
'git commit --dry-run will show a staged but ignored submodule' '
1556 cat >expect << EOF &&
1558 Your branch and '\''upstream'\'' have diverged,
1559 and have 2 and 2 different commits each, respectively.
1561 Changes to be committed:
1562 (use "git restore --staged <file>..." to unstage)
1565 Changes not staged for commit:
1566 (use "git add <file>..." to update what will be committed)
1567 (use "git restore <file>..." to discard changes in working directory)
1568 modified: dir1/modified
1570 Untracked files not listed (use -u option to show untracked files)
1572 git commit -uno --dry-run >output &&
1573 test_cmp expect output &&
1574 git status -s --ignore-submodules=dirty >output &&
1575 test_i18ngrep "^M. sm" output
1578 test_expect_success
'git commit -m will commit a staged but ignored submodule' '
1579 git commit -uno -m message &&
1580 git status -s --ignore-submodules=dirty >output &&
1581 test_i18ngrep ! "^M. sm" output &&
1582 git config --remove-section submodule.subname &&
1583 git config -f .gitmodules --remove-section submodule.subname
1586 test_expect_success
'show stash info with "--show-stash"' '
1592 git status >expected_default &&
1593 git status --show-stash >expected_with_stash &&
1594 test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
1597 test_expect_success
'no stash info with "--show-stash --no-show-stash"' '
1598 git status --show-stash --no-show-stash >expected_without_stash &&
1599 test_cmp expected_default expected_without_stash
1602 test_expect_success
'"status.showStash=false" weaker than "--show-stash"' '
1603 git -c status.showStash=false status --show-stash >actual &&
1604 test_cmp expected_with_stash actual
1607 test_expect_success
'"status.showStash=true" weaker than "--no-show-stash"' '
1608 git -c status.showStash=true status --no-show-stash >actual &&
1609 test_cmp expected_without_stash actual
1612 test_expect_success
'no additional info if no stash entries' '
1614 git -c status.showStash=true status >actual &&
1615 test_cmp expected_without_stash actual
1618 test_expect_success
'"No commits yet" should be noted in status output' '
1619 git checkout --orphan empty-branch-1 &&
1620 git status >output &&
1621 test_i18ngrep "No commits yet" output
1624 test_expect_success
'"No commits yet" should not be noted in status output' '
1625 git checkout --orphan empty-branch-2 &&
1626 test_commit test-commit-1 &&
1627 git status >output &&
1628 test_i18ngrep ! "No commits yet" output
1631 test_expect_success
'"Initial commit" should be noted in commit template' '
1632 git checkout --orphan empty-branch-3 &&
1633 touch to_be_committed_1 &&
1634 git add to_be_committed_1 &&
1635 git commit --dry-run >output &&
1636 test_i18ngrep "Initial commit" output
1639 test_expect_success
'"Initial commit" should not be noted in commit template' '
1640 git checkout --orphan empty-branch-4 &&
1641 test_commit test-commit-2 &&
1642 touch to_be_committed_2 &&
1643 git add to_be_committed_2 &&
1644 git commit --dry-run >output &&
1645 test_i18ngrep ! "Initial commit" output
1648 test_expect_success
'--no-optional-locks prevents index update' '
1649 test_set_magic_mtime .git/index &&
1650 git --no-optional-locks status &&
1651 test_is_magic_mtime .git/index &&
1653 ! test_is_magic_mtime .git/index
1656 test_expect_success
'racy timestamps will be fixed for clean worktree' '
1657 echo content >racy-dirty &&
1658 echo content >racy-racy &&
1660 git commit -m "racy test files" &&
1661 # let status rewrite the index, if necessary; after that we expect
1662 # no more index writes unless caused by racy timestamps; note that
1663 # timestamps may already be racy now (depending on previous tests)
1665 test_set_magic_mtime .git/index &&
1667 ! test_is_magic_mtime .git/index
1670 test_expect_success
'racy timestamps will be fixed for dirty worktree' '
1671 echo content2 >racy-dirty &&
1673 test_set_magic_mtime .git/index &&
1675 ! test_is_magic_mtime .git/index
1678 test_expect_success
'setup slow status advice' '
1679 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main git init slowstatus &&
1682 cat >.gitignore <<-\EOF &&
1687 git add .gitignore &&
1688 git commit -m "Add .gitignore" &&
1689 git config advice.statusuoption true
1693 test_expect_success
'slow status advice when core.untrackedCache and fsmonitor are unset' '
1696 git config core.untrackedCache false &&
1697 git config core.fsmonitor false &&
1698 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1699 cat >expected <<-\EOF &&
1702 It took 3.25 seconds to enumerate untracked files.
1703 See '\''git help status'\'' for information on how to improve this.
1705 nothing to commit, working tree clean
1707 test_cmp expected actual
1711 test_expect_success
'slow status advice when core.untrackedCache true, but not fsmonitor' '
1714 git config core.untrackedCache true &&
1715 git config core.fsmonitor false &&
1716 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1717 cat >expected <<-\EOF &&
1720 It took 3.25 seconds to enumerate untracked files.
1721 See '\''git help status'\'' for information on how to improve this.
1723 nothing to commit, working tree clean
1725 test_cmp expected actual
1729 test_expect_success
'slow status advice when core.untrackedCache true, and fsmonitor' '
1732 git config core.untrackedCache true &&
1733 git config core.fsmonitor true &&
1734 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1735 cat >expected <<-\EOF &&
1738 It took 3.25 seconds to enumerate untracked files,
1739 but the results were cached, and subsequent runs may be faster.
1740 See '\''git help status'\'' for information on how to improve this.
1742 nothing to commit, working tree clean
1744 test_cmp expected actual
1748 test_expect_success EXPENSIVE
'status does not re-read unchanged 4 or 8 GiB file' '
1752 # Files are 2 GiB, 4 GiB, and 8 GiB sparse files.
1753 test-tool truncate file-a 0x080000000 &&
1754 test-tool truncate file-b 0x100000000 &&
1755 test-tool truncate file-c 0x200000000 &&
1756 # This will be slow.
1757 git add file-a file-b file-c &&
1758 git commit -m "add large files" &&
1759 git diff-index HEAD file-a file-b file-c >actual &&
1760 test_must_be_empty actual