git status --ignored: tests and docs
[git/mingw.git] / t / t7508-status.sh
blob4856f9eeeaad1d0ffbf88b9371e664edf557119f
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git status'
8 . ./test-lib.sh
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 . &&
21 git status >output &&
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
34 test_expect_success 'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
40 cat >expect <<\EOF
41 # On branch master
42 # Changes to be committed:
43 # (use "git reset HEAD <file>..." to unstage)
45 # new file: dir2/added
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)
51 # modified: dir1/modified
53 # Untracked files:
54 # (use "git add <file>..." to include in what will be committed)
56 # dir1/untracked
57 # dir2/modified
58 # dir2/untracked
59 # expect
60 # output
61 # untracked
62 EOF
64 test_expect_success 'status (2)' '
66 git status >output &&
67 test_cmp expect output
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
82 test_expect_success 'status -s (2)' '
84 git status -s >output &&
85 test_cmp expect output
89 test_expect_success 'status with gitignore' '
91 echo ".gitignore" &&
92 echo "expect" &&
93 echo "output" &&
94 echo "untracked"
95 } >.gitignore &&
97 cat >expect <<-\EOF &&
98 M dir1/modified
99 A dir2/added
100 ?? dir2/modified
102 git status -s >output &&
103 test_cmp expect output &&
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
116 git status -s --ignored >output &&
117 test_cmp expect output &&
119 cat >expect <<-\EOF &&
120 # On branch master
121 # Changes to be committed:
122 # (use "git reset HEAD <file>..." to unstage)
124 # new file: dir2/added
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)
130 # modified: dir1/modified
132 # Untracked files:
133 # (use "git add <file>..." to include in what will be committed)
135 # dir2/modified
136 # Ignored files:
137 # (use "git add -f <file>..." to include in what will be committed)
139 # .gitignore
140 # dir1/untracked
141 # dir2/untracked
142 # expect
143 # output
144 # untracked
146 git status --ignored >output &&
147 test_cmp expect output
150 test_expect_success 'status with gitignore (nothing untracked)' '
152 echo ".gitignore" &&
153 echo "expect" &&
154 echo "dir2/modified" &&
155 echo "output" &&
156 echo "untracked"
157 } >.gitignore &&
159 cat >expect <<-\EOF &&
160 M dir1/modified
161 A dir2/added
163 git status -s >output &&
164 test_cmp expect output &&
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
177 git status -s --ignored >output &&
178 test_cmp expect output &&
180 cat >expect <<-\EOF &&
181 # On branch master
182 # Changes to be committed:
183 # (use "git reset HEAD <file>..." to unstage)
185 # new file: dir2/added
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)
191 # modified: dir1/modified
193 # Ignored files:
194 # (use "git add -f <file>..." to include in what will be committed)
196 # .gitignore
197 # dir1/untracked
198 # dir2/modified
199 # dir2/untracked
200 # expect
201 # output
202 # untracked
204 git status --ignored >output &&
205 test_cmp expect output
208 rm -f .gitignore
210 cat >expect <<EOF
211 # On branch master
212 # Changes to be committed:
213 # (use "git reset HEAD <file>..." to unstage)
215 # new file: dir2/added
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)
221 # modified: dir1/modified
223 # Untracked files not listed (use -u option to show untracked files)
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
233 test_expect_success 'status (status.showUntrackedFiles no)' '
234 git config status.showuntrackedfiles no
235 git status >output &&
236 test_cmp expect output
239 cat >expect << EOF
240 M dir1/modified
241 A dir2/added
243 test_expect_success 'status -s -uno' '
244 git config --unset status.showuntrackedfiles
245 git status -s -uno >output &&
246 test_cmp expect output
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
255 cat >expect <<EOF
256 # On branch master
257 # Changes to be committed:
258 # (use "git reset HEAD <file>..." to unstage)
260 # new file: dir2/added
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)
266 # modified: dir1/modified
268 # Untracked files:
269 # (use "git add <file>..." to include in what will be committed)
271 # dir1/untracked
272 # dir2/modified
273 # dir2/untracked
274 # dir3/
275 # expect
276 # output
277 # untracked
279 test_expect_success 'status -unormal' '
280 git status -unormal >output &&
281 test_cmp expect output
284 test_expect_success 'status (status.showUntrackedFiles normal)' '
285 git config status.showuntrackedfiles normal
286 git status >output &&
287 test_cmp expect output
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
301 test_expect_success 'status -s -unormal' '
302 git config --unset status.showuntrackedfiles
303 git status -s -unormal >output &&
304 test_cmp expect output
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
313 cat >expect <<EOF
314 # On branch master
315 # Changes to be committed:
316 # (use "git reset HEAD <file>..." to unstage)
318 # new file: dir2/added
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)
324 # modified: dir1/modified
326 # Untracked files:
327 # (use "git add <file>..." to include in what will be committed)
329 # dir1/untracked
330 # dir2/modified
331 # dir2/untracked
332 # dir3/untracked1
333 # dir3/untracked2
334 # expect
335 # output
336 # untracked
338 test_expect_success 'status -uall' '
339 git status -uall >output &&
340 test_cmp expect output
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
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
360 test_expect_success 'status -s -uall' '
361 git config --unset status.showuntrackedfiles
362 git status -s -uall >output &&
363 test_cmp expect output
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
373 cat >expect <<\EOF
374 # On branch master
375 # Changes to be committed:
376 # (use "git reset HEAD <file>..." to unstage)
378 # new file: ../dir2/added
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)
384 # modified: modified
386 # Untracked files:
387 # (use "git add <file>..." to include in what will be committed)
389 # untracked
390 # ../dir2/modified
391 # ../dir2/untracked
392 # ../expect
393 # ../output
394 # ../untracked
397 test_expect_success 'status with relative paths' '
399 (cd dir1 && git status) >output &&
400 test_cmp expect output
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
414 test_expect_success 'status -s with relative paths' '
416 (cd dir1 && git status -s) >output &&
417 test_cmp expect output
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
432 test_expect_success 'status --porcelain ignores relative paths setting' '
434 (cd dir1 && git status --porcelain) >output &&
435 test_cmp expect output
439 test_expect_success 'setup unique colors' '
441 git config status.color.untracked blue
445 cat >expect <<\EOF
446 # On branch master
447 # Changes to be committed:
448 # (use "git reset HEAD <file>..." to unstage)
450 # <GREEN>new file: dir2/added<RESET>
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)
456 # <RED>modified: dir1/modified<RESET>
458 # Untracked files:
459 # (use "git add <file>..." to include in what will be committed)
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>
469 test_expect_success 'status with color.ui' '
471 git config color.ui always &&
472 git status | test_decode_color >output &&
473 test_cmp expect output
477 test_expect_success 'status with color.status' '
479 git config --unset color.ui &&
480 git config color.status always &&
481 git status | test_decode_color >output &&
482 test_cmp expect output
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
497 test_expect_success 'status -s with color.ui' '
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
506 test_expect_success 'status -s with color.status' '
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
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
526 test_expect_success 'status --porcelain ignores color.ui' '
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
535 test_expect_success 'status --porcelain ignores color.status' '
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
544 # recover unconditionally from color tests
545 git config --unset color.status
546 git config --unset color.ui
548 cat >expect <<\EOF
549 # On branch master
550 # Changes to be committed:
551 # (use "git reset HEAD <file>..." to unstage)
553 # new file: dir2/added
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)
559 # modified: dir1/modified
561 # Untracked files:
562 # (use "git add <file>..." to include in what will be committed)
564 # dir1/untracked
565 # dir2/modified
566 # dir2/untracked
567 # expect
568 # output
569 # untracked
573 test_expect_success 'status without relative paths' '
575 git config status.relativePaths false
576 (cd dir1 && git status) >output &&
577 test_cmp expect output
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
592 test_expect_success 'status -s without relative paths' '
594 (cd dir1 && git status -s) >output &&
595 test_cmp expect output
599 cat <<EOF >expect
600 # On branch master
601 # Changes to be committed:
602 # (use "git reset HEAD <file>..." to unstage)
604 # modified: dir1/modified
606 # Untracked files:
607 # (use "git add <file>..." to include in what will be committed)
609 # dir1/untracked
610 # dir2/
611 # expect
612 # output
613 # untracked
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
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
630 cat >expect <<EOF
631 # On branch master
632 # Changes to be committed:
633 # (use "git reset HEAD <file>..." to unstage)
635 # new file: dir2/added
636 # new file: sm
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)
642 # modified: dir1/modified
644 # Untracked files:
645 # (use "git add <file>..." to include in what will be committed)
647 # dir1/untracked
648 # dir2/modified
649 # dir2/untracked
650 # expect
651 # output
652 # untracked
654 test_expect_success 'status submodule summary is disabled by default' '
655 git status >output &&
656 test_cmp expect output
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
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
676 test_expect_success 'status -s submodule summary is disabled by default' '
677 git status -s >output &&
678 test_cmp expect output
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
687 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
689 cat >expect <<EOF
690 # On branch master
691 # Changes to be committed:
692 # (use "git reset HEAD <file>..." to unstage)
694 # new file: dir2/added
695 # new file: sm
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)
701 # modified: dir1/modified
703 # Submodule changes to be committed:
705 # * sm 0000000...$head (1):
706 # > Add foo
708 # Untracked files:
709 # (use "git add <file>..." to include in what will be committed)
711 # dir1/untracked
712 # dir2/modified
713 # dir2/untracked
714 # expect
715 # output
716 # untracked
718 test_expect_success 'status submodule summary' '
719 git config status.submodulesummary 10 &&
720 git status >output &&
721 test_cmp expect output
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
735 test_expect_success 'status -s submodule summary' '
736 git status -s >output &&
737 test_cmp expect output
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)
746 # modified: dir1/modified
748 # Untracked files:
749 # (use "git add <file>..." to include in what will be committed)
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")
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
768 cat >expect <<EOF
769 M dir1/modified
770 ?? dir1/untracked
771 ?? dir2/modified
772 ?? dir2/untracked
773 ?? expect
774 ?? output
775 ?? untracked
777 test_expect_success 'status -s submodule summary (clean submodule)' '
778 git status -s >output &&
779 test_cmp expect output
782 cat >expect <<EOF
783 # On branch master
784 # Changes to be committed:
785 # (use "git reset HEAD^1 <file>..." to unstage)
787 # new file: dir2/added
788 # new file: sm
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)
794 # modified: dir1/modified
796 # Submodule changes to be committed:
798 # * sm 0000000...$head (1):
799 # > Add foo
801 # Untracked files:
802 # (use "git add <file>..." to include in what will be committed)
804 # dir1/untracked
805 # dir2/modified
806 # dir2/untracked
807 # expect
808 # output
809 # untracked
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
817 test_done