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