grep: remove redundant REG_NEWLINE when compiling fixed regex
[alt-git.git] / t / t7508-status.sh
blobf7fe22a195e437d5a2aa9c28ea5991b53ae2c7e7
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git status'
8 . ./test-lib.sh
10 test_expect_success 'status -h in broken repository' '
11 git config --global advice.statusuoption false &&
12 mkdir broken &&
13 test_when_finished "rm -fr broken" &&
15 cd broken &&
16 git init &&
17 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
18 test_expect_code 129 git status -h >usage 2>&1
19 ) &&
20 test_i18ngrep "[Uu]sage" broken/usage
23 test_expect_success 'commit -h in broken repository' '
24 mkdir broken &&
25 test_when_finished "rm -fr broken" &&
27 cd broken &&
28 git init &&
29 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
30 test_expect_code 129 git commit -h >usage 2>&1
31 ) &&
32 test_i18ngrep "[Uu]sage" broken/usage
35 test_expect_success 'create upstream branch' '
36 git checkout -b upstream &&
37 test_commit upstream1 &&
38 test_commit upstream2 &&
39 # leave the first commit on master as root because several
40 # tests depend on this case; for our upstream we only
41 # care about commit counts anyway, so a totally divergent
42 # history is OK
43 git checkout --orphan master
46 test_expect_success 'setup' '
47 : >tracked &&
48 : >modified &&
49 mkdir dir1 &&
50 : >dir1/tracked &&
51 : >dir1/modified &&
52 mkdir dir2 &&
53 : >dir1/tracked &&
54 : >dir1/modified &&
55 git add . &&
57 git status >output &&
59 test_tick &&
60 git commit -m initial &&
61 : >untracked &&
62 : >dir1/untracked &&
63 : >dir2/untracked &&
64 echo 1 >dir1/modified &&
65 echo 2 >dir2/modified &&
66 echo 3 >dir2/added &&
67 git add dir2/added &&
69 git branch --set-upstream-to=upstream
72 test_expect_success 'status (1)' '
73 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
76 strip_comments () {
77 tab=' '
78 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
79 rm "$1" && mv "$1".tmp "$1"
82 cat >.gitignore <<\EOF
83 .gitignore
84 expect*
85 output*
86 EOF
88 test_expect_success 'status --column' '
89 cat >expect <<\EOF &&
90 # On branch master
91 # Your branch and '\''upstream'\'' have diverged,
92 # and have 1 and 2 different commits each, respectively.
93 # (use "git pull" to merge the remote branch into yours)
95 # Changes to be committed:
96 # (use "git reset HEAD <file>..." to unstage)
98 # new file: dir2/added
100 # Changes not staged for commit:
101 # (use "git add <file>..." to update what will be committed)
102 # (use "git checkout -- <file>..." to discard changes in working directory)
104 # modified: dir1/modified
106 # Untracked files:
107 # (use "git add <file>..." to include in what will be committed)
109 # dir1/untracked dir2/untracked
110 # dir2/modified untracked
113 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
114 test_i18ncmp expect output
117 test_expect_success 'status --column status.displayCommentPrefix=false' '
118 strip_comments expect &&
119 COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
120 test_i18ncmp expect output
123 cat >expect <<\EOF
124 # On branch master
125 # Your branch and 'upstream' have diverged,
126 # and have 1 and 2 different commits each, respectively.
127 # (use "git pull" to merge the remote branch into yours)
129 # Changes to be committed:
130 # (use "git reset HEAD <file>..." to unstage)
132 # new file: dir2/added
134 # Changes not staged for commit:
135 # (use "git add <file>..." to update what will be committed)
136 # (use "git checkout -- <file>..." to discard changes in working directory)
138 # modified: dir1/modified
140 # Untracked files:
141 # (use "git add <file>..." to include in what will be committed)
143 # dir1/untracked
144 # dir2/modified
145 # dir2/untracked
146 # untracked
150 test_expect_success 'status with status.displayCommentPrefix=true' '
151 git -c status.displayCommentPrefix=true status >output &&
152 test_i18ncmp expect output
155 test_expect_success 'status with status.displayCommentPrefix=false' '
156 strip_comments expect &&
157 git -c status.displayCommentPrefix=false status >output &&
158 test_i18ncmp expect output
161 test_expect_success 'status -v' '
162 (cat expect && git diff --cached) >expect-with-v &&
163 git status -v >output &&
164 test_i18ncmp expect-with-v output
167 test_expect_success 'status -v -v' '
168 (cat expect &&
169 echo "Changes to be committed:" &&
170 git -c diff.mnemonicprefix=true diff --cached &&
171 echo "--------------------------------------------------" &&
172 echo "Changes not staged for commit:" &&
173 git -c diff.mnemonicprefix=true diff) >expect-with-v &&
174 git status -v -v >output &&
175 test_i18ncmp expect-with-v output
178 test_expect_success 'setup fake editor' '
179 cat >.git/editor <<-\EOF &&
180 #! /bin/sh
181 cp "$1" output
183 chmod 755 .git/editor
186 commit_template_commented () {
188 EDITOR=.git/editor &&
189 export EDITOR &&
190 # Fails due to empty message
191 test_must_fail git commit
192 ) &&
193 ! grep '^[^#]' output
196 test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
197 commit_template_commented
200 cat >expect <<\EOF
201 On branch master
202 Your branch and 'upstream' have diverged,
203 and have 1 and 2 different commits each, respectively.
205 Changes to be committed:
206 new file: dir2/added
208 Changes not staged for commit:
209 modified: dir1/modified
211 Untracked files:
212 dir1/untracked
213 dir2/modified
214 dir2/untracked
215 untracked
219 test_expect_success 'status (advice.statusHints false)' '
220 test_config advice.statusHints false &&
221 git status >output &&
222 test_i18ncmp expect output
226 cat >expect <<\EOF
227 M dir1/modified
228 A dir2/added
229 ?? dir1/untracked
230 ?? dir2/modified
231 ?? dir2/untracked
232 ?? untracked
235 test_expect_success 'status -s' '
237 git status -s >output &&
238 test_cmp expect output
242 test_expect_success 'status with gitignore' '
244 echo ".gitignore" &&
245 echo "expect*" &&
246 echo "output" &&
247 echo "untracked"
248 } >.gitignore &&
250 cat >expect <<-\EOF &&
251 M dir1/modified
252 A dir2/added
253 ?? dir2/modified
255 git status -s >output &&
256 test_cmp expect output &&
258 cat >expect <<-\EOF &&
259 M dir1/modified
260 A dir2/added
261 ?? dir2/modified
262 !! .gitignore
263 !! dir1/untracked
264 !! dir2/untracked
265 !! expect
266 !! expect-with-v
267 !! output
268 !! untracked
270 git status -s --ignored >output &&
271 test_cmp expect output &&
273 cat >expect <<\EOF &&
274 On branch master
275 Your branch and '\''upstream'\'' have diverged,
276 and have 1 and 2 different commits each, respectively.
277 (use "git pull" to merge the remote branch into yours)
279 Changes to be committed:
280 (use "git reset HEAD <file>..." to unstage)
282 new file: dir2/added
284 Changes not staged for commit:
285 (use "git add <file>..." to update what will be committed)
286 (use "git checkout -- <file>..." to discard changes in working directory)
288 modified: dir1/modified
290 Untracked files:
291 (use "git add <file>..." to include in what will be committed)
293 dir2/modified
295 Ignored files:
296 (use "git add -f <file>..." to include in what will be committed)
298 .gitignore
299 dir1/untracked
300 dir2/untracked
301 expect
302 expect-with-v
303 output
304 untracked
307 git status --ignored >output &&
308 test_i18ncmp expect output
311 test_expect_success 'status with gitignore (nothing untracked)' '
313 echo ".gitignore" &&
314 echo "expect*" &&
315 echo "dir2/modified" &&
316 echo "output" &&
317 echo "untracked"
318 } >.gitignore &&
320 cat >expect <<-\EOF &&
321 M dir1/modified
322 A dir2/added
324 git status -s >output &&
325 test_cmp expect output &&
327 cat >expect <<-\EOF &&
328 M dir1/modified
329 A dir2/added
330 !! .gitignore
331 !! dir1/untracked
332 !! dir2/modified
333 !! dir2/untracked
334 !! expect
335 !! expect-with-v
336 !! output
337 !! untracked
339 git status -s --ignored >output &&
340 test_cmp expect output &&
342 cat >expect <<\EOF &&
343 On branch master
344 Your branch and '\''upstream'\'' have diverged,
345 and have 1 and 2 different commits each, respectively.
346 (use "git pull" to merge the remote branch into yours)
348 Changes to be committed:
349 (use "git reset HEAD <file>..." to unstage)
351 new file: dir2/added
353 Changes not staged for commit:
354 (use "git add <file>..." to update what will be committed)
355 (use "git checkout -- <file>..." to discard changes in working directory)
357 modified: dir1/modified
359 Ignored files:
360 (use "git add -f <file>..." to include in what will be committed)
362 .gitignore
363 dir1/untracked
364 dir2/modified
365 dir2/untracked
366 expect
367 expect-with-v
368 output
369 untracked
372 git status --ignored >output &&
373 test_i18ncmp expect output
376 cat >.gitignore <<\EOF
377 .gitignore
378 expect*
379 output*
382 cat >expect <<\EOF
383 ## master...upstream [ahead 1, behind 2]
384 M dir1/modified
385 A dir2/added
386 ?? dir1/untracked
387 ?? dir2/modified
388 ?? dir2/untracked
389 ?? untracked
392 test_expect_success 'status -s -b' '
394 git status -s -b >output &&
395 test_i18ncmp expect output
399 test_expect_success 'status -s -z -b' '
400 tr "\\n" Q <expect >expect.q &&
401 mv expect.q expect &&
402 git status -s -z -b >output &&
403 nul_to_q <output >output.q &&
404 mv output.q output &&
405 test_i18ncmp expect output
408 test_expect_success 'setup dir3' '
409 mkdir dir3 &&
410 : >dir3/untracked1 &&
411 : >dir3/untracked2
414 test_expect_success 'status -uno' '
415 cat >expect <<EOF &&
416 On branch master
417 Your branch and '\''upstream'\'' have diverged,
418 and have 1 and 2 different commits each, respectively.
419 (use "git pull" to merge the remote branch into yours)
421 Changes to be committed:
422 (use "git reset HEAD <file>..." to unstage)
424 new file: dir2/added
426 Changes not staged for commit:
427 (use "git add <file>..." to update what will be committed)
428 (use "git checkout -- <file>..." to discard changes in working directory)
430 modified: dir1/modified
432 Untracked files not listed (use -u option to show untracked files)
434 git status -uno >output &&
435 test_i18ncmp expect output
438 test_expect_success 'status (status.showUntrackedFiles no)' '
439 test_config status.showuntrackedfiles no &&
440 git status >output &&
441 test_i18ncmp expect output
444 test_expect_success 'status -uno (advice.statusHints false)' '
445 cat >expect <<EOF &&
446 On branch master
447 Your branch and '\''upstream'\'' have diverged,
448 and have 1 and 2 different commits each, respectively.
450 Changes to be committed:
451 new file: dir2/added
453 Changes not staged for commit:
454 modified: dir1/modified
456 Untracked files not listed
458 test_config advice.statusHints false &&
459 git status -uno >output &&
460 test_i18ncmp expect output
463 cat >expect << EOF
464 M dir1/modified
465 A dir2/added
467 test_expect_success 'status -s -uno' '
468 git status -s -uno >output &&
469 test_cmp expect output
472 test_expect_success 'status -s (status.showUntrackedFiles no)' '
473 git config status.showuntrackedfiles no &&
474 git status -s >output &&
475 test_cmp expect output
478 test_expect_success 'status -unormal' '
479 cat >expect <<EOF &&
480 On branch master
481 Your branch and '\''upstream'\'' have diverged,
482 and have 1 and 2 different commits each, respectively.
483 (use "git pull" to merge the remote branch into yours)
485 Changes to be committed:
486 (use "git reset HEAD <file>..." to unstage)
488 new file: dir2/added
490 Changes not staged for commit:
491 (use "git add <file>..." to update what will be committed)
492 (use "git checkout -- <file>..." to discard changes in working directory)
494 modified: dir1/modified
496 Untracked files:
497 (use "git add <file>..." to include in what will be committed)
499 dir1/untracked
500 dir2/modified
501 dir2/untracked
502 dir3/
503 untracked
506 git status -unormal >output &&
507 test_i18ncmp expect output
510 test_expect_success 'status (status.showUntrackedFiles normal)' '
511 test_config status.showuntrackedfiles normal &&
512 git status >output &&
513 test_i18ncmp expect output
516 cat >expect <<EOF
517 M dir1/modified
518 A dir2/added
519 ?? dir1/untracked
520 ?? dir2/modified
521 ?? dir2/untracked
522 ?? dir3/
523 ?? untracked
525 test_expect_success 'status -s -unormal' '
526 git status -s -unormal >output &&
527 test_cmp expect output
530 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
531 git config status.showuntrackedfiles normal &&
532 git status -s >output &&
533 test_cmp expect output
536 test_expect_success 'status -uall' '
537 cat >expect <<EOF &&
538 On branch master
539 Your branch and '\''upstream'\'' have diverged,
540 and have 1 and 2 different commits each, respectively.
541 (use "git pull" to merge the remote branch into yours)
543 Changes to be committed:
544 (use "git reset HEAD <file>..." to unstage)
546 new file: dir2/added
548 Changes not staged for commit:
549 (use "git add <file>..." to update what will be committed)
550 (use "git checkout -- <file>..." to discard changes in working directory)
552 modified: dir1/modified
554 Untracked files:
555 (use "git add <file>..." to include in what will be committed)
557 dir1/untracked
558 dir2/modified
559 dir2/untracked
560 dir3/untracked1
561 dir3/untracked2
562 untracked
565 git status -uall >output &&
566 test_i18ncmp expect output
569 test_expect_success 'status (status.showUntrackedFiles all)' '
570 test_config status.showuntrackedfiles all &&
571 git status >output &&
572 test_i18ncmp expect output
575 test_expect_success 'teardown dir3' '
576 rm -rf dir3
579 cat >expect <<EOF
580 M dir1/modified
581 A dir2/added
582 ?? dir1/untracked
583 ?? dir2/modified
584 ?? dir2/untracked
585 ?? untracked
587 test_expect_success 'status -s -uall' '
588 test_unconfig status.showuntrackedfiles &&
589 git status -s -uall >output &&
590 test_cmp expect output
592 test_expect_success 'status -s (status.showUntrackedFiles all)' '
593 test_config status.showuntrackedfiles all &&
594 git status -s >output &&
595 rm -rf dir3 &&
596 test_cmp expect output
599 test_expect_success 'status with relative paths' '
600 cat >expect <<\EOF &&
601 On branch master
602 Your branch and '\''upstream'\'' have diverged,
603 and have 1 and 2 different commits each, respectively.
604 (use "git pull" to merge the remote branch into yours)
606 Changes to be committed:
607 (use "git reset HEAD <file>..." to unstage)
609 new file: ../dir2/added
611 Changes not staged for commit:
612 (use "git add <file>..." to update what will be committed)
613 (use "git checkout -- <file>..." to discard changes in working directory)
615 modified: modified
617 Untracked files:
618 (use "git add <file>..." to include in what will be committed)
620 untracked
621 ../dir2/modified
622 ../dir2/untracked
623 ../untracked
626 (cd dir1 && git status) >output &&
627 test_i18ncmp expect output
630 cat >expect <<\EOF
631 M modified
632 A ../dir2/added
633 ?? untracked
634 ?? ../dir2/modified
635 ?? ../dir2/untracked
636 ?? ../untracked
638 test_expect_success 'status -s with relative paths' '
640 (cd dir1 && git status -s) >output &&
641 test_cmp expect output
645 cat >expect <<\EOF
646 M dir1/modified
647 A dir2/added
648 ?? dir1/untracked
649 ?? dir2/modified
650 ?? dir2/untracked
651 ?? untracked
654 test_expect_success 'status --porcelain ignores relative paths setting' '
656 (cd dir1 && git status --porcelain) >output &&
657 test_cmp expect output
661 test_expect_success 'setup unique colors' '
663 git config status.color.untracked blue &&
664 git config status.color.branch green &&
665 git config status.color.localBranch yellow &&
666 git config status.color.remoteBranch cyan
670 test_expect_success 'status with color.ui' '
671 cat >expect <<\EOF &&
672 On branch <GREEN>master<RESET>
673 Your branch and '\''upstream'\'' have diverged,
674 and have 1 and 2 different commits each, respectively.
675 (use "git pull" to merge the remote branch into yours)
677 Changes to be committed:
678 (use "git reset HEAD <file>..." to unstage)
680 <GREEN>new file: dir2/added<RESET>
682 Changes not staged for commit:
683 (use "git add <file>..." to update what will be committed)
684 (use "git checkout -- <file>..." to discard changes in working directory)
686 <RED>modified: dir1/modified<RESET>
688 Untracked files:
689 (use "git add <file>..." to include in what will be committed)
691 <BLUE>dir1/untracked<RESET>
692 <BLUE>dir2/modified<RESET>
693 <BLUE>dir2/untracked<RESET>
694 <BLUE>untracked<RESET>
697 test_config color.ui always &&
698 git status | test_decode_color >output &&
699 test_i18ncmp expect output
702 test_expect_success 'status with color.status' '
703 test_config color.status always &&
704 git status | test_decode_color >output &&
705 test_i18ncmp expect output
708 cat >expect <<\EOF
709 <RED>M<RESET> dir1/modified
710 <GREEN>A<RESET> dir2/added
711 <BLUE>??<RESET> dir1/untracked
712 <BLUE>??<RESET> dir2/modified
713 <BLUE>??<RESET> dir2/untracked
714 <BLUE>??<RESET> untracked
717 test_expect_success 'status -s with color.ui' '
719 git config color.ui always &&
720 git status -s | test_decode_color >output &&
721 test_cmp expect output
725 test_expect_success 'status -s with color.status' '
727 git config --unset color.ui &&
728 git config color.status always &&
729 git status -s | test_decode_color >output &&
730 test_cmp expect output
734 cat >expect <<\EOF
735 ## <YELLOW>master<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
736 <RED>M<RESET> dir1/modified
737 <GREEN>A<RESET> dir2/added
738 <BLUE>??<RESET> dir1/untracked
739 <BLUE>??<RESET> dir2/modified
740 <BLUE>??<RESET> dir2/untracked
741 <BLUE>??<RESET> untracked
744 test_expect_success 'status -s -b with color.status' '
746 git status -s -b | test_decode_color >output &&
747 test_i18ncmp expect output
751 cat >expect <<\EOF
752 M dir1/modified
753 A dir2/added
754 ?? dir1/untracked
755 ?? dir2/modified
756 ?? dir2/untracked
757 ?? untracked
760 test_expect_success 'status --porcelain ignores color.ui' '
762 git config --unset color.status &&
763 git config color.ui always &&
764 git status --porcelain | test_decode_color >output &&
765 test_cmp expect output
769 test_expect_success 'status --porcelain ignores color.status' '
771 git config --unset color.ui &&
772 git config color.status always &&
773 git status --porcelain | test_decode_color >output &&
774 test_cmp expect output
778 # recover unconditionally from color tests
779 git config --unset color.status
780 git config --unset color.ui
782 test_expect_success 'status --porcelain respects -b' '
784 git status --porcelain -b >output &&
786 echo "## master...upstream [ahead 1, behind 2]" &&
787 cat expect
788 } >tmp &&
789 mv tmp expect &&
790 test_cmp expect output
796 test_expect_success 'status without relative paths' '
797 cat >expect <<\EOF &&
798 On branch master
799 Your branch and '\''upstream'\'' have diverged,
800 and have 1 and 2 different commits each, respectively.
801 (use "git pull" to merge the remote branch into yours)
803 Changes to be committed:
804 (use "git reset HEAD <file>..." to unstage)
806 new file: dir2/added
808 Changes not staged for commit:
809 (use "git add <file>..." to update what will be committed)
810 (use "git checkout -- <file>..." to discard changes in working directory)
812 modified: dir1/modified
814 Untracked files:
815 (use "git add <file>..." to include in what will be committed)
817 dir1/untracked
818 dir2/modified
819 dir2/untracked
820 untracked
823 test_config status.relativePaths false &&
824 (cd dir1 && git status) >output &&
825 test_i18ncmp expect output
829 cat >expect <<\EOF
830 M dir1/modified
831 A dir2/added
832 ?? dir1/untracked
833 ?? dir2/modified
834 ?? dir2/untracked
835 ?? untracked
838 test_expect_success 'status -s without relative paths' '
840 test_config status.relativePaths false &&
841 (cd dir1 && git status -s) >output &&
842 test_cmp expect output
846 test_expect_success 'dry-run of partial commit excluding new file in index' '
847 cat >expect <<EOF &&
848 On branch master
849 Your branch and '\''upstream'\'' have diverged,
850 and have 1 and 2 different commits each, respectively.
851 (use "git pull" to merge the remote branch into yours)
853 Changes to be committed:
854 (use "git reset HEAD <file>..." to unstage)
856 modified: dir1/modified
858 Untracked files:
859 (use "git add <file>..." to include in what will be committed)
861 dir1/untracked
862 dir2/
863 untracked
866 git commit --dry-run dir1/modified >output &&
867 test_i18ncmp expect output
870 cat >expect <<EOF
871 :100644 100644 $EMPTY_BLOB 0000000000000000000000000000000000000000 M dir1/modified
873 test_expect_success 'status refreshes the index' '
874 touch dir2/added &&
875 git status &&
876 git diff-files >output &&
877 test_cmp expect output
880 test_expect_success 'setup status submodule summary' '
881 test_create_repo sm && (
882 cd sm &&
883 >foo &&
884 git add foo &&
885 git commit -m "Add foo"
886 ) &&
887 git add sm
890 test_expect_success 'status submodule summary is disabled by default' '
891 cat >expect <<EOF &&
892 On branch master
893 Your branch and '\''upstream'\'' have diverged,
894 and have 1 and 2 different commits each, respectively.
895 (use "git pull" to merge the remote branch into yours)
897 Changes to be committed:
898 (use "git reset HEAD <file>..." to unstage)
900 new file: dir2/added
901 new file: sm
903 Changes not staged for commit:
904 (use "git add <file>..." to update what will be committed)
905 (use "git checkout -- <file>..." to discard changes in working directory)
907 modified: dir1/modified
909 Untracked files:
910 (use "git add <file>..." to include in what will be committed)
912 dir1/untracked
913 dir2/modified
914 dir2/untracked
915 untracked
918 git status >output &&
919 test_i18ncmp expect output
922 # we expect the same as the previous test
923 test_expect_success 'status --untracked-files=all does not show submodule' '
924 git status --untracked-files=all >output &&
925 test_i18ncmp expect output
928 cat >expect <<EOF
929 M dir1/modified
930 A dir2/added
931 A sm
932 ?? dir1/untracked
933 ?? dir2/modified
934 ?? dir2/untracked
935 ?? untracked
937 test_expect_success 'status -s submodule summary is disabled by default' '
938 git status -s >output &&
939 test_cmp expect output
942 # we expect the same as the previous test
943 test_expect_success 'status -s --untracked-files=all does not show submodule' '
944 git status -s --untracked-files=all >output &&
945 test_cmp expect output
948 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
950 test_expect_success 'status submodule summary' '
951 cat >expect <<EOF &&
952 On branch master
953 Your branch and '\''upstream'\'' have diverged,
954 and have 1 and 2 different commits each, respectively.
955 (use "git pull" to merge the remote branch into yours)
957 Changes to be committed:
958 (use "git reset HEAD <file>..." to unstage)
960 new file: dir2/added
961 new file: sm
963 Changes not staged for commit:
964 (use "git add <file>..." to update what will be committed)
965 (use "git checkout -- <file>..." to discard changes in working directory)
967 modified: dir1/modified
969 Submodule changes to be committed:
971 * sm 0000000...$head (1):
972 > Add foo
974 Untracked files:
975 (use "git add <file>..." to include in what will be committed)
977 dir1/untracked
978 dir2/modified
979 dir2/untracked
980 untracked
983 git config status.submodulesummary 10 &&
984 git status >output &&
985 test_i18ncmp expect output
988 test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
989 strip_comments expect &&
990 git -c status.displayCommentPrefix=false status >output &&
991 test_i18ncmp expect output
994 test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
995 commit_template_commented
998 cat >expect <<EOF
999 M dir1/modified
1000 A dir2/added
1001 A sm
1002 ?? dir1/untracked
1003 ?? dir2/modified
1004 ?? dir2/untracked
1005 ?? untracked
1007 test_expect_success 'status -s submodule summary' '
1008 git status -s >output &&
1009 test_cmp expect output
1012 test_expect_success 'status submodule summary (clean submodule): commit' '
1013 cat >expect <<EOF &&
1014 On branch master
1015 Your branch and '\''upstream'\'' have diverged,
1016 and have 2 and 2 different commits each, respectively.
1017 (use "git pull" to merge the remote branch into yours)
1019 Changes not staged for commit:
1020 (use "git add <file>..." to update what will be committed)
1021 (use "git checkout -- <file>..." to discard changes in working directory)
1023 modified: dir1/modified
1025 Untracked files:
1026 (use "git add <file>..." to include in what will be committed)
1028 dir1/untracked
1029 dir2/modified
1030 dir2/untracked
1031 untracked
1033 no changes added to commit (use "git add" and/or "git commit -a")
1035 git commit -m "commit submodule" &&
1036 git config status.submodulesummary 10 &&
1037 test_must_fail git commit --dry-run >output &&
1038 test_i18ncmp expect output &&
1039 git status >output &&
1040 test_i18ncmp expect output
1043 cat >expect <<EOF
1044 M dir1/modified
1045 ?? dir1/untracked
1046 ?? dir2/modified
1047 ?? dir2/untracked
1048 ?? untracked
1050 test_expect_success 'status -s submodule summary (clean submodule)' '
1051 git status -s >output &&
1052 test_cmp expect output
1055 test_expect_success 'status -z implies porcelain' '
1056 git status --porcelain |
1057 perl -pe "s/\012/\000/g" >expect &&
1058 git status -z >output &&
1059 test_cmp expect output
1062 test_expect_success 'commit --dry-run submodule summary (--amend)' '
1063 cat >expect <<EOF &&
1064 On branch master
1065 Your branch and '\''upstream'\'' have diverged,
1066 and have 2 and 2 different commits each, respectively.
1067 (use "git pull" to merge the remote branch into yours)
1069 Changes to be committed:
1070 (use "git reset HEAD^1 <file>..." to unstage)
1072 new file: dir2/added
1073 new file: sm
1075 Changes not staged for commit:
1076 (use "git add <file>..." to update what will be committed)
1077 (use "git checkout -- <file>..." to discard changes in working directory)
1079 modified: dir1/modified
1081 Submodule changes to be committed:
1083 * sm 0000000...$head (1):
1084 > Add foo
1086 Untracked files:
1087 (use "git add <file>..." to include in what will be committed)
1089 dir1/untracked
1090 dir2/modified
1091 dir2/untracked
1092 untracked
1095 git config status.submodulesummary 10 &&
1096 git commit --dry-run --amend >output &&
1097 test_i18ncmp expect output
1100 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1102 chmod a-w .git &&
1103 # make dir1/tracked stat-dirty
1104 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1105 git status -s >output &&
1106 ! grep dir1/tracked output &&
1107 # make sure "status" succeeded without writing index out
1108 git diff-files | grep dir1/tracked
1110 status=$?
1111 chmod 775 .git
1112 (exit $status)
1115 (cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
1116 new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1117 touch .gitmodules
1119 test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1120 cat > expect << EOF &&
1121 On branch master
1122 Your branch and '\''upstream'\'' have diverged,
1123 and have 2 and 2 different commits each, respectively.
1124 (use "git pull" to merge the remote branch into yours)
1126 Changes to be committed:
1127 (use "git reset HEAD <file>..." to unstage)
1129 modified: sm
1131 Changes not staged for commit:
1132 (use "git add <file>..." to update what will be committed)
1133 (use "git checkout -- <file>..." to discard changes in working directory)
1135 modified: dir1/modified
1137 Submodule changes to be committed:
1139 * sm $head...$new_head (1):
1140 > Add bar
1142 Untracked files:
1143 (use "git add <file>..." to include in what will be committed)
1145 .gitmodules
1146 dir1/untracked
1147 dir2/modified
1148 dir2/untracked
1149 untracked
1152 echo modified sm/untracked &&
1153 git status --ignore-submodules=untracked >output &&
1154 test_i18ncmp expect output
1157 test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
1158 test_config diff.ignoreSubmodules dirty &&
1159 git status >output &&
1160 test_i18ncmp expect output &&
1161 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1162 git config --add -f .gitmodules submodule.subname.path sm &&
1163 git status >output &&
1164 test_i18ncmp expect output &&
1165 git config -f .gitmodules --remove-section submodule.subname
1168 test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
1169 git config --add -f .gitmodules submodule.subname.ignore none &&
1170 git config --add -f .gitmodules submodule.subname.path sm &&
1171 git config --add submodule.subname.ignore untracked &&
1172 git config --add submodule.subname.path sm &&
1173 git status >output &&
1174 test_i18ncmp expect output &&
1175 git config --remove-section submodule.subname &&
1176 git config --remove-section -f .gitmodules submodule.subname
1179 test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1180 git status --ignore-submodules=dirty >output &&
1181 test_i18ncmp expect output
1184 test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
1185 test_config diff.ignoreSubmodules dirty &&
1186 git status >output &&
1187 ! test -s actual &&
1188 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1189 git config --add -f .gitmodules submodule.subname.path sm &&
1190 git status >output &&
1191 test_i18ncmp expect output &&
1192 git config -f .gitmodules --remove-section submodule.subname
1195 test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
1196 git config --add -f .gitmodules submodule.subname.ignore none &&
1197 git config --add -f .gitmodules submodule.subname.path sm &&
1198 git config --add submodule.subname.ignore dirty &&
1199 git config --add submodule.subname.path sm &&
1200 git status >output &&
1201 test_i18ncmp expect output &&
1202 git config --remove-section submodule.subname &&
1203 git config -f .gitmodules --remove-section submodule.subname
1206 test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1207 echo modified >sm/foo &&
1208 git status --ignore-submodules=dirty >output &&
1209 test_i18ncmp expect output
1212 test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
1213 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1214 git config --add -f .gitmodules submodule.subname.path sm &&
1215 git status >output &&
1216 test_i18ncmp expect output &&
1217 git config -f .gitmodules --remove-section submodule.subname
1220 test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
1221 git config --add -f .gitmodules submodule.subname.ignore none &&
1222 git config --add -f .gitmodules submodule.subname.path sm &&
1223 git config --add submodule.subname.ignore dirty &&
1224 git config --add submodule.subname.path sm &&
1225 git status >output &&
1226 test_i18ncmp expect output &&
1227 git config --remove-section submodule.subname &&
1228 git config -f .gitmodules --remove-section submodule.subname
1231 test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1232 cat > expect << EOF &&
1233 On branch master
1234 Your branch and '\''upstream'\'' have diverged,
1235 and have 2 and 2 different commits each, respectively.
1236 (use "git pull" to merge the remote branch into yours)
1238 Changes to be committed:
1239 (use "git reset HEAD <file>..." to unstage)
1241 modified: sm
1243 Changes not staged for commit:
1244 (use "git add <file>..." to update what will be committed)
1245 (use "git checkout -- <file>..." to discard changes in working directory)
1246 (commit or discard the untracked or modified content in submodules)
1248 modified: dir1/modified
1249 modified: sm (modified content)
1251 Submodule changes to be committed:
1253 * sm $head...$new_head (1):
1254 > Add bar
1256 Untracked files:
1257 (use "git add <file>..." to include in what will be committed)
1259 .gitmodules
1260 dir1/untracked
1261 dir2/modified
1262 dir2/untracked
1263 untracked
1266 git status --ignore-submodules=untracked > output &&
1267 test_i18ncmp expect output
1270 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1271 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1272 git config --add -f .gitmodules submodule.subname.path sm &&
1273 git status >output &&
1274 test_i18ncmp expect output &&
1275 git config -f .gitmodules --remove-section submodule.subname
1278 test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
1279 git config --add -f .gitmodules submodule.subname.ignore none &&
1280 git config --add -f .gitmodules submodule.subname.path sm &&
1281 git config --add submodule.subname.ignore untracked &&
1282 git config --add submodule.subname.path sm &&
1283 git status >output &&
1284 test_i18ncmp expect output &&
1285 git config --remove-section submodule.subname &&
1286 git config -f .gitmodules --remove-section submodule.subname
1289 head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1291 test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1292 cat > expect << EOF &&
1293 On branch master
1294 Your branch and '\''upstream'\'' have diverged,
1295 and have 2 and 2 different commits each, respectively.
1296 (use "git pull" to merge the remote branch into yours)
1298 Changes to be committed:
1299 (use "git reset HEAD <file>..." to unstage)
1301 modified: sm
1303 Changes not staged for commit:
1304 (use "git add <file>..." to update what will be committed)
1305 (use "git checkout -- <file>..." to discard changes in working directory)
1307 modified: dir1/modified
1308 modified: sm (new commits)
1310 Submodule changes to be committed:
1312 * sm $head...$new_head (1):
1313 > Add bar
1315 Submodules changed but not updated:
1317 * sm $new_head...$head2 (1):
1318 > 2nd commit
1320 Untracked files:
1321 (use "git add <file>..." to include in what will be committed)
1323 .gitmodules
1324 dir1/untracked
1325 dir2/modified
1326 dir2/untracked
1327 untracked
1330 git status --ignore-submodules=untracked > output &&
1331 test_i18ncmp expect output
1334 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
1335 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1336 git config --add -f .gitmodules submodule.subname.path sm &&
1337 git status >output &&
1338 test_i18ncmp expect output &&
1339 git config -f .gitmodules --remove-section submodule.subname
1342 test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
1343 git config --add -f .gitmodules submodule.subname.ignore none &&
1344 git config --add -f .gitmodules submodule.subname.path sm &&
1345 git config --add submodule.subname.ignore untracked &&
1346 git config --add submodule.subname.path sm &&
1347 git status >output &&
1348 test_i18ncmp expect output &&
1349 git config --remove-section submodule.subname &&
1350 git config -f .gitmodules --remove-section submodule.subname
1353 test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
1354 git status --ignore-submodules=dirty > output &&
1355 test_i18ncmp expect output
1357 test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
1358 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1359 git config --add -f .gitmodules submodule.subname.path sm &&
1360 git status >output &&
1361 test_i18ncmp expect output &&
1362 git config -f .gitmodules --remove-section submodule.subname
1365 test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
1366 git config --add -f .gitmodules submodule.subname.ignore none &&
1367 git config --add -f .gitmodules submodule.subname.path sm &&
1368 git config --add submodule.subname.ignore dirty &&
1369 git config --add submodule.subname.path sm &&
1370 git status >output &&
1371 test_i18ncmp expect output &&
1372 git config --remove-section submodule.subname &&
1373 git config -f .gitmodules --remove-section submodule.subname
1376 cat > expect << EOF
1377 ; On branch master
1378 ; Your branch and 'upstream' have diverged,
1379 ; and have 2 and 2 different commits each, respectively.
1380 ; (use "git pull" to merge the remote branch into yours)
1382 ; Changes to be committed:
1383 ; (use "git reset HEAD <file>..." to unstage)
1385 ; modified: sm
1387 ; Changes not staged for commit:
1388 ; (use "git add <file>..." to update what will be committed)
1389 ; (use "git checkout -- <file>..." to discard changes in working directory)
1391 ; modified: dir1/modified
1392 ; modified: sm (new commits)
1394 ; Submodule changes to be committed:
1396 ; * sm $head...$new_head (1):
1397 ; > Add bar
1399 ; Submodules changed but not updated:
1401 ; * sm $new_head...$head2 (1):
1402 ; > 2nd commit
1404 ; Untracked files:
1405 ; (use "git add <file>..." to include in what will be committed)
1407 ; .gitmodules
1408 ; dir1/untracked
1409 ; dir2/modified
1410 ; dir2/untracked
1411 ; untracked
1415 test_expect_success "status (core.commentchar with submodule summary)" '
1416 test_config core.commentchar ";" &&
1417 git -c status.displayCommentPrefix=true status >output &&
1418 test_i18ncmp expect output
1421 test_expect_success "status (core.commentchar with two chars with submodule summary)" '
1422 test_config core.commentchar ";;" &&
1423 test_must_fail git -c status.displayCommentPrefix=true status
1426 test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1427 cat > expect << EOF &&
1428 On branch master
1429 Your branch and '\''upstream'\'' have diverged,
1430 and have 2 and 2 different commits each, respectively.
1431 (use "git pull" to merge the remote branch into yours)
1433 Changes not staged for commit:
1434 (use "git add <file>..." to update what will be committed)
1435 (use "git checkout -- <file>..." to discard changes in working directory)
1437 modified: dir1/modified
1439 Untracked files:
1440 (use "git add <file>..." to include in what will be committed)
1442 .gitmodules
1443 dir1/untracked
1444 dir2/modified
1445 dir2/untracked
1446 untracked
1448 no changes added to commit (use "git add" and/or "git commit -a")
1450 git status --ignore-submodules=all > output &&
1451 test_i18ncmp expect output
1454 test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1455 cat > expect << EOF &&
1456 On branch master
1457 Your branch and '\''upstream'\'' have diverged,
1458 and have 2 and 2 different commits each, respectively.
1459 (use "git pull" to merge the remote branch into yours)
1461 Changes to be committed:
1462 (use "git reset HEAD <file>..." to unstage)
1464 modified: sm
1466 Changes not staged for commit:
1467 (use "git add <file>..." to update what will be committed)
1468 (use "git checkout -- <file>..." to discard changes in working directory)
1470 modified: dir1/modified
1472 Untracked files:
1473 (use "git add <file>..." to include in what will be committed)
1475 .gitmodules
1476 dir1/untracked
1477 dir2/modified
1478 dir2/untracked
1479 untracked
1482 git config --add -f .gitmodules submodule.subname.ignore all &&
1483 git config --add -f .gitmodules submodule.subname.path sm &&
1484 git status > output &&
1485 test_i18ncmp expect output &&
1486 git config -f .gitmodules --remove-section submodule.subname
1489 test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
1490 git config --add -f .gitmodules submodule.subname.ignore none &&
1491 git config --add -f .gitmodules submodule.subname.path sm &&
1492 git config --add submodule.subname.ignore all &&
1493 git config --add submodule.subname.path sm &&
1494 git status > output &&
1495 test_i18ncmp expect output &&
1496 git config --remove-section submodule.subname &&
1497 git config -f .gitmodules --remove-section submodule.subname
1500 test_expect_success 'setup of test environment' '
1501 git config status.showUntrackedFiles no &&
1502 git status -s >expected_short &&
1503 git status --no-short >expected_noshort
1506 test_expect_success '"status.short=true" same as "-s"' '
1507 git -c status.short=true status >actual &&
1508 test_cmp expected_short actual
1511 test_expect_success '"status.short=true" weaker than "--no-short"' '
1512 git -c status.short=true status --no-short >actual &&
1513 test_cmp expected_noshort actual
1516 test_expect_success '"status.short=false" same as "--no-short"' '
1517 git -c status.short=false status >actual &&
1518 test_cmp expected_noshort actual
1521 test_expect_success '"status.short=false" weaker than "-s"' '
1522 git -c status.short=false status -s >actual &&
1523 test_cmp expected_short actual
1526 test_expect_success '"status.branch=true" same as "-b"' '
1527 git status -sb >expected_branch &&
1528 git -c status.branch=true status -s >actual &&
1529 test_cmp expected_branch actual
1532 test_expect_success '"status.branch=true" different from "--no-branch"' '
1533 git status -s --no-branch >expected_nobranch &&
1534 git -c status.branch=true status -s >actual &&
1535 test_must_fail test_cmp expected_nobranch actual
1538 test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1539 git -c status.branch=true status -s --no-branch >actual &&
1540 test_cmp expected_nobranch actual
1543 test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1544 git -c status.branch=true status --porcelain >actual &&
1545 test_cmp expected_nobranch actual
1548 test_expect_success '"status.branch=false" same as "--no-branch"' '
1549 git -c status.branch=false status -s >actual &&
1550 test_cmp expected_nobranch actual
1553 test_expect_success '"status.branch=false" weaker than "-b"' '
1554 git -c status.branch=false status -sb >actual &&
1555 test_cmp expected_branch actual
1558 test_expect_success 'Restore default test environment' '
1559 git config --unset status.showUntrackedFiles
1562 test_expect_success 'git commit will commit a staged but ignored submodule' '
1563 git config --add -f .gitmodules submodule.subname.ignore all &&
1564 git config --add -f .gitmodules submodule.subname.path sm &&
1565 git config --add submodule.subname.ignore all &&
1566 git status -s --ignore-submodules=dirty >output &&
1567 test_i18ngrep "^M. sm" output &&
1568 GIT_EDITOR="echo hello >>\"\$1\"" &&
1569 export GIT_EDITOR &&
1570 git commit -uno &&
1571 git status -s --ignore-submodules=dirty >output &&
1572 test_i18ngrep ! "^M. sm" output
1575 test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
1576 git reset HEAD^ &&
1577 git add sm &&
1578 cat >expect << EOF &&
1579 On branch master
1580 Your branch and '\''upstream'\'' have diverged,
1581 and have 2 and 2 different commits each, respectively.
1582 (use "git pull" to merge the remote branch into yours)
1584 Changes to be committed:
1585 (use "git reset HEAD <file>..." to unstage)
1587 modified: sm
1589 Changes not staged for commit:
1590 (use "git add <file>..." to update what will be committed)
1591 (use "git checkout -- <file>..." to discard changes in working directory)
1593 modified: dir1/modified
1595 Untracked files not listed (use -u option to show untracked files)
1597 git commit -uno --dry-run >output &&
1598 test_i18ncmp expect output &&
1599 git status -s --ignore-submodules=dirty >output &&
1600 test_i18ngrep "^M. sm" output
1603 test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1604 git commit -uno -m message &&
1605 git status -s --ignore-submodules=dirty >output &&
1606 test_i18ngrep ! "^M. sm" output &&
1607 git config --remove-section submodule.subname &&
1608 git config -f .gitmodules --remove-section submodule.subname
1611 test_expect_success 'show stash info with "--show-stash"' '
1612 git reset --hard &&
1613 git stash clear &&
1614 echo 1 >file &&
1615 git add file &&
1616 git stash &&
1617 git status >expected_default &&
1618 git status --show-stash >expected_with_stash &&
1619 test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
1622 test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
1623 git status --show-stash --no-show-stash >expected_without_stash &&
1624 test_cmp expected_default expected_without_stash
1627 test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
1628 git -c status.showStash=false status --show-stash >actual &&
1629 test_cmp expected_with_stash actual
1632 test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
1633 git -c status.showStash=true status --no-show-stash >actual &&
1634 test_cmp expected_without_stash actual
1637 test_expect_success 'no additionnal info if no stash entries' '
1638 git stash clear &&
1639 git -c status.showStash=true status >actual &&
1640 test_cmp expected_without_stash actual
1643 test_done