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