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