1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
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
32 '
34 test_expect_success 'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
38 '
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
64 test_expect_success 'status (2)' '
66 git status >output &&
67 test_cmp expect output
69 '
71 cat >expect <<\EOF
72 # On branch master
73 # Changes to be committed:
74 # new file: dir2/added
75 #
76 # Changed but not updated:
77 # modified: dir1/modified
78 #
79 # Untracked files:
80 # dir1/untracked
81 # dir2/modified
82 # dir2/untracked
83 # expect
84 # output
85 # untracked
86 EOF
88 git config advice.statusHints false
90 test_expect_success 'status (advice.statusHints false)' '
92 git status >output &&
93 test_cmp expect output
95 '
97 git config --unset advice.statusHints
99 cat >expect <<\EOF
100 M dir1/modified
101 A dir2/added
102 ?? dir1/untracked
103 ?? dir2/modified
104 ?? dir2/untracked
105 ?? expect
106 ?? output
107 ?? untracked
108 EOF
110 test_expect_success 'status -s (2)' '
112 git status -s >output &&
113 test_cmp expect output
115 '
117 cat >expect <<EOF
118 # On branch master
119 # Changes to be committed:
120 # (use "git reset HEAD <file>..." to unstage)
121 #
122 # new file: dir2/added
123 #
124 # Changed but not updated:
125 # (use "git add <file>..." to update what will be committed)
126 # (use "git checkout -- <file>..." to discard changes in working directory)
127 #
128 # modified: dir1/modified
129 #
130 # Untracked files not listed (use -u option to show untracked files)
131 EOF
132 test_expect_success 'status -uno' '
133 mkdir dir3 &&
134 : >dir3/untracked1 &&
135 : >dir3/untracked2 &&
136 git status -uno >output &&
137 test_cmp expect output
138 '
140 test_expect_success 'status (status.showUntrackedFiles no)' '
141 git config status.showuntrackedfiles no
142 git status >output &&
143 test_cmp expect output
144 '
146 cat >expect <<EOF
147 # On branch master
148 # Changes to be committed:
149 # new file: dir2/added
150 #
151 # Changed but not updated:
152 # modified: dir1/modified
153 #
154 # Untracked files not listed
155 EOF
156 git config advice.statusHints false
157 test_expect_success 'status -uno (advice.statusHints false)' '
158 git status -uno >output &&
159 test_cmp expect output
160 '
161 git config --unset advice.statusHints
163 cat >expect << EOF
164 M dir1/modified
165 A dir2/added
166 EOF
167 test_expect_success 'status -s -uno' '
168 git config --unset status.showuntrackedfiles
169 git status -s -uno >output &&
170 test_cmp expect output
171 '
173 test_expect_success 'status -s (status.showUntrackedFiles no)' '
174 git config status.showuntrackedfiles no
175 git status -s >output &&
176 test_cmp expect output
177 '
179 cat >expect <<EOF
180 # On branch master
181 # Changes to be committed:
182 # (use "git reset HEAD <file>..." to unstage)
183 #
184 # new file: dir2/added
185 #
186 # Changed but not updated:
187 # (use "git add <file>..." to update what will be committed)
188 # (use "git checkout -- <file>..." to discard changes in working directory)
189 #
190 # modified: dir1/modified
191 #
192 # Untracked files:
193 # (use "git add <file>..." to include in what will be committed)
194 #
195 # dir1/untracked
196 # dir2/modified
197 # dir2/untracked
198 # dir3/
199 # expect
200 # output
201 # untracked
202 EOF
203 test_expect_success 'status -unormal' '
204 git status -unormal >output &&
205 test_cmp expect output
206 '
208 test_expect_success 'status (status.showUntrackedFiles normal)' '
209 git config status.showuntrackedfiles normal
210 git status >output &&
211 test_cmp expect output
212 '
214 cat >expect <<EOF
215 M dir1/modified
216 A dir2/added
217 ?? dir1/untracked
218 ?? dir2/modified
219 ?? dir2/untracked
220 ?? dir3/
221 ?? expect
222 ?? output
223 ?? untracked
224 EOF
225 test_expect_success 'status -s -unormal' '
226 git config --unset status.showuntrackedfiles
227 git status -s -unormal >output &&
228 test_cmp expect output
229 '
231 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
232 git config status.showuntrackedfiles normal
233 git status -s >output &&
234 test_cmp expect output
235 '
237 cat >expect <<EOF
238 # On branch master
239 # Changes to be committed:
240 # (use "git reset HEAD <file>..." to unstage)
241 #
242 # new file: dir2/added
243 #
244 # Changed but not updated:
245 # (use "git add <file>..." to update what will be committed)
246 # (use "git checkout -- <file>..." to discard changes in working directory)
247 #
248 # modified: dir1/modified
249 #
250 # Untracked files:
251 # (use "git add <file>..." to include in what will be committed)
252 #
253 # dir1/untracked
254 # dir2/modified
255 # dir2/untracked
256 # dir3/untracked1
257 # dir3/untracked2
258 # expect
259 # output
260 # untracked
261 EOF
262 test_expect_success 'status -uall' '
263 git status -uall >output &&
264 test_cmp expect output
265 '
266 test_expect_success 'status (status.showUntrackedFiles all)' '
267 git config status.showuntrackedfiles all
268 git status >output &&
269 rm -rf dir3 &&
270 git config --unset status.showuntrackedfiles &&
271 test_cmp expect output
272 '
274 cat >expect <<EOF
275 M dir1/modified
276 A dir2/added
277 ?? dir1/untracked
278 ?? dir2/modified
279 ?? dir2/untracked
280 ?? expect
281 ?? output
282 ?? untracked
283 EOF
284 test_expect_success 'status -s -uall' '
285 git config --unset status.showuntrackedfiles
286 git status -s -uall >output &&
287 test_cmp expect output
288 '
289 test_expect_success 'status -s (status.showUntrackedFiles all)' '
290 git config status.showuntrackedfiles all
291 git status -s >output &&
292 rm -rf dir3 &&
293 git config --unset status.showuntrackedfiles &&
294 test_cmp expect output
295 '
297 cat >expect <<\EOF
298 # On branch master
299 # Changes to be committed:
300 # (use "git reset HEAD <file>..." to unstage)
301 #
302 # new file: ../dir2/added
303 #
304 # Changed but not updated:
305 # (use "git add <file>..." to update what will be committed)
306 # (use "git checkout -- <file>..." to discard changes in working directory)
307 #
308 # modified: modified
309 #
310 # Untracked files:
311 # (use "git add <file>..." to include in what will be committed)
312 #
313 # untracked
314 # ../dir2/modified
315 # ../dir2/untracked
316 # ../expect
317 # ../output
318 # ../untracked
319 EOF
321 test_expect_success 'status with relative paths' '
323 (cd dir1 && git status) >output &&
324 test_cmp expect output
326 '
328 cat >expect <<\EOF
329 M modified
330 A ../dir2/added
331 ?? untracked
332 ?? ../dir2/modified
333 ?? ../dir2/untracked
334 ?? ../expect
335 ?? ../output
336 ?? ../untracked
337 EOF
338 test_expect_success 'status -s with relative paths' '
340 (cd dir1 && git status -s) >output &&
341 test_cmp expect output
343 '
345 cat >expect <<\EOF
346 M dir1/modified
347 A dir2/added
348 ?? dir1/untracked
349 ?? dir2/modified
350 ?? dir2/untracked
351 ?? expect
352 ?? output
353 ?? untracked
354 EOF
356 test_expect_success 'status --porcelain ignores relative paths setting' '
358 (cd dir1 && git status --porcelain) >output &&
359 test_cmp expect output
361 '
363 test_expect_success 'setup unique colors' '
365 git config status.color.untracked blue
367 '
369 cat >expect <<\EOF
370 # On branch master
371 # Changes to be committed:
372 # (use "git reset HEAD <file>..." to unstage)
373 #
374 # <GREEN>new file: dir2/added<RESET>
375 #
376 # Changed but not updated:
377 # (use "git add <file>..." to update what will be committed)
378 # (use "git checkout -- <file>..." to discard changes in working directory)
379 #
380 # <RED>modified: dir1/modified<RESET>
381 #
382 # Untracked files:
383 # (use "git add <file>..." to include in what will be committed)
384 #
385 # <BLUE>dir1/untracked<RESET>
386 # <BLUE>dir2/modified<RESET>
387 # <BLUE>dir2/untracked<RESET>
388 # <BLUE>expect<RESET>
389 # <BLUE>output<RESET>
390 # <BLUE>untracked<RESET>
391 EOF
393 test_expect_success 'status with color.ui' '
395 git config color.ui always &&
396 git status | test_decode_color >output &&
397 test_cmp expect output
399 '
401 test_expect_success 'status with color.status' '
403 git config --unset color.ui &&
404 git config color.status always &&
405 git status | test_decode_color >output &&
406 test_cmp expect output
408 '
410 cat >expect <<\EOF
411 <RED>M<RESET> dir1/modified
412 <GREEN>A<RESET> dir2/added
413 <BLUE>??<RESET> dir1/untracked
414 <BLUE>??<RESET> dir2/modified
415 <BLUE>??<RESET> dir2/untracked
416 <BLUE>??<RESET> expect
417 <BLUE>??<RESET> output
418 <BLUE>??<RESET> untracked
419 EOF
421 test_expect_success 'status -s with color.ui' '
423 git config --unset color.status &&
424 git config color.ui always &&
425 git status -s | test_decode_color >output &&
426 test_cmp expect output
428 '
430 test_expect_success 'status -s with color.status' '
432 git config --unset color.ui &&
433 git config color.status always &&
434 git status -s | test_decode_color >output &&
435 test_cmp expect output
437 '
439 cat >expect <<\EOF
440 M dir1/modified
441 A dir2/added
442 ?? dir1/untracked
443 ?? dir2/modified
444 ?? dir2/untracked
445 ?? expect
446 ?? output
447 ?? untracked
448 EOF
450 test_expect_success 'status --porcelain ignores color.ui' '
452 git config --unset color.status &&
453 git config color.ui always &&
454 git status --porcelain | test_decode_color >output &&
455 test_cmp expect output
457 '
459 test_expect_success 'status --porcelain ignores color.status' '
461 git config --unset color.ui &&
462 git config color.status always &&
463 git status --porcelain | test_decode_color >output &&
464 test_cmp expect output
466 '
468 # recover unconditionally from color tests
469 git config --unset color.status
470 git config --unset color.ui
472 cat >expect <<\EOF
473 # On branch master
474 # Changes to be committed:
475 # (use "git reset HEAD <file>..." to unstage)
476 #
477 # new file: dir2/added
478 #
479 # Changed but not updated:
480 # (use "git add <file>..." to update what will be committed)
481 # (use "git checkout -- <file>..." to discard changes in working directory)
482 #
483 # modified: dir1/modified
484 #
485 # Untracked files:
486 # (use "git add <file>..." to include in what will be committed)
487 #
488 # dir1/untracked
489 # dir2/modified
490 # dir2/untracked
491 # expect
492 # output
493 # untracked
494 EOF
497 test_expect_success 'status without relative paths' '
499 git config status.relativePaths false
500 (cd dir1 && git status) >output &&
501 test_cmp expect output
503 '
505 cat >expect <<\EOF
506 M dir1/modified
507 A dir2/added
508 ?? dir1/untracked
509 ?? dir2/modified
510 ?? dir2/untracked
511 ?? expect
512 ?? output
513 ?? untracked
514 EOF
516 test_expect_success 'status -s without relative paths' '
518 (cd dir1 && git status -s) >output &&
519 test_cmp expect output
521 '
523 cat <<EOF >expect
524 # On branch master
525 # Changes to be committed:
526 # (use "git reset HEAD <file>..." to unstage)
527 #
528 # modified: dir1/modified
529 #
530 # Untracked files:
531 # (use "git add <file>..." to include in what will be committed)
532 #
533 # dir1/untracked
534 # dir2/
535 # expect
536 # output
537 # untracked
538 EOF
539 test_expect_success 'dry-run of partial commit excluding new file in index' '
540 git commit --dry-run dir1/modified >output &&
541 test_cmp expect output
542 '
544 cat >expect <<EOF
545 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
546 EOF
547 test_expect_success 'status refreshes the index' '
548 touch dir2/added &&
549 git status &&
550 git diff-files >output &&
551 test_cmp expect output
552 '
554 test_expect_success 'setup status submodule summary' '
555 test_create_repo sm && (
556 cd sm &&
557 >foo &&
558 git add foo &&
559 git commit -m "Add foo"
560 ) &&
561 git add sm
562 '
564 cat >expect <<EOF
565 # On branch master
566 # Changes to be committed:
567 # (use "git reset HEAD <file>..." to unstage)
568 #
569 # new file: dir2/added
570 # new file: sm
571 #
572 # Changed but not updated:
573 # (use "git add <file>..." to update what will be committed)
574 # (use "git checkout -- <file>..." to discard changes in working directory)
575 #
576 # modified: dir1/modified
577 #
578 # Untracked files:
579 # (use "git add <file>..." to include in what will be committed)
580 #
581 # dir1/untracked
582 # dir2/modified
583 # dir2/untracked
584 # expect
585 # output
586 # untracked
587 EOF
588 test_expect_success 'status submodule summary is disabled by default' '
589 git status >output &&
590 test_cmp expect output
591 '
593 # we expect the same as the previous test
594 test_expect_success 'status --untracked-files=all does not show submodule' '
595 git status --untracked-files=all >output &&
596 test_cmp expect output
597 '
599 cat >expect <<EOF
600 M dir1/modified
601 A dir2/added
602 A sm
603 ?? dir1/untracked
604 ?? dir2/modified
605 ?? dir2/untracked
606 ?? expect
607 ?? output
608 ?? untracked
609 EOF
610 test_expect_success 'status -s submodule summary is disabled by default' '
611 git status -s >output &&
612 test_cmp expect output
613 '
615 # we expect the same as the previous test
616 test_expect_success 'status -s --untracked-files=all does not show submodule' '
617 git status -s --untracked-files=all >output &&
618 test_cmp expect output
619 '
621 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
623 cat >expect <<EOF
624 # On branch master
625 # Changes to be committed:
626 # (use "git reset HEAD <file>..." to unstage)
627 #
628 # new file: dir2/added
629 # new file: sm
630 #
631 # Changed but not updated:
632 # (use "git add <file>..." to update what will be committed)
633 # (use "git checkout -- <file>..." to discard changes in working directory)
634 #
635 # modified: dir1/modified
636 #
637 # Submodule changes to be committed:
638 #
639 # * sm 0000000...$head (1):
640 # > Add foo
641 #
642 # Untracked files:
643 # (use "git add <file>..." to include in what will be committed)
644 #
645 # dir1/untracked
646 # dir2/modified
647 # dir2/untracked
648 # expect
649 # output
650 # untracked
651 EOF
652 test_expect_success 'status submodule summary' '
653 git config status.submodulesummary 10 &&
654 git status >output &&
655 test_cmp expect output
656 '
658 cat >expect <<EOF
659 M dir1/modified
660 A dir2/added
661 A sm
662 ?? dir1/untracked
663 ?? dir2/modified
664 ?? dir2/untracked
665 ?? expect
666 ?? output
667 ?? untracked
668 EOF
669 test_expect_success 'status -s submodule summary' '
670 git status -s >output &&
671 test_cmp expect output
672 '
674 cat >expect <<EOF
675 # On branch master
676 # Changed but not updated:
677 # (use "git add <file>..." to update what will be committed)
678 # (use "git checkout -- <file>..." to discard changes in working directory)
679 #
680 # modified: dir1/modified
681 #
682 # Untracked files:
683 # (use "git add <file>..." to include in what will be committed)
684 #
685 # dir1/untracked
686 # dir2/modified
687 # dir2/untracked
688 # expect
689 # output
690 # untracked
691 no changes added to commit (use "git add" and/or "git commit -a")
692 EOF
693 test_expect_success 'status submodule summary (clean submodule)' '
694 git commit -m "commit submodule" &&
695 git config status.submodulesummary 10 &&
696 test_must_fail git commit --dry-run >output &&
697 test_cmp expect output &&
698 git status >output &&
699 test_cmp expect output
700 '
702 cat >expect <<EOF
703 M dir1/modified
704 ?? dir1/untracked
705 ?? dir2/modified
706 ?? dir2/untracked
707 ?? expect
708 ?? output
709 ?? untracked
710 EOF
711 test_expect_success 'status -s submodule summary (clean submodule)' '
712 git status -s >output &&
713 test_cmp expect output
714 '
716 cat >expect <<EOF
717 # On branch master
718 # Changes to be committed:
719 # (use "git reset HEAD^1 <file>..." to unstage)
720 #
721 # new file: dir2/added
722 # new file: sm
723 #
724 # Changed but not updated:
725 # (use "git add <file>..." to update what will be committed)
726 # (use "git checkout -- <file>..." to discard changes in working directory)
727 #
728 # modified: dir1/modified
729 #
730 # Submodule changes to be committed:
731 #
732 # * sm 0000000...$head (1):
733 # > Add foo
734 #
735 # Untracked files:
736 # (use "git add <file>..." to include in what will be committed)
737 #
738 # dir1/untracked
739 # dir2/modified
740 # dir2/untracked
741 # expect
742 # output
743 # untracked
744 EOF
745 test_expect_success 'commit --dry-run submodule summary (--amend)' '
746 git config status.submodulesummary 10 &&
747 git commit --dry-run --amend >output &&
748 test_cmp expect output
749 '
751 test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
752 (
753 chmod a-w .git &&
754 # make dir1/tracked stat-dirty
755 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
756 git status -s >output &&
757 ! grep dir1/tracked output &&
758 # make sure "status" succeeded without writing index out
759 git diff-files | grep dir1/tracked
760 )
761 status=$?
762 chmod 775 .git
763 (exit $status)
764 '
766 test_done