git status --ignored: tests and docs
[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 'setup' '
11         : >tracked &&
12         : >modified &&
13         mkdir dir1 &&
14         : >dir1/tracked &&
15         : >dir1/modified &&
16         mkdir dir2 &&
17         : >dir1/tracked &&
18         : >dir1/modified &&
19         git add . &&
20
21         git status >output &&
22
23         test_tick &&
24         git commit -m initial &&
25         : >untracked &&
26         : >dir1/untracked &&
27         : >dir2/untracked &&
28         echo 1 >dir1/modified &&
29         echo 2 >dir2/modified &&
30         echo 3 >dir2/added &&
31         git add dir2/added
32 '
33
34 test_expect_success 'status (1)' '
35
36         grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
37
38 '
39
40 cat >expect <<\EOF
41 # On branch master
42 # Changes to be committed:
43 #   (use "git reset HEAD <file>..." to unstage)
44 #
45 #       new file:   dir2/added
46 #
47 # Changed but not updated:
48 #   (use "git add <file>..." to update what will be committed)
49 #   (use "git checkout -- <file>..." to discard changes in working directory)
50 #
51 #       modified:   dir1/modified
52 #
53 # Untracked files:
54 #   (use "git add <file>..." to include in what will be committed)
55 #
56 #       dir1/untracked
57 #       dir2/modified
58 #       dir2/untracked
59 #       expect
60 #       output
61 #       untracked
62 EOF
63
64 test_expect_success 'status (2)' '
65
66         git status >output &&
67         test_cmp expect output
68
69 '
70
71 cat >expect <<\EOF
72  M dir1/modified
73 A  dir2/added
74 ?? dir1/untracked
75 ?? dir2/modified
76 ?? dir2/untracked
77 ?? expect
78 ?? output
79 ?? untracked
80 EOF
81
82 test_expect_success 'status -s (2)' '
83
84         git status -s >output &&
85         test_cmp expect output
86
87 '
88
89 test_expect_success 'status with gitignore' '
90         {
91                 echo ".gitignore" &&
92                 echo "expect" &&
93                 echo "output" &&
94                 echo "untracked"
95         } >.gitignore &&
96
97         cat >expect <<-\EOF &&
98          M dir1/modified
99         A  dir2/added
100         ?? dir2/modified
101         EOF
102         git status -s >output &&
103         test_cmp expect output &&
104
105         cat >expect <<-\EOF &&
106          M dir1/modified
107         A  dir2/added
108         ?? dir2/modified
109         !! .gitignore
110         !! dir1/untracked
111         !! dir2/untracked
112         !! expect
113         !! output
114         !! untracked
115         EOF
116         git status -s --ignored >output &&
117         test_cmp expect output &&
118
119         cat >expect <<-\EOF &&
120         # On branch master
121         # Changes to be committed:
122         #   (use "git reset HEAD <file>..." to unstage)
123         #
124         #       new file:   dir2/added
125         #
126         # Changed but not updated:
127         #   (use "git add <file>..." to update what will be committed)
128         #   (use "git checkout -- <file>..." to discard changes in working directory)
129         #
130         #       modified:   dir1/modified
131         #
132         # Untracked files:
133         #   (use "git add <file>..." to include in what will be committed)
134         #
135         #       dir2/modified
136         # Ignored files:
137         #   (use "git add -f <file>..." to include in what will be committed)
138         #
139         #       .gitignore
140         #       dir1/untracked
141         #       dir2/untracked
142         #       expect
143         #       output
144         #       untracked
145         EOF
146         git status --ignored >output &&
147         test_cmp expect output
148 '
149
150 test_expect_success 'status with gitignore (nothing untracked)' '
151         {
152                 echo ".gitignore" &&
153                 echo "expect" &&
154                 echo "dir2/modified" &&
155                 echo "output" &&
156                 echo "untracked"
157         } >.gitignore &&
158
159         cat >expect <<-\EOF &&
160          M dir1/modified
161         A  dir2/added
162         EOF
163         git status -s >output &&
164         test_cmp expect output &&
165
166         cat >expect <<-\EOF &&
167          M dir1/modified
168         A  dir2/added
169         !! .gitignore
170         !! dir1/untracked
171         !! dir2/modified
172         !! dir2/untracked
173         !! expect
174         !! output
175         !! untracked
176         EOF
177         git status -s --ignored >output &&
178         test_cmp expect output &&
179
180         cat >expect <<-\EOF &&
181         # On branch master
182         # Changes to be committed:
183         #   (use "git reset HEAD <file>..." to unstage)
184         #
185         #       new file:   dir2/added
186         #
187         # Changed but not updated:
188         #   (use "git add <file>..." to update what will be committed)
189         #   (use "git checkout -- <file>..." to discard changes in working directory)
190         #
191         #       modified:   dir1/modified
192         #
193         # Ignored files:
194         #   (use "git add -f <file>..." to include in what will be committed)
195         #
196         #       .gitignore
197         #       dir1/untracked
198         #       dir2/modified
199         #       dir2/untracked
200         #       expect
201         #       output
202         #       untracked
203         EOF
204         git status --ignored >output &&
205         test_cmp expect output
206 '
207
208 rm -f .gitignore
209
210 cat >expect <<EOF
211 # On branch master
212 # Changes to be committed:
213 #   (use "git reset HEAD <file>..." to unstage)
214 #
215 #       new file:   dir2/added
216 #
217 # Changed but not updated:
218 #   (use "git add <file>..." to update what will be committed)
219 #   (use "git checkout -- <file>..." to discard changes in working directory)
220 #
221 #       modified:   dir1/modified
222 #
223 # Untracked files not listed (use -u option to show untracked files)
224 EOF
225 test_expect_success 'status -uno' '
226         mkdir dir3 &&
227         : >dir3/untracked1 &&
228         : >dir3/untracked2 &&
229         git status -uno >output &&
230         test_cmp expect output
231 '
232
233 test_expect_success 'status (status.showUntrackedFiles no)' '
234         git config status.showuntrackedfiles no
235         git status >output &&
236         test_cmp expect output
237 '
238
239 cat >expect << EOF
240  M dir1/modified
241 A  dir2/added
242 EOF
243 test_expect_success 'status -s -uno' '
244         git config --unset status.showuntrackedfiles
245         git status -s -uno >output &&
246         test_cmp expect output
247 '
248
249 test_expect_success 'status -s (status.showUntrackedFiles no)' '
250         git config status.showuntrackedfiles no
251         git status -s >output &&
252         test_cmp expect output
253 '
254
255 cat >expect <<EOF
256 # On branch master
257 # Changes to be committed:
258 #   (use "git reset HEAD <file>..." to unstage)
259 #
260 #       new file:   dir2/added
261 #
262 # Changed but not updated:
263 #   (use "git add <file>..." to update what will be committed)
264 #   (use "git checkout -- <file>..." to discard changes in working directory)
265 #
266 #       modified:   dir1/modified
267 #
268 # Untracked files:
269 #   (use "git add <file>..." to include in what will be committed)
270 #
271 #       dir1/untracked
272 #       dir2/modified
273 #       dir2/untracked
274 #       dir3/
275 #       expect
276 #       output
277 #       untracked
278 EOF
279 test_expect_success 'status -unormal' '
280         git status -unormal >output &&
281         test_cmp expect output
282 '
283
284 test_expect_success 'status (status.showUntrackedFiles normal)' '
285         git config status.showuntrackedfiles normal
286         git status >output &&
287         test_cmp expect output
288 '
289
290 cat >expect <<EOF
291  M dir1/modified
292 A  dir2/added
293 ?? dir1/untracked
294 ?? dir2/modified
295 ?? dir2/untracked
296 ?? dir3/
297 ?? expect
298 ?? output
299 ?? untracked
300 EOF
301 test_expect_success 'status -s -unormal' '
302         git config --unset status.showuntrackedfiles
303         git status -s -unormal >output &&
304         test_cmp expect output
305 '
306
307 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
308         git config status.showuntrackedfiles normal
309         git status -s >output &&
310         test_cmp expect output
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 # Changed but not updated:
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:
327 #   (use "git add <file>..." to include in what will be committed)
328 #
329 #       dir1/untracked
330 #       dir2/modified
331 #       dir2/untracked
332 #       dir3/untracked1
333 #       dir3/untracked2
334 #       expect
335 #       output
336 #       untracked
337 EOF
338 test_expect_success 'status -uall' '
339         git status -uall >output &&
340         test_cmp expect output
341 '
342 test_expect_success 'status (status.showUntrackedFiles all)' '
343         git config status.showuntrackedfiles all
344         git status >output &&
345         rm -rf dir3 &&
346         git config --unset status.showuntrackedfiles &&
347         test_cmp expect output
348 '
349
350 cat >expect <<EOF
351  M dir1/modified
352 A  dir2/added
353 ?? dir1/untracked
354 ?? dir2/modified
355 ?? dir2/untracked
356 ?? expect
357 ?? output
358 ?? untracked
359 EOF
360 test_expect_success 'status -s -uall' '
361         git config --unset status.showuntrackedfiles
362         git status -s -uall >output &&
363         test_cmp expect output
364 '
365 test_expect_success 'status -s (status.showUntrackedFiles all)' '
366         git config status.showuntrackedfiles all
367         git status -s >output &&
368         rm -rf dir3 &&
369         git config --unset status.showuntrackedfiles &&
370         test_cmp expect output
371 '
372
373 cat >expect <<\EOF
374 # On branch master
375 # Changes to be committed:
376 #   (use "git reset HEAD <file>..." to unstage)
377 #
378 #       new file:   ../dir2/added
379 #
380 # Changed but not updated:
381 #   (use "git add <file>..." to update what will be committed)
382 #   (use "git checkout -- <file>..." to discard changes in working directory)
383 #
384 #       modified:   modified
385 #
386 # Untracked files:
387 #   (use "git add <file>..." to include in what will be committed)
388 #
389 #       untracked
390 #       ../dir2/modified
391 #       ../dir2/untracked
392 #       ../expect
393 #       ../output
394 #       ../untracked
395 EOF
396
397 test_expect_success 'status with relative paths' '
398
399         (cd dir1 && git status) >output &&
400         test_cmp expect output
401
402 '
403
404 cat >expect <<\EOF
405  M modified
406 A  ../dir2/added
407 ?? untracked
408 ?? ../dir2/modified
409 ?? ../dir2/untracked
410 ?? ../expect
411 ?? ../output
412 ?? ../untracked
413 EOF
414 test_expect_success 'status -s with relative paths' '
415
416         (cd dir1 && git status -s) >output &&
417         test_cmp expect output
418
419 '
420
421 cat >expect <<\EOF
422  M dir1/modified
423 A  dir2/added
424 ?? dir1/untracked
425 ?? dir2/modified
426 ?? dir2/untracked
427 ?? expect
428 ?? output
429 ?? untracked
430 EOF
431
432 test_expect_success 'status --porcelain ignores relative paths setting' '
433
434         (cd dir1 && git status --porcelain) >output &&
435         test_cmp expect output
436
437 '
438
439 test_expect_success 'setup unique colors' '
440
441         git config status.color.untracked blue
442
443 '
444
445 cat >expect <<\EOF
446 # On branch master
447 # Changes to be committed:
448 #   (use "git reset HEAD <file>..." to unstage)
449 #
450 #       <GREEN>new file:   dir2/added<RESET>
451 #
452 # Changed but not updated:
453 #   (use "git add <file>..." to update what will be committed)
454 #   (use "git checkout -- <file>..." to discard changes in working directory)
455 #
456 #       <RED>modified:   dir1/modified<RESET>
457 #
458 # Untracked files:
459 #   (use "git add <file>..." to include in what will be committed)
460 #
461 #       <BLUE>dir1/untracked<RESET>
462 #       <BLUE>dir2/modified<RESET>
463 #       <BLUE>dir2/untracked<RESET>
464 #       <BLUE>expect<RESET>
465 #       <BLUE>output<RESET>
466 #       <BLUE>untracked<RESET>
467 EOF
468
469 test_expect_success 'status with color.ui' '
470
471         git config color.ui always &&
472         git status | test_decode_color >output &&
473         test_cmp expect output
474
475 '
476
477 test_expect_success 'status with color.status' '
478
479         git config --unset color.ui &&
480         git config color.status always &&
481         git status | test_decode_color >output &&
482         test_cmp expect output
483
484 '
485
486 cat >expect <<\EOF
487  <RED>M<RESET> dir1/modified
488 <GREEN>A<RESET>  dir2/added
489 <BLUE>??<RESET> dir1/untracked
490 <BLUE>??<RESET> dir2/modified
491 <BLUE>??<RESET> dir2/untracked
492 <BLUE>??<RESET> expect
493 <BLUE>??<RESET> output
494 <BLUE>??<RESET> untracked
495 EOF
496
497 test_expect_success 'status -s with color.ui' '
498
499         git config --unset color.status &&
500         git config color.ui always &&
501         git status -s | test_decode_color >output &&
502         test_cmp expect output
503
504 '
505
506 test_expect_success 'status -s with color.status' '
507
508         git config --unset color.ui &&
509         git config color.status always &&
510         git status -s | test_decode_color >output &&
511         test_cmp expect output
512
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
526 test_expect_success 'status --porcelain ignores color.ui' '
527
528         git config --unset color.status &&
529         git config color.ui always &&
530         git status --porcelain | test_decode_color >output &&
531         test_cmp expect output
532
533 '
534
535 test_expect_success 'status --porcelain ignores color.status' '
536
537         git config --unset color.ui &&
538         git config color.status always &&
539         git status --porcelain | test_decode_color >output &&
540         test_cmp expect output
541
542 '
543
544 # recover unconditionally from color tests
545 git config --unset color.status
546 git config --unset color.ui
547
548 cat >expect <<\EOF
549 # On branch master
550 # Changes to be committed:
551 #   (use "git reset HEAD <file>..." to unstage)
552 #
553 #       new file:   dir2/added
554 #
555 # Changed but not updated:
556 #   (use "git add <file>..." to update what will be committed)
557 #   (use "git checkout -- <file>..." to discard changes in working directory)
558 #
559 #       modified:   dir1/modified
560 #
561 # Untracked files:
562 #   (use "git add <file>..." to include in what will be committed)
563 #
564 #       dir1/untracked
565 #       dir2/modified
566 #       dir2/untracked
567 #       expect
568 #       output
569 #       untracked
570 EOF
571
572
573 test_expect_success 'status without relative paths' '
574
575         git config status.relativePaths false
576         (cd dir1 && git status) >output &&
577         test_cmp expect output
578
579 '
580
581 cat >expect <<\EOF
582  M dir1/modified
583 A  dir2/added
584 ?? dir1/untracked
585 ?? dir2/modified
586 ?? dir2/untracked
587 ?? expect
588 ?? output
589 ?? untracked
590 EOF
591
592 test_expect_success 'status -s without relative paths' '
593
594         (cd dir1 && git status -s) >output &&
595         test_cmp expect output
596
597 '
598
599 cat <<EOF >expect
600 # On branch master
601 # Changes to be committed:
602 #   (use "git reset HEAD <file>..." to unstage)
603 #
604 #       modified:   dir1/modified
605 #
606 # Untracked files:
607 #   (use "git add <file>..." to include in what will be committed)
608 #
609 #       dir1/untracked
610 #       dir2/
611 #       expect
612 #       output
613 #       untracked
614 EOF
615 test_expect_success 'dry-run of partial commit excluding new file in index' '
616         git commit --dry-run dir1/modified >output &&
617         test_cmp expect output
618 '
619
620 test_expect_success 'setup status submodule summary' '
621         test_create_repo sm && (
622                 cd sm &&
623                 >foo &&
624                 git add foo &&
625                 git commit -m "Add foo"
626         ) &&
627         git add sm
628 '
629
630 cat >expect <<EOF
631 # On branch master
632 # Changes to be committed:
633 #   (use "git reset HEAD <file>..." to unstage)
634 #
635 #       new file:   dir2/added
636 #       new file:   sm
637 #
638 # Changed but not updated:
639 #   (use "git add <file>..." to update what will be committed)
640 #   (use "git checkout -- <file>..." to discard changes in working directory)
641 #
642 #       modified:   dir1/modified
643 #
644 # Untracked files:
645 #   (use "git add <file>..." to include in what will be committed)
646 #
647 #       dir1/untracked
648 #       dir2/modified
649 #       dir2/untracked
650 #       expect
651 #       output
652 #       untracked
653 EOF
654 test_expect_success 'status submodule summary is disabled by default' '
655         git status >output &&
656         test_cmp expect output
657 '
658
659 # we expect the same as the previous test
660 test_expect_success 'status --untracked-files=all does not show submodule' '
661         git status --untracked-files=all >output &&
662         test_cmp expect output
663 '
664
665 cat >expect <<EOF
666  M dir1/modified
667 A  dir2/added
668 A  sm
669 ?? dir1/untracked
670 ?? dir2/modified
671 ?? dir2/untracked
672 ?? expect
673 ?? output
674 ?? untracked
675 EOF
676 test_expect_success 'status -s submodule summary is disabled by default' '
677         git status -s >output &&
678         test_cmp expect output
679 '
680
681 # we expect the same as the previous test
682 test_expect_success 'status -s --untracked-files=all does not show submodule' '
683         git status -s --untracked-files=all >output &&
684         test_cmp expect output
685 '
686
687 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
688
689 cat >expect <<EOF
690 # On branch master
691 # Changes to be committed:
692 #   (use "git reset HEAD <file>..." to unstage)
693 #
694 #       new file:   dir2/added
695 #       new file:   sm
696 #
697 # Changed but not updated:
698 #   (use "git add <file>..." to update what will be committed)
699 #   (use "git checkout -- <file>..." to discard changes in working directory)
700 #
701 #       modified:   dir1/modified
702 #
703 # Submodule changes to be committed:
704 #
705 # * sm 0000000...$head (1):
706 #   > Add foo
707 #
708 # Untracked files:
709 #   (use "git add <file>..." to include in what will be committed)
710 #
711 #       dir1/untracked
712 #       dir2/modified
713 #       dir2/untracked
714 #       expect
715 #       output
716 #       untracked
717 EOF
718 test_expect_success 'status submodule summary' '
719         git config status.submodulesummary 10 &&
720         git status >output &&
721         test_cmp expect output
722 '
723
724 cat >expect <<EOF
725  M dir1/modified
726 A  dir2/added
727 A  sm
728 ?? dir1/untracked
729 ?? dir2/modified
730 ?? dir2/untracked
731 ?? expect
732 ?? output
733 ?? untracked
734 EOF
735 test_expect_success 'status -s submodule summary' '
736         git status -s >output &&
737         test_cmp expect output
738 '
739
740 cat >expect <<EOF
741 # On branch master
742 # Changed but not updated:
743 #   (use "git add <file>..." to update what will be committed)
744 #   (use "git checkout -- <file>..." to discard changes in working directory)
745 #
746 #       modified:   dir1/modified
747 #
748 # Untracked files:
749 #   (use "git add <file>..." to include in what will be committed)
750 #
751 #       dir1/untracked
752 #       dir2/modified
753 #       dir2/untracked
754 #       expect
755 #       output
756 #       untracked
757 no changes added to commit (use "git add" and/or "git commit -a")
758 EOF
759 test_expect_success 'status submodule summary (clean submodule)' '
760         git commit -m "commit submodule" &&
761         git config status.submodulesummary 10 &&
762         test_must_fail git commit --dry-run >output &&
763         test_cmp expect output &&
764         git status >output &&
765         test_cmp expect output
766 '
767
768 cat >expect <<EOF
769  M dir1/modified
770 ?? dir1/untracked
771 ?? dir2/modified
772 ?? dir2/untracked
773 ?? expect
774 ?? output
775 ?? untracked
776 EOF
777 test_expect_success 'status -s submodule summary (clean submodule)' '
778         git status -s >output &&
779         test_cmp expect output
780 '
781
782 cat >expect <<EOF
783 # On branch master
784 # Changes to be committed:
785 #   (use "git reset HEAD^1 <file>..." to unstage)
786 #
787 #       new file:   dir2/added
788 #       new file:   sm
789 #
790 # Changed but not updated:
791 #   (use "git add <file>..." to update what will be committed)
792 #   (use "git checkout -- <file>..." to discard changes in working directory)
793 #
794 #       modified:   dir1/modified
795 #
796 # Submodule changes to be committed:
797 #
798 # * sm 0000000...$head (1):
799 #   > Add foo
800 #
801 # Untracked files:
802 #   (use "git add <file>..." to include in what will be committed)
803 #
804 #       dir1/untracked
805 #       dir2/modified
806 #       dir2/untracked
807 #       expect
808 #       output
809 #       untracked
810 EOF
811 test_expect_success 'commit --dry-run submodule summary (--amend)' '
812         git config status.submodulesummary 10 &&
813         git commit --dry-run --amend >output &&
814         test_cmp expect output
815 '
816
817 test_done