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