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