Code

Merge branch 'jn/fsck-ident'
[git.git] / t / t7508-status.sh
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  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
87 '
89 cat >expect <<EOF
90 # On branch master
91 # Changes to be committed:
92 #   (use "git reset HEAD <file>..." to unstage)
93 #
94 #       new file:   dir2/added
95 #
96 # Changed but not updated:
97 #   (use "git add <file>..." to update what will be committed)
98 #   (use "git checkout -- <file>..." to discard changes in working directory)
99 #
100 #       modified:   dir1/modified
102 # Untracked files not listed (use -u option to show untracked files)
103 EOF
104 test_expect_success 'status -uno' '
105         mkdir dir3 &&
106         : >dir3/untracked1 &&
107         : >dir3/untracked2 &&
108         git status -uno >output &&
109         test_cmp expect output
112 test_expect_success 'status (status.showUntrackedFiles no)' '
113         git config status.showuntrackedfiles no
114         git status >output &&
115         test_cmp expect output
118 cat >expect << EOF
119  M dir1/modified
120 A  dir2/added
121 EOF
122 test_expect_success 'status -s -uno' '
123         git config --unset status.showuntrackedfiles
124         git status -s -uno >output &&
125         test_cmp expect output
128 test_expect_success 'status -s (status.showUntrackedFiles no)' '
129         git config status.showuntrackedfiles no
130         git status -s >output &&
131         test_cmp expect output
134 cat >expect <<EOF
135 # On branch master
136 # Changes to be committed:
137 #   (use "git reset HEAD <file>..." to unstage)
139 #       new file:   dir2/added
141 # Changed but not updated:
142 #   (use "git add <file>..." to update what will be committed)
143 #   (use "git checkout -- <file>..." to discard changes in working directory)
145 #       modified:   dir1/modified
147 # Untracked files:
148 #   (use "git add <file>..." to include in what will be committed)
150 #       dir1/untracked
151 #       dir2/modified
152 #       dir2/untracked
153 #       dir3/
154 #       expect
155 #       output
156 #       untracked
157 EOF
158 test_expect_success 'status -unormal' '
159         git status -unormal >output &&
160         test_cmp expect output
163 test_expect_success 'status (status.showUntrackedFiles normal)' '
164         git config status.showuntrackedfiles normal
165         git status >output &&
166         test_cmp expect output
169 cat >expect <<EOF
170  M dir1/modified
171 A  dir2/added
172 ?? dir1/untracked
173 ?? dir2/modified
174 ?? dir2/untracked
175 ?? dir3/
176 ?? expect
177 ?? output
178 ?? untracked
179 EOF
180 test_expect_success 'status -s -unormal' '
181         git config --unset status.showuntrackedfiles
182         git status -s -unormal >output &&
183         test_cmp expect output
186 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
187         git config status.showuntrackedfiles normal
188         git status -s >output &&
189         test_cmp expect output
192 cat >expect <<EOF
193 # On branch master
194 # Changes to be committed:
195 #   (use "git reset HEAD <file>..." to unstage)
197 #       new file:   dir2/added
199 # Changed but not updated:
200 #   (use "git add <file>..." to update what will be committed)
201 #   (use "git checkout -- <file>..." to discard changes in working directory)
203 #       modified:   dir1/modified
205 # Untracked files:
206 #   (use "git add <file>..." to include in what will be committed)
208 #       dir1/untracked
209 #       dir2/modified
210 #       dir2/untracked
211 #       dir3/untracked1
212 #       dir3/untracked2
213 #       expect
214 #       output
215 #       untracked
216 EOF
217 test_expect_success 'status -uall' '
218         git status -uall >output &&
219         test_cmp expect output
221 test_expect_success 'status (status.showUntrackedFiles all)' '
222         git config status.showuntrackedfiles all
223         git status >output &&
224         rm -rf dir3 &&
225         git config --unset status.showuntrackedfiles &&
226         test_cmp expect output
229 cat >expect <<EOF
230  M dir1/modified
231 A  dir2/added
232 ?? dir1/untracked
233 ?? dir2/modified
234 ?? dir2/untracked
235 ?? expect
236 ?? output
237 ?? untracked
238 EOF
239 test_expect_success 'status -s -uall' '
240         git config --unset status.showuntrackedfiles
241         git status -s -uall >output &&
242         test_cmp expect output
244 test_expect_success 'status -s (status.showUntrackedFiles all)' '
245         git config status.showuntrackedfiles all
246         git status -s >output &&
247         rm -rf dir3 &&
248         git config --unset status.showuntrackedfiles &&
249         test_cmp expect output
252 cat >expect <<\EOF
253 # On branch master
254 # Changes to be committed:
255 #   (use "git reset HEAD <file>..." to unstage)
257 #       new file:   ../dir2/added
259 # Changed but not updated:
260 #   (use "git add <file>..." to update what will be committed)
261 #   (use "git checkout -- <file>..." to discard changes in working directory)
263 #       modified:   modified
265 # Untracked files:
266 #   (use "git add <file>..." to include in what will be committed)
268 #       untracked
269 #       ../dir2/modified
270 #       ../dir2/untracked
271 #       ../expect
272 #       ../output
273 #       ../untracked
274 EOF
276 test_expect_success 'status with relative paths' '
278         (cd dir1 && git status) >output &&
279         test_cmp expect output
283 cat >expect <<\EOF
284  M modified
285 A  ../dir2/added
286 ?? untracked
287 ?? ../dir2/modified
288 ?? ../dir2/untracked
289 ?? ../expect
290 ?? ../output
291 ?? ../untracked
292 EOF
293 test_expect_success 'status -s with relative paths' '
295         (cd dir1 && git status -s) >output &&
296         test_cmp expect output
300 cat >expect <<\EOF
301  M dir1/modified
302 A  dir2/added
303 ?? dir1/untracked
304 ?? dir2/modified
305 ?? dir2/untracked
306 ?? expect
307 ?? output
308 ?? untracked
309 EOF
311 test_expect_success 'status --porcelain ignores relative paths setting' '
313         (cd dir1 && git status --porcelain) >output &&
314         test_cmp expect output
318 test_expect_success 'setup unique colors' '
320         git config status.color.untracked blue
324 cat >expect <<\EOF
325 # On branch master
326 # Changes to be committed:
327 #   (use "git reset HEAD <file>..." to unstage)
329 #       <GREEN>new file:   dir2/added<RESET>
331 # Changed but not updated:
332 #   (use "git add <file>..." to update what will be committed)
333 #   (use "git checkout -- <file>..." to discard changes in working directory)
335 #       <RED>modified:   dir1/modified<RESET>
337 # Untracked files:
338 #   (use "git add <file>..." to include in what will be committed)
340 #       <BLUE>dir1/untracked<RESET>
341 #       <BLUE>dir2/modified<RESET>
342 #       <BLUE>dir2/untracked<RESET>
343 #       <BLUE>expect<RESET>
344 #       <BLUE>output<RESET>
345 #       <BLUE>untracked<RESET>
346 EOF
348 test_expect_success 'status with color.ui' '
350         git config color.ui always &&
351         git status | test_decode_color >output &&
352         test_cmp expect output
356 test_expect_success 'status with color.status' '
358         git config --unset color.ui &&
359         git config color.status always &&
360         git status | test_decode_color >output &&
361         test_cmp expect output
365 cat >expect <<\EOF
366  <RED>M<RESET> dir1/modified
367 <GREEN>A<RESET>  dir2/added
368 <BLUE>??<RESET> dir1/untracked
369 <BLUE>??<RESET> dir2/modified
370 <BLUE>??<RESET> dir2/untracked
371 <BLUE>??<RESET> expect
372 <BLUE>??<RESET> output
373 <BLUE>??<RESET> untracked
374 EOF
376 test_expect_success 'status -s with color.ui' '
378         git config --unset color.status &&
379         git config color.ui always &&
380         git status -s | test_decode_color >output &&
381         test_cmp expect output
385 test_expect_success 'status -s with color.status' '
387         git config --unset color.ui &&
388         git config color.status always &&
389         git status -s | test_decode_color >output &&
390         test_cmp expect output
394 cat >expect <<\EOF
395  M dir1/modified
396 A  dir2/added
397 ?? dir1/untracked
398 ?? dir2/modified
399 ?? dir2/untracked
400 ?? expect
401 ?? output
402 ?? untracked
403 EOF
405 test_expect_success 'status --porcelain ignores color.ui' '
407         git config --unset color.status &&
408         git config color.ui always &&
409         git status --porcelain | test_decode_color >output &&
410         test_cmp expect output
414 test_expect_success 'status --porcelain ignores color.status' '
416         git config --unset color.ui &&
417         git config color.status always &&
418         git status --porcelain | test_decode_color >output &&
419         test_cmp expect output
423 # recover unconditionally from color tests
424 git config --unset color.status
425 git config --unset color.ui
427 cat >expect <<\EOF
428 # On branch master
429 # Changes to be committed:
430 #   (use "git reset HEAD <file>..." to unstage)
432 #       new file:   dir2/added
434 # Changed but not updated:
435 #   (use "git add <file>..." to update what will be committed)
436 #   (use "git checkout -- <file>..." to discard changes in working directory)
438 #       modified:   dir1/modified
440 # Untracked files:
441 #   (use "git add <file>..." to include in what will be committed)
443 #       dir1/untracked
444 #       dir2/modified
445 #       dir2/untracked
446 #       expect
447 #       output
448 #       untracked
449 EOF
452 test_expect_success 'status without relative paths' '
454         git config status.relativePaths false
455         (cd dir1 && git status) >output &&
456         test_cmp expect output
460 cat >expect <<\EOF
461  M dir1/modified
462 A  dir2/added
463 ?? dir1/untracked
464 ?? dir2/modified
465 ?? dir2/untracked
466 ?? expect
467 ?? output
468 ?? untracked
469 EOF
471 test_expect_success 'status -s without relative paths' '
473         (cd dir1 && git status -s) >output &&
474         test_cmp expect output
478 cat <<EOF >expect
479 # On branch master
480 # Changes to be committed:
481 #   (use "git reset HEAD <file>..." to unstage)
483 #       modified:   dir1/modified
485 # Untracked files:
486 #   (use "git add <file>..." to include in what will be committed)
488 #       dir1/untracked
489 #       dir2/
490 #       expect
491 #       output
492 #       untracked
493 EOF
494 test_expect_success 'dry-run of partial commit excluding new file in index' '
495         git commit --dry-run dir1/modified >output &&
496         test_cmp expect output
499 cat >expect <<EOF
500 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M      dir1/modified
501 EOF
502 test_expect_success 'status refreshes the index' '
503         touch dir2/added &&
504         git status &&
505         git diff-files >output &&
506         test_cmp expect output
509 test_expect_success 'setup status submodule summary' '
510         test_create_repo sm && (
511                 cd sm &&
512                 >foo &&
513                 git add foo &&
514                 git commit -m "Add foo"
515         ) &&
516         git add sm
519 cat >expect <<EOF
520 # On branch master
521 # Changes to be committed:
522 #   (use "git reset HEAD <file>..." to unstage)
524 #       new file:   dir2/added
525 #       new file:   sm
527 # Changed but not updated:
528 #   (use "git add <file>..." to update what will be committed)
529 #   (use "git checkout -- <file>..." to discard changes in working directory)
531 #       modified:   dir1/modified
533 # Untracked files:
534 #   (use "git add <file>..." to include in what will be committed)
536 #       dir1/untracked
537 #       dir2/modified
538 #       dir2/untracked
539 #       expect
540 #       output
541 #       untracked
542 EOF
543 test_expect_success 'status submodule summary is disabled by default' '
544         git status >output &&
545         test_cmp expect output
548 # we expect the same as the previous test
549 test_expect_success 'status --untracked-files=all does not show submodule' '
550         git status --untracked-files=all >output &&
551         test_cmp expect output
554 cat >expect <<EOF
555  M dir1/modified
556 A  dir2/added
557 A  sm
558 ?? dir1/untracked
559 ?? dir2/modified
560 ?? dir2/untracked
561 ?? expect
562 ?? output
563 ?? untracked
564 EOF
565 test_expect_success 'status -s submodule summary is disabled by default' '
566         git status -s >output &&
567         test_cmp expect output
570 # we expect the same as the previous test
571 test_expect_success 'status -s --untracked-files=all does not show submodule' '
572         git status -s --untracked-files=all >output &&
573         test_cmp expect output
576 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
578 cat >expect <<EOF
579 # On branch master
580 # Changes to be committed:
581 #   (use "git reset HEAD <file>..." to unstage)
583 #       new file:   dir2/added
584 #       new file:   sm
586 # Changed but not updated:
587 #   (use "git add <file>..." to update what will be committed)
588 #   (use "git checkout -- <file>..." to discard changes in working directory)
590 #       modified:   dir1/modified
592 # Submodule changes to be committed:
594 # * sm 0000000...$head (1):
595 #   > Add foo
597 # Untracked files:
598 #   (use "git add <file>..." to include in what will be committed)
600 #       dir1/untracked
601 #       dir2/modified
602 #       dir2/untracked
603 #       expect
604 #       output
605 #       untracked
606 EOF
607 test_expect_success 'status submodule summary' '
608         git config status.submodulesummary 10 &&
609         git status >output &&
610         test_cmp expect output
613 cat >expect <<EOF
614  M dir1/modified
615 A  dir2/added
616 A  sm
617 ?? dir1/untracked
618 ?? dir2/modified
619 ?? dir2/untracked
620 ?? expect
621 ?? output
622 ?? untracked
623 EOF
624 test_expect_success 'status -s submodule summary' '
625         git status -s >output &&
626         test_cmp expect output
629 cat >expect <<EOF
630 # On branch master
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)
635 #       modified:   dir1/modified
637 # Untracked files:
638 #   (use "git add <file>..." to include in what will be committed)
640 #       dir1/untracked
641 #       dir2/modified
642 #       dir2/untracked
643 #       expect
644 #       output
645 #       untracked
646 no changes added to commit (use "git add" and/or "git commit -a")
647 EOF
648 test_expect_success 'status submodule summary (clean submodule)' '
649         git commit -m "commit submodule" &&
650         git config status.submodulesummary 10 &&
651         test_must_fail git commit --dry-run >output &&
652         test_cmp expect output &&
653         git status >output &&
654         test_cmp expect output
657 cat >expect <<EOF
658  M dir1/modified
659 ?? dir1/untracked
660 ?? dir2/modified
661 ?? dir2/untracked
662 ?? expect
663 ?? output
664 ?? untracked
665 EOF
666 test_expect_success 'status -s submodule summary (clean submodule)' '
667         git status -s >output &&
668         test_cmp expect output
671 cat >expect <<EOF
672 # On branch master
673 # Changes to be committed:
674 #   (use "git reset HEAD^1 <file>..." to unstage)
676 #       new file:   dir2/added
677 #       new file:   sm
679 # Changed but not updated:
680 #   (use "git add <file>..." to update what will be committed)
681 #   (use "git checkout -- <file>..." to discard changes in working directory)
683 #       modified:   dir1/modified
685 # Submodule changes to be committed:
687 # * sm 0000000...$head (1):
688 #   > Add foo
690 # Untracked files:
691 #   (use "git add <file>..." to include in what will be committed)
693 #       dir1/untracked
694 #       dir2/modified
695 #       dir2/untracked
696 #       expect
697 #       output
698 #       untracked
699 EOF
700 test_expect_success 'commit --dry-run submodule summary (--amend)' '
701         git config status.submodulesummary 10 &&
702         git commit --dry-run --amend >output &&
703         test_cmp expect output
706 test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
707         (
708                 chmod a-w .git &&
709                 # make dir1/tracked stat-dirty
710                 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
711                 git status -s >output &&
712                 ! grep dir1/tracked output &&
713                 # make sure "status" succeeded without writing index out
714                 git diff-files | grep dir1/tracked
715         )
716         status=$?
717         chmod 775 .git
718         (exit $status)
721 test_done