e3c9cf9c104e6d1bd1aa01290f988bc2e2258794
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='git status'
7
8. ./test-lib.sh
9
10test_expect_success 'status -h in broken repository' '
11 git config --global advice.statusuoption false &&
12 mkdir broken &&
13 test_when_finished "rm -fr broken" &&
14 (
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
21'
22
23test_expect_success 'commit -h in broken repository' '
24 mkdir broken &&
25 test_when_finished "rm -fr broken" &&
26 (
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
33'
34
35test_expect_success 'setup' '
36 : >tracked &&
37 : >modified &&
38 mkdir dir1 &&
39 : >dir1/tracked &&
40 : >dir1/modified &&
41 mkdir dir2 &&
42 : >dir1/tracked &&
43 : >dir1/modified &&
44 git add . &&
45
46 git status >output &&
47
48 test_tick &&
49 git commit -m initial &&
50 : >untracked &&
51 : >dir1/untracked &&
52 : >dir2/untracked &&
53 echo 1 >dir1/modified &&
54 echo 2 >dir2/modified &&
55 echo 3 >dir2/added &&
56 git add dir2/added
57'
58
59test_expect_success 'status (1)' '
60 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
61'
62
63strip_comments () {
64 tab=' '
65 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
66 rm "$1" && mv "$1".tmp "$1"
67}
68
69cat >.gitignore <<\EOF
70.gitignore
71expect*
72output*
73EOF
74
75test_expect_success 'status --column' '
76 cat >expect <<\EOF &&
77# On branch master
78# Changes to be committed:
79# (use "git reset HEAD <file>..." to unstage)
80#
81# new file: dir2/added
82#
83# Changes not staged for commit:
84# (use "git add <file>..." to update what will be committed)
85# (use "git checkout -- <file>..." to discard changes in working directory)
86#
87# modified: dir1/modified
88#
89# Untracked files:
90# (use "git add <file>..." to include in what will be committed)
91#
92# dir1/untracked dir2/untracked
93# dir2/modified untracked
94#
95EOF
96 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
97 test_i18ncmp expect output
98'
99
100test_expect_success 'status --column status.displayCommentPrefix=false' '
101 strip_comments expect &&
102 COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
103 test_i18ncmp expect output
104'
105
106cat >expect <<\EOF
107# On branch master
108# Changes to be committed:
109# (use "git reset HEAD <file>..." to unstage)
110#
111# new file: dir2/added
112#
113# Changes not staged for commit:
114# (use "git add <file>..." to update what will be committed)
115# (use "git checkout -- <file>..." to discard changes in working directory)
116#
117# modified: dir1/modified
118#
119# Untracked files:
120# (use "git add <file>..." to include in what will be committed)
121#
122# dir1/untracked
123# dir2/modified
124# dir2/untracked
125# untracked
126#
127EOF
128
129test_expect_success 'status with status.displayCommentPrefix=true' '
130 git -c status.displayCommentPrefix=true status >output &&
131 test_i18ncmp expect output
132'
133
134test_expect_success 'status with status.displayCommentPrefix=false' '
135 strip_comments expect &&
136 git -c status.displayCommentPrefix=false status >output &&
137 test_i18ncmp expect output
138'
139
140test_expect_success 'status -v' '
141 (cat expect && git diff --cached) >expect-with-v &&
142 git status -v >output &&
143 test_i18ncmp expect-with-v output
144'
145
146test_expect_success 'setup fake editor' '
147 cat >.git/editor <<-\EOF &&
148 #! /bin/sh
149 cp "$1" output
150EOF
151 chmod 755 .git/editor
152'
153
154commit_template_commented () {
155 (
156 EDITOR=.git/editor &&
157 export EDITOR &&
158 # Fails due to empty message
159 test_must_fail git commit
160 ) &&
161 ! grep '^[^#]' output
162}
163
164test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
165 commit_template_commented
166'
167
168cat >expect <<\EOF
169On branch master
170Changes to be committed:
171 new file: dir2/added
172
173Changes not staged for commit:
174 modified: dir1/modified
175
176Untracked files:
177 dir1/untracked
178 dir2/modified
179 dir2/untracked
180 untracked
181
182EOF
183
184test_expect_success 'status (advice.statusHints false)' '
185 test_config advice.statusHints false &&
186 git status >output &&
187 test_i18ncmp expect output
188
189'
190
191cat >expect <<\EOF
192 M dir1/modified
193A dir2/added
194?? dir1/untracked
195?? dir2/modified
196?? dir2/untracked
197?? untracked
198EOF
199
200test_expect_success 'status -s' '
201
202 git status -s >output &&
203 test_cmp expect output
204
205'
206
207test_expect_success 'status with gitignore' '
208 {
209 echo ".gitignore" &&
210 echo "expect*" &&
211 echo "output" &&
212 echo "untracked"
213 } >.gitignore &&
214
215 cat >expect <<-\EOF &&
216 M dir1/modified
217 A dir2/added
218 ?? dir2/modified
219 EOF
220 git status -s >output &&
221 test_cmp expect output &&
222
223 cat >expect <<-\EOF &&
224 M dir1/modified
225 A dir2/added
226 ?? dir2/modified
227 !! .gitignore
228 !! dir1/untracked
229 !! dir2/untracked
230 !! expect
231 !! expect-with-v
232 !! output
233 !! untracked
234 EOF
235 git status -s --ignored >output &&
236 test_cmp expect output &&
237
238 cat >expect <<\EOF &&
239On branch master
240Changes to be committed:
241 (use "git reset HEAD <file>..." to unstage)
242
243 new file: dir2/added
244
245Changes not staged for commit:
246 (use "git add <file>..." to update what will be committed)
247 (use "git checkout -- <file>..." to discard changes in working directory)
248
249 modified: dir1/modified
250
251Untracked files:
252 (use "git add <file>..." to include in what will be committed)
253
254 dir2/modified
255
256Ignored files:
257 (use "git add -f <file>..." to include in what will be committed)
258
259 .gitignore
260 dir1/untracked
261 dir2/untracked
262 expect
263 expect-with-v
264 output
265 untracked
266
267EOF
268 git status --ignored >output &&
269 test_i18ncmp expect output
270'
271
272test_expect_success 'status with gitignore (nothing untracked)' '
273 {
274 echo ".gitignore" &&
275 echo "expect*" &&
276 echo "dir2/modified" &&
277 echo "output" &&
278 echo "untracked"
279 } >.gitignore &&
280
281 cat >expect <<-\EOF &&
282 M dir1/modified
283 A dir2/added
284 EOF
285 git status -s >output &&
286 test_cmp expect output &&
287
288 cat >expect <<-\EOF &&
289 M dir1/modified
290 A dir2/added
291 !! .gitignore
292 !! dir1/untracked
293 !! dir2/modified
294 !! dir2/untracked
295 !! expect
296 !! expect-with-v
297 !! output
298 !! untracked
299 EOF
300 git status -s --ignored >output &&
301 test_cmp expect output &&
302
303 cat >expect <<\EOF &&
304On branch master
305Changes to be committed:
306 (use "git reset HEAD <file>..." to unstage)
307
308 new file: dir2/added
309
310Changes not staged for commit:
311 (use "git add <file>..." to update what will be committed)
312 (use "git checkout -- <file>..." to discard changes in working directory)
313
314 modified: dir1/modified
315
316Ignored files:
317 (use "git add -f <file>..." to include in what will be committed)
318
319 .gitignore
320 dir1/untracked
321 dir2/modified
322 dir2/untracked
323 expect
324 expect-with-v
325 output
326 untracked
327
328EOF
329 git status --ignored >output &&
330 test_i18ncmp expect output
331'
332
333cat >.gitignore <<\EOF
334.gitignore
335expect*
336output*
337EOF
338
339cat >expect <<\EOF
340## master
341 M dir1/modified
342A dir2/added
343?? dir1/untracked
344?? dir2/modified
345?? dir2/untracked
346?? untracked
347EOF
348
349test_expect_success 'status -s -b' '
350
351 git status -s -b >output &&
352 test_cmp expect output
353
354'
355
356test_expect_success 'status -s -z -b' '
357 tr "\\n" Q <expect >expect.q &&
358 mv expect.q expect &&
359 git status -s -z -b >output &&
360 nul_to_q <output >output.q &&
361 mv output.q output &&
362 test_cmp expect output
363'
364
365test_expect_success 'setup dir3' '
366 mkdir dir3 &&
367 : >dir3/untracked1 &&
368 : >dir3/untracked2
369'
370
371test_expect_success 'status -uno' '
372 cat >expect <<EOF &&
373On branch master
374Changes to be committed:
375 (use "git reset HEAD <file>..." to unstage)
376
377 new file: dir2/added
378
379Changes not staged for commit:
380 (use "git add <file>..." to update what will be committed)
381 (use "git checkout -- <file>..." to discard changes in working directory)
382
383 modified: dir1/modified
384
385Untracked files not listed (use -u option to show untracked files)
386EOF
387 git status -uno >output &&
388 test_i18ncmp expect output
389'
390
391test_expect_success 'status (status.showUntrackedFiles no)' '
392 test_config status.showuntrackedfiles no &&
393 git status >output &&
394 test_i18ncmp expect output
395'
396
397test_expect_success 'status -uno (advice.statusHints false)' '
398 cat >expect <<EOF &&
399On branch master
400Changes to be committed:
401 new file: dir2/added
402
403Changes not staged for commit:
404 modified: dir1/modified
405
406Untracked files not listed
407EOF
408 test_config advice.statusHints false &&
409 git status -uno >output &&
410 test_i18ncmp expect output
411'
412
413cat >expect << EOF
414 M dir1/modified
415A dir2/added
416EOF
417test_expect_success 'status -s -uno' '
418 git status -s -uno >output &&
419 test_cmp expect output
420'
421
422test_expect_success 'status -s (status.showUntrackedFiles no)' '
423 git config status.showuntrackedfiles no
424 git status -s >output &&
425 test_cmp expect output
426'
427
428test_expect_success 'status -unormal' '
429 cat >expect <<EOF &&
430On branch master
431Changes to be committed:
432 (use "git reset HEAD <file>..." to unstage)
433
434 new file: dir2/added
435
436Changes not staged for commit:
437 (use "git add <file>..." to update what will be committed)
438 (use "git checkout -- <file>..." to discard changes in working directory)
439
440 modified: dir1/modified
441
442Untracked files:
443 (use "git add <file>..." to include in what will be committed)
444
445 dir1/untracked
446 dir2/modified
447 dir2/untracked
448 dir3/
449 untracked
450
451EOF
452 git status -unormal >output &&
453 test_i18ncmp expect output
454'
455
456test_expect_success 'status (status.showUntrackedFiles normal)' '
457 test_config status.showuntrackedfiles normal
458 git status >output &&
459 test_i18ncmp expect output
460'
461
462cat >expect <<EOF
463 M dir1/modified
464A dir2/added
465?? dir1/untracked
466?? dir2/modified
467?? dir2/untracked
468?? dir3/
469?? untracked
470EOF
471test_expect_success 'status -s -unormal' '
472 git status -s -unormal >output &&
473 test_cmp expect output
474'
475
476test_expect_success 'status -s (status.showUntrackedFiles normal)' '
477 git config status.showuntrackedfiles normal
478 git status -s >output &&
479 test_cmp expect output
480'
481
482test_expect_success 'status -uall' '
483 cat >expect <<EOF &&
484On branch master
485Changes to be committed:
486 (use "git reset HEAD <file>..." to unstage)
487
488 new file: dir2/added
489
490Changes 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)
493
494 modified: dir1/modified
495
496Untracked files:
497 (use "git add <file>..." to include in what will be committed)
498
499 dir1/untracked
500 dir2/modified
501 dir2/untracked
502 dir3/untracked1
503 dir3/untracked2
504 untracked
505
506EOF
507 git status -uall >output &&
508 test_i18ncmp expect output
509'
510
511test_expect_success 'status (status.showUntrackedFiles all)' '
512 test_config status.showuntrackedfiles all
513 git status >output &&
514 test_i18ncmp expect output
515'
516
517test_expect_success 'teardown dir3' '
518 rm -rf dir3
519'
520
521cat >expect <<EOF
522 M dir1/modified
523A dir2/added
524?? dir1/untracked
525?? dir2/modified
526?? dir2/untracked
527?? untracked
528EOF
529test_expect_success 'status -s -uall' '
530 git config --unset status.showuntrackedfiles
531 git status -s -uall >output &&
532 test_cmp expect output
533'
534test_expect_success 'status -s (status.showUntrackedFiles all)' '
535 test_config status.showuntrackedfiles all &&
536 git status -s >output &&
537 rm -rf dir3 &&
538 test_cmp expect output
539'
540
541test_expect_success 'status with relative paths' '
542 cat >expect <<\EOF &&
543On branch master
544Changes to be committed:
545 (use "git reset HEAD <file>..." to unstage)
546
547 new file: ../dir2/added
548
549Changes not staged for commit:
550 (use "git add <file>..." to update what will be committed)
551 (use "git checkout -- <file>..." to discard changes in working directory)
552
553 modified: modified
554
555Untracked files:
556 (use "git add <file>..." to include in what will be committed)
557
558 untracked
559 ../dir2/modified
560 ../dir2/untracked
561 ../untracked
562
563EOF
564 (cd dir1 && git status) >output &&
565 test_i18ncmp expect output
566'
567
568cat >expect <<\EOF
569 M modified
570A ../dir2/added
571?? untracked
572?? ../dir2/modified
573?? ../dir2/untracked
574?? ../untracked
575EOF
576test_expect_success 'status -s with relative paths' '
577
578 (cd dir1 && git status -s) >output &&
579 test_cmp expect output
580
581'
582
583cat >expect <<\EOF
584 M dir1/modified
585A dir2/added
586?? dir1/untracked
587?? dir2/modified
588?? dir2/untracked
589?? untracked
590EOF
591
592test_expect_success 'status --porcelain ignores relative paths setting' '
593
594 (cd dir1 && git status --porcelain) >output &&
595 test_cmp expect output
596
597'
598
599test_expect_success 'setup unique colors' '
600
601 git config status.color.untracked blue &&
602 git config status.color.branch green
603
604'
605
606test_expect_success 'status with color.ui' '
607 cat >expect <<\EOF &&
608On branch <GREEN>master<RESET>
609Changes to be committed:
610 (use "git reset HEAD <file>..." to unstage)
611
612 <GREEN>new file: dir2/added<RESET>
613
614Changes not staged for commit:
615 (use "git add <file>..." to update what will be committed)
616 (use "git checkout -- <file>..." to discard changes in working directory)
617
618 <RED>modified: dir1/modified<RESET>
619
620Untracked files:
621 (use "git add <file>..." to include in what will be committed)
622
623 <BLUE>dir1/untracked<RESET>
624 <BLUE>dir2/modified<RESET>
625 <BLUE>dir2/untracked<RESET>
626 <BLUE>untracked<RESET>
627
628EOF
629 test_config color.ui always &&
630 git status | test_decode_color >output &&
631 test_i18ncmp expect output
632'
633
634test_expect_success 'status with color.status' '
635 test_config color.status always &&
636 git status | test_decode_color >output &&
637 test_i18ncmp expect output
638'
639
640cat >expect <<\EOF
641 <RED>M<RESET> dir1/modified
642<GREEN>A<RESET> dir2/added
643<BLUE>??<RESET> dir1/untracked
644<BLUE>??<RESET> dir2/modified
645<BLUE>??<RESET> dir2/untracked
646<BLUE>??<RESET> untracked
647EOF
648
649test_expect_success 'status -s with color.ui' '
650
651 git config color.ui always &&
652 git status -s | test_decode_color >output &&
653 test_cmp expect output
654
655'
656
657test_expect_success 'status -s with color.status' '
658
659 git config --unset color.ui &&
660 git config color.status always &&
661 git status -s | test_decode_color >output &&
662 test_cmp expect output
663
664'
665
666cat >expect <<\EOF
667## <GREEN>master<RESET>
668 <RED>M<RESET> dir1/modified
669<GREEN>A<RESET> dir2/added
670<BLUE>??<RESET> dir1/untracked
671<BLUE>??<RESET> dir2/modified
672<BLUE>??<RESET> dir2/untracked
673<BLUE>??<RESET> untracked
674EOF
675
676test_expect_success 'status -s -b with color.status' '
677
678 git status -s -b | test_decode_color >output &&
679 test_cmp expect output
680
681'
682
683cat >expect <<\EOF
684 M dir1/modified
685A dir2/added
686?? dir1/untracked
687?? dir2/modified
688?? dir2/untracked
689?? untracked
690EOF
691
692test_expect_success 'status --porcelain ignores color.ui' '
693
694 git config --unset color.status &&
695 git config color.ui always &&
696 git status --porcelain | test_decode_color >output &&
697 test_cmp expect output
698
699'
700
701test_expect_success 'status --porcelain ignores color.status' '
702
703 git config --unset color.ui &&
704 git config color.status always &&
705 git status --porcelain | test_decode_color >output &&
706 test_cmp expect output
707
708'
709
710# recover unconditionally from color tests
711git config --unset color.status
712git config --unset color.ui
713
714test_expect_success 'status --porcelain respects -b' '
715
716 git status --porcelain -b >output &&
717 {
718 echo "## master" &&
719 cat expect
720 } >tmp &&
721 mv tmp expect &&
722 test_cmp expect output
723
724'
725
726
727
728test_expect_success 'status without relative paths' '
729 cat >expect <<\EOF &&
730On branch master
731Changes to be committed:
732 (use "git reset HEAD <file>..." to unstage)
733
734 new file: dir2/added
735
736Changes not staged for commit:
737 (use "git add <file>..." to update what will be committed)
738 (use "git checkout -- <file>..." to discard changes in working directory)
739
740 modified: dir1/modified
741
742Untracked files:
743 (use "git add <file>..." to include in what will be committed)
744
745 dir1/untracked
746 dir2/modified
747 dir2/untracked
748 untracked
749
750EOF
751 test_config status.relativePaths false &&
752 (cd dir1 && git status) >output &&
753 test_i18ncmp expect output
754
755'
756
757cat >expect <<\EOF
758 M dir1/modified
759A dir2/added
760?? dir1/untracked
761?? dir2/modified
762?? dir2/untracked
763?? untracked
764EOF
765
766test_expect_success 'status -s without relative paths' '
767
768 test_config status.relativePaths false &&
769 (cd dir1 && git status -s) >output &&
770 test_cmp expect output
771
772'
773
774test_expect_success 'dry-run of partial commit excluding new file in index' '
775 cat >expect <<EOF &&
776On branch master
777Changes to be committed:
778 (use "git reset HEAD <file>..." to unstage)
779
780 modified: dir1/modified
781
782Untracked files:
783 (use "git add <file>..." to include in what will be committed)
784
785 dir1/untracked
786 dir2/
787 untracked
788
789EOF
790 git commit --dry-run dir1/modified >output &&
791 test_i18ncmp expect output
792'
793
794cat >expect <<EOF
795:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
796EOF
797test_expect_success 'status refreshes the index' '
798 touch dir2/added &&
799 git status &&
800 git diff-files >output &&
801 test_cmp expect output
802'
803
804test_expect_success 'setup status submodule summary' '
805 test_create_repo sm && (
806 cd sm &&
807 >foo &&
808 git add foo &&
809 git commit -m "Add foo"
810 ) &&
811 git add sm
812'
813
814test_expect_success 'status submodule summary is disabled by default' '
815 cat >expect <<EOF &&
816On branch master
817Changes to be committed:
818 (use "git reset HEAD <file>..." to unstage)
819
820 new file: dir2/added
821 new file: sm
822
823Changes not staged for commit:
824 (use "git add <file>..." to update what will be committed)
825 (use "git checkout -- <file>..." to discard changes in working directory)
826
827 modified: dir1/modified
828
829Untracked files:
830 (use "git add <file>..." to include in what will be committed)
831
832 dir1/untracked
833 dir2/modified
834 dir2/untracked
835 untracked
836
837EOF
838 git status >output &&
839 test_i18ncmp expect output
840'
841
842# we expect the same as the previous test
843test_expect_success 'status --untracked-files=all does not show submodule' '
844 git status --untracked-files=all >output &&
845 test_i18ncmp expect output
846'
847
848cat >expect <<EOF
849 M dir1/modified
850A dir2/added
851A sm
852?? dir1/untracked
853?? dir2/modified
854?? dir2/untracked
855?? untracked
856EOF
857test_expect_success 'status -s submodule summary is disabled by default' '
858 git status -s >output &&
859 test_cmp expect output
860'
861
862# we expect the same as the previous test
863test_expect_success 'status -s --untracked-files=all does not show submodule' '
864 git status -s --untracked-files=all >output &&
865 test_cmp expect output
866'
867
868head=$(cd sm && git rev-parse --short=7 --verify HEAD)
869
870test_expect_success 'status submodule summary' '
871 cat >expect <<EOF &&
872On branch master
873Changes to be committed:
874 (use "git reset HEAD <file>..." to unstage)
875
876 new file: dir2/added
877 new file: sm
878
879Changes not staged for commit:
880 (use "git add <file>..." to update what will be committed)
881 (use "git checkout -- <file>..." to discard changes in working directory)
882
883 modified: dir1/modified
884
885Submodule changes to be committed:
886
887* sm 0000000...$head (1):
888 > Add foo
889
890Untracked files:
891 (use "git add <file>..." to include in what will be committed)
892
893 dir1/untracked
894 dir2/modified
895 dir2/untracked
896 untracked
897
898EOF
899 git config status.submodulesummary 10 &&
900 git status >output &&
901 test_i18ncmp expect output
902'
903
904test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
905 strip_comments expect &&
906 git -c status.displayCommentPrefix=false status >output &&
907 test_i18ncmp expect output
908'
909
910test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
911 commit_template_commented
912'
913
914cat >expect <<EOF
915 M dir1/modified
916A dir2/added
917A sm
918?? dir1/untracked
919?? dir2/modified
920?? dir2/untracked
921?? untracked
922EOF
923test_expect_success 'status -s submodule summary' '
924 git status -s >output &&
925 test_cmp expect output
926'
927
928test_expect_success 'status submodule summary (clean submodule): commit' '
929 cat >expect <<EOF &&
930On branch master
931Changes not staged for commit:
932 (use "git add <file>..." to update what will be committed)
933 (use "git checkout -- <file>..." to discard changes in working directory)
934
935 modified: dir1/modified
936
937Untracked files:
938 (use "git add <file>..." to include in what will be committed)
939
940 dir1/untracked
941 dir2/modified
942 dir2/untracked
943 untracked
944
945no changes added to commit (use "git add" and/or "git commit -a")
946EOF
947 git commit -m "commit submodule" &&
948 git config status.submodulesummary 10 &&
949 test_must_fail git commit --dry-run >output &&
950 test_i18ncmp expect output &&
951 git status >output &&
952 test_i18ncmp expect output
953'
954
955cat >expect <<EOF
956 M dir1/modified
957?? dir1/untracked
958?? dir2/modified
959?? dir2/untracked
960?? untracked
961EOF
962test_expect_success 'status -s submodule summary (clean submodule)' '
963 git status -s >output &&
964 test_cmp expect output
965'
966
967test_expect_success 'status -z implies porcelain' '
968 git status --porcelain |
969 perl -pe "s/\012/\000/g" >expect &&
970 git status -z >output &&
971 test_cmp expect output
972'
973
974test_expect_success 'commit --dry-run submodule summary (--amend)' '
975 cat >expect <<EOF &&
976On branch master
977Changes to be committed:
978 (use "git reset HEAD^1 <file>..." to unstage)
979
980 new file: dir2/added
981 new file: sm
982
983Changes not staged for commit:
984 (use "git add <file>..." to update what will be committed)
985 (use "git checkout -- <file>..." to discard changes in working directory)
986
987 modified: dir1/modified
988
989Submodule changes to be committed:
990
991* sm 0000000...$head (1):
992 > Add foo
993
994Untracked files:
995 (use "git add <file>..." to include in what will be committed)
996
997 dir1/untracked
998 dir2/modified
999 dir2/untracked
1000 untracked
1001
1002EOF
1003 git config status.submodulesummary 10 &&
1004 git commit --dry-run --amend >output &&
1005 test_i18ncmp expect output
1006'
1007
1008test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1009 (
1010 chmod a-w .git &&
1011 # make dir1/tracked stat-dirty
1012 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1013 git status -s >output &&
1014 ! grep dir1/tracked output &&
1015 # make sure "status" succeeded without writing index out
1016 git diff-files | grep dir1/tracked
1017 )
1018 status=$?
1019 chmod 775 .git
1020 (exit $status)
1021'
1022
1023(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
1024new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1025touch .gitmodules
1026
1027test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1028 cat > expect << EOF &&
1029On branch master
1030Changes to be committed:
1031 (use "git reset HEAD <file>..." to unstage)
1032
1033 modified: sm
1034
1035Changes not staged for commit:
1036 (use "git add <file>..." to update what will be committed)
1037 (use "git checkout -- <file>..." to discard changes in working directory)
1038
1039 modified: dir1/modified
1040
1041Submodule changes to be committed:
1042
1043* sm $head...$new_head (1):
1044 > Add bar
1045
1046Untracked files:
1047 (use "git add <file>..." to include in what will be committed)
1048
1049 .gitmodules
1050 dir1/untracked
1051 dir2/modified
1052 dir2/untracked
1053 untracked
1054
1055EOF
1056 echo modified sm/untracked &&
1057 git status --ignore-submodules=untracked >output &&
1058 test_i18ncmp expect output
1059'
1060
1061test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
1062 test_config diff.ignoreSubmodules dirty &&
1063 git status >output &&
1064 test_i18ncmp expect output &&
1065 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1066 git config --add -f .gitmodules submodule.subname.path sm &&
1067 git status >output &&
1068 test_i18ncmp expect output &&
1069 git config -f .gitmodules --remove-section submodule.subname
1070'
1071
1072test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
1073 git config --add -f .gitmodules submodule.subname.ignore none &&
1074 git config --add -f .gitmodules submodule.subname.path sm &&
1075 git config --add submodule.subname.ignore untracked &&
1076 git config --add submodule.subname.path sm &&
1077 git status >output &&
1078 test_i18ncmp expect output &&
1079 git config --remove-section submodule.subname &&
1080 git config --remove-section -f .gitmodules submodule.subname
1081'
1082
1083test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1084 git status --ignore-submodules=dirty >output &&
1085 test_i18ncmp expect output
1086'
1087
1088test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
1089 test_config diff.ignoreSubmodules dirty &&
1090 git status >output &&
1091 ! test -s actual &&
1092 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1093 git config --add -f .gitmodules submodule.subname.path sm &&
1094 git status >output &&
1095 test_i18ncmp expect output &&
1096 git config -f .gitmodules --remove-section submodule.subname
1097'
1098
1099test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
1100 git config --add -f .gitmodules submodule.subname.ignore none &&
1101 git config --add -f .gitmodules submodule.subname.path sm &&
1102 git config --add submodule.subname.ignore dirty &&
1103 git config --add submodule.subname.path sm &&
1104 git status >output &&
1105 test_i18ncmp expect output &&
1106 git config --remove-section submodule.subname &&
1107 git config -f .gitmodules --remove-section submodule.subname
1108'
1109
1110test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1111 echo modified >sm/foo &&
1112 git status --ignore-submodules=dirty >output &&
1113 test_i18ncmp expect output
1114'
1115
1116test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
1117 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1118 git config --add -f .gitmodules submodule.subname.path sm &&
1119 git status >output &&
1120 test_i18ncmp expect output &&
1121 git config -f .gitmodules --remove-section submodule.subname
1122'
1123
1124test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
1125 git config --add -f .gitmodules submodule.subname.ignore none &&
1126 git config --add -f .gitmodules submodule.subname.path sm &&
1127 git config --add submodule.subname.ignore dirty &&
1128 git config --add submodule.subname.path sm &&
1129 git status >output &&
1130 test_i18ncmp expect output &&
1131 git config --remove-section submodule.subname &&
1132 git config -f .gitmodules --remove-section submodule.subname
1133'
1134
1135test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1136 cat > expect << EOF &&
1137On branch master
1138Changes to be committed:
1139 (use "git reset HEAD <file>..." to unstage)
1140
1141 modified: sm
1142
1143Changes not staged for commit:
1144 (use "git add <file>..." to update what will be committed)
1145 (use "git checkout -- <file>..." to discard changes in working directory)
1146 (commit or discard the untracked or modified content in submodules)
1147
1148 modified: dir1/modified
1149 modified: sm (modified content)
1150
1151Submodule changes to be committed:
1152
1153* sm $head...$new_head (1):
1154 > Add bar
1155
1156Untracked files:
1157 (use "git add <file>..." to include in what will be committed)
1158
1159 .gitmodules
1160 dir1/untracked
1161 dir2/modified
1162 dir2/untracked
1163 untracked
1164
1165EOF
1166 git status --ignore-submodules=untracked > output &&
1167 test_i18ncmp expect output
1168'
1169
1170test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1171 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1172 git config --add -f .gitmodules submodule.subname.path sm &&
1173 git status >output &&
1174 test_i18ncmp expect output &&
1175 git config -f .gitmodules --remove-section submodule.subname
1176'
1177
1178test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
1179 git config --add -f .gitmodules submodule.subname.ignore none &&
1180 git config --add -f .gitmodules submodule.subname.path sm &&
1181 git config --add submodule.subname.ignore untracked &&
1182 git config --add submodule.subname.path sm &&
1183 git status >output &&
1184 test_i18ncmp expect output &&
1185 git config --remove-section submodule.subname &&
1186 git config -f .gitmodules --remove-section submodule.subname
1187'
1188
1189head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1190
1191test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1192 cat > expect << EOF &&
1193On branch master
1194Changes to be committed:
1195 (use "git reset HEAD <file>..." to unstage)
1196
1197 modified: sm
1198
1199Changes not staged for commit:
1200 (use "git add <file>..." to update what will be committed)
1201 (use "git checkout -- <file>..." to discard changes in working directory)
1202
1203 modified: dir1/modified
1204 modified: sm (new commits)
1205
1206Submodule changes to be committed:
1207
1208* sm $head...$new_head (1):
1209 > Add bar
1210
1211Submodules changed but not updated:
1212
1213* sm $new_head...$head2 (1):
1214 > 2nd commit
1215
1216Untracked files:
1217 (use "git add <file>..." to include in what will be committed)
1218
1219 .gitmodules
1220 dir1/untracked
1221 dir2/modified
1222 dir2/untracked
1223 untracked
1224
1225EOF
1226 git status --ignore-submodules=untracked > output &&
1227 test_i18ncmp expect output
1228'
1229
1230test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
1231 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1232 git config --add -f .gitmodules submodule.subname.path sm &&
1233 git status >output &&
1234 test_i18ncmp expect output &&
1235 git config -f .gitmodules --remove-section submodule.subname
1236'
1237
1238test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
1239 git config --add -f .gitmodules submodule.subname.ignore none &&
1240 git config --add -f .gitmodules submodule.subname.path sm &&
1241 git config --add submodule.subname.ignore untracked &&
1242 git config --add submodule.subname.path sm &&
1243 git status >output &&
1244 test_i18ncmp expect output &&
1245 git config --remove-section submodule.subname &&
1246 git config -f .gitmodules --remove-section submodule.subname
1247'
1248
1249test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
1250 git status --ignore-submodules=dirty > output &&
1251 test_i18ncmp expect output
1252'
1253test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
1254 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1255 git config --add -f .gitmodules submodule.subname.path sm &&
1256 git status >output &&
1257 test_i18ncmp expect output &&
1258 git config -f .gitmodules --remove-section submodule.subname
1259'
1260
1261test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
1262 git config --add -f .gitmodules submodule.subname.ignore none &&
1263 git config --add -f .gitmodules submodule.subname.path sm &&
1264 git config --add submodule.subname.ignore dirty &&
1265 git config --add submodule.subname.path sm &&
1266 git status >output &&
1267 test_i18ncmp expect output &&
1268 git config --remove-section submodule.subname &&
1269 git config -f .gitmodules --remove-section submodule.subname
1270'
1271
1272cat > expect << EOF
1273; On branch master
1274; Changes to be committed:
1275; (use "git reset HEAD <file>..." to unstage)
1276;
1277; modified: sm
1278;
1279; Changes not staged for commit:
1280; (use "git add <file>..." to update what will be committed)
1281; (use "git checkout -- <file>..." to discard changes in working directory)
1282;
1283; modified: dir1/modified
1284; modified: sm (new commits)
1285;
1286; Submodule changes to be committed:
1287;
1288; * sm $head...$new_head (1):
1289; > Add bar
1290;
1291; Submodules changed but not updated:
1292;
1293; * sm $new_head...$head2 (1):
1294; > 2nd commit
1295;
1296; Untracked files:
1297; (use "git add <file>..." to include in what will be committed)
1298;
1299; .gitmodules
1300; dir1/untracked
1301; dir2/modified
1302; dir2/untracked
1303; untracked
1304;
1305EOF
1306
1307test_expect_success "status (core.commentchar with submodule summary)" '
1308 test_config core.commentchar ";" &&
1309 git -c status.displayCommentPrefix=true status >output &&
1310 test_i18ncmp expect output
1311'
1312
1313test_expect_success "status (core.commentchar with two chars with submodule summary)" '
1314 test_config core.commentchar ";;" &&
1315 test_must_fail git -c status.displayCommentPrefix=true status
1316'
1317
1318test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1319 cat > expect << EOF &&
1320On branch master
1321Changes not staged for commit:
1322 (use "git add <file>..." to update what will be committed)
1323 (use "git checkout -- <file>..." to discard changes in working directory)
1324
1325 modified: dir1/modified
1326
1327Untracked files:
1328 (use "git add <file>..." to include in what will be committed)
1329
1330 .gitmodules
1331 dir1/untracked
1332 dir2/modified
1333 dir2/untracked
1334 untracked
1335
1336no changes added to commit (use "git add" and/or "git commit -a")
1337EOF
1338 git status --ignore-submodules=all > output &&
1339 test_i18ncmp expect output
1340'
1341
1342test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1343 cat > expect << EOF &&
1344On branch master
1345Changes to be committed:
1346 (use "git reset HEAD <file>..." to unstage)
1347
1348 modified: sm
1349
1350Changes not staged for commit:
1351 (use "git add <file>..." to update what will be committed)
1352 (use "git checkout -- <file>..." to discard changes in working directory)
1353
1354 modified: dir1/modified
1355
1356Untracked files:
1357 (use "git add <file>..." to include in what will be committed)
1358
1359 .gitmodules
1360 dir1/untracked
1361 dir2/modified
1362 dir2/untracked
1363 untracked
1364
1365EOF
1366 git config --add -f .gitmodules submodule.subname.ignore all &&
1367 git config --add -f .gitmodules submodule.subname.path sm &&
1368 git status > output &&
1369 test_cmp expect output &&
1370 git config -f .gitmodules --remove-section submodule.subname
1371'
1372
1373test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
1374 git config --add -f .gitmodules submodule.subname.ignore none &&
1375 git config --add -f .gitmodules submodule.subname.path sm &&
1376 git config --add submodule.subname.ignore all &&
1377 git config --add submodule.subname.path sm &&
1378 git status > output &&
1379 test_cmp expect output &&
1380 git config --remove-section submodule.subname &&
1381 git config -f .gitmodules --remove-section submodule.subname
1382'
1383
1384test_expect_success 'setup of test environment' '
1385 git config status.showUntrackedFiles no &&
1386 git status -s >expected_short &&
1387 git status --no-short >expected_noshort
1388'
1389
1390test_expect_success '"status.short=true" same as "-s"' '
1391 git -c status.short=true status >actual &&
1392 test_cmp expected_short actual
1393'
1394
1395test_expect_success '"status.short=true" weaker than "--no-short"' '
1396 git -c status.short=true status --no-short >actual &&
1397 test_cmp expected_noshort actual
1398'
1399
1400test_expect_success '"status.short=false" same as "--no-short"' '
1401 git -c status.short=false status >actual &&
1402 test_cmp expected_noshort actual
1403'
1404
1405test_expect_success '"status.short=false" weaker than "-s"' '
1406 git -c status.short=false status -s >actual &&
1407 test_cmp expected_short actual
1408'
1409
1410test_expect_success '"status.branch=true" same as "-b"' '
1411 git status -sb >expected_branch &&
1412 git -c status.branch=true status -s >actual &&
1413 test_cmp expected_branch actual
1414'
1415
1416test_expect_success '"status.branch=true" different from "--no-branch"' '
1417 git status -s --no-branch >expected_nobranch &&
1418 git -c status.branch=true status -s >actual &&
1419 test_must_fail test_cmp expected_nobranch actual
1420'
1421
1422test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1423 git -c status.branch=true status -s --no-branch >actual &&
1424 test_cmp expected_nobranch actual
1425'
1426
1427test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1428 git -c status.branch=true status --porcelain >actual &&
1429 test_cmp expected_nobranch actual
1430'
1431
1432test_expect_success '"status.branch=false" same as "--no-branch"' '
1433 git -c status.branch=false status -s >actual &&
1434 test_cmp expected_nobranch actual
1435'
1436
1437test_expect_success '"status.branch=false" weaker than "-b"' '
1438 git -c status.branch=false status -sb >actual &&
1439 test_cmp expected_branch actual
1440'
1441
1442test_expect_success 'Restore default test environment' '
1443 git config --unset status.showUntrackedFiles
1444'
1445
1446test_expect_success 'git commit will commit a staged but ignored submodule' '
1447 git config --add -f .gitmodules submodule.subname.ignore all &&
1448 git config --add -f .gitmodules submodule.subname.path sm &&
1449 git config --add submodule.subname.ignore all &&
1450 git status -s --ignore-submodules=dirty >output &&
1451 test_i18ngrep "^M. sm" output &&
1452 GIT_EDITOR="echo hello >>\"\$1\"" &&
1453 export GIT_EDITOR &&
1454 git commit -uno &&
1455 git status -s --ignore-submodules=dirty >output &&
1456 test_i18ngrep ! "^M. sm" output
1457'
1458
1459test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
1460 git reset HEAD^ &&
1461 git add sm &&
1462 cat >expect << EOF &&
1463On branch master
1464Changes to be committed:
1465 (use "git reset HEAD <file>..." to unstage)
1466
1467 modified: sm
1468
1469Changes not staged for commit:
1470 (use "git add <file>..." to update what will be committed)
1471 (use "git checkout -- <file>..." to discard changes in working directory)
1472
1473 modified: dir1/modified
1474
1475Untracked files not listed (use -u option to show untracked files)
1476EOF
1477 git commit -uno --dry-run >output &&
1478 test_i18ncmp expect output &&
1479 git status -s --ignore-submodules=dirty >output &&
1480 test_i18ngrep "^M. sm" output
1481'
1482
1483test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1484 git commit -uno -m message &&
1485 git status -s --ignore-submodules=dirty >output &&
1486 test_i18ngrep ! "^M. sm" output &&
1487 git config --remove-section submodule.subname &&
1488 git config -f .gitmodules --remove-section submodule.subname
1489'
1490
1491test_done