Merge branch 'master' of git://repo.or.cz/alt-git
[git/dscho.git] / t / t7508-status.sh
blob7c7b50b0cb13eb0184f876294d0986567981a4bb
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git status'
8 case $(uname -s) in
9 *MINGW*) GIT_TEST_CMP="diff -uw";;
10 esac
12 . ./test-lib.sh
14 test_expect_success 'setup' '
15 : >tracked &&
16 : >modified &&
17 mkdir dir1 &&
18 : >dir1/tracked &&
19 : >dir1/modified &&
20 mkdir dir2 &&
21 : >dir1/tracked &&
22 : >dir1/modified &&
23 git add . &&
25 git status >output &&
27 test_tick &&
28 git commit -m initial &&
29 : >untracked &&
30 : >dir1/untracked &&
31 : >dir2/untracked &&
32 echo 1 >dir1/modified &&
33 echo 2 >dir2/modified &&
34 echo 3 >dir2/added &&
35 git add dir2/added
38 test_expect_success 'status (1)' '
40 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
44 cat >expect <<\EOF
45 # On branch master
46 # Changes to be committed:
47 # (use "git reset HEAD <file>..." to unstage)
49 # new file: dir2/added
51 # Changed but not updated:
52 # (use "git add <file>..." to update what will be committed)
53 # (use "git checkout -- <file>..." to discard changes in working directory)
55 # modified: dir1/modified
57 # Untracked files:
58 # (use "git add <file>..." to include in what will be committed)
60 # dir1/untracked
61 # dir2/modified
62 # dir2/untracked
63 # expect
64 # output
65 # untracked
66 EOF
68 test_expect_success 'status (2)' '
70 git status >output &&
71 test_cmp expect output
75 cat >expect <<\EOF
76 M dir1/modified
77 A dir2/added
78 ?? dir1/untracked
79 ?? dir2/modified
80 ?? dir2/untracked
81 ?? expect
82 ?? output
83 ?? untracked
84 EOF
86 test_expect_success 'status -s (2)' '
88 git status -s >output &&
89 test_cmp expect output
93 cat >expect <<EOF
94 # On branch master
95 # Changes to be committed:
96 # (use "git reset HEAD <file>..." to unstage)
98 # new file: dir2/added
100 # Changed but not updated:
101 # (use "git add <file>..." to update what will be committed)
102 # (use "git checkout -- <file>..." to discard changes in working directory)
104 # modified: dir1/modified
106 # Untracked files not listed (use -u option to show untracked files)
108 test_expect_success 'status -uno' '
109 mkdir dir3 &&
110 : >dir3/untracked1 &&
111 : >dir3/untracked2 &&
112 git status -uno >output &&
113 test_cmp expect output
116 test_expect_success 'status (status.showUntrackedFiles no)' '
117 git config status.showuntrackedfiles no
118 git status >output &&
119 test_cmp expect output
122 cat >expect << EOF
123 M dir1/modified
124 A dir2/added
126 test_expect_success 'status -s -uno' '
127 git config --unset status.showuntrackedfiles
128 git status -s -uno >output &&
129 test_cmp expect output
132 test_expect_success 'status -s (status.showUntrackedFiles no)' '
133 git config status.showuntrackedfiles no
134 git status -s >output &&
135 test_cmp expect output
138 cat >expect <<EOF
139 # On branch master
140 # Changes to be committed:
141 # (use "git reset HEAD <file>..." to unstage)
143 # new file: dir2/added
145 # Changed but not updated:
146 # (use "git add <file>..." to update what will be committed)
147 # (use "git checkout -- <file>..." to discard changes in working directory)
149 # modified: dir1/modified
151 # Untracked files:
152 # (use "git add <file>..." to include in what will be committed)
154 # dir1/untracked
155 # dir2/modified
156 # dir2/untracked
157 # dir3/
158 # expect
159 # output
160 # untracked
162 test_expect_success 'status -unormal' '
163 git status -unormal >output &&
164 test_cmp expect output
167 test_expect_success 'status (status.showUntrackedFiles normal)' '
168 git config status.showuntrackedfiles normal
169 git status >output &&
170 test_cmp expect output
173 cat >expect <<EOF
174 M dir1/modified
175 A dir2/added
176 ?? dir1/untracked
177 ?? dir2/modified
178 ?? dir2/untracked
179 ?? dir3/
180 ?? expect
181 ?? output
182 ?? untracked
184 test_expect_success 'status -s -unormal' '
185 git config --unset status.showuntrackedfiles
186 git status -s -unormal >output &&
187 test_cmp expect output
190 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
191 git config status.showuntrackedfiles normal
192 git status -s >output &&
193 test_cmp expect output
196 cat >expect <<EOF
197 # On branch master
198 # Changes to be committed:
199 # (use "git reset HEAD <file>..." to unstage)
201 # new file: dir2/added
203 # Changed but not updated:
204 # (use "git add <file>..." to update what will be committed)
205 # (use "git checkout -- <file>..." to discard changes in working directory)
207 # modified: dir1/modified
209 # Untracked files:
210 # (use "git add <file>..." to include in what will be committed)
212 # dir1/untracked
213 # dir2/modified
214 # dir2/untracked
215 # dir3/untracked1
216 # dir3/untracked2
217 # expect
218 # output
219 # untracked
221 test_expect_success 'status -uall' '
222 git status -uall >output &&
223 test_cmp expect output
225 test_expect_success 'status (status.showUntrackedFiles all)' '
226 git config status.showuntrackedfiles all
227 git status >output &&
228 rm -rf dir3 &&
229 git config --unset status.showuntrackedfiles &&
230 test_cmp expect output
233 cat >expect <<EOF
234 M dir1/modified
235 A dir2/added
236 ?? dir1/untracked
237 ?? dir2/modified
238 ?? dir2/untracked
239 ?? expect
240 ?? output
241 ?? untracked
243 test_expect_success 'status -s -uall' '
244 git config --unset status.showuntrackedfiles
245 git status -s -uall >output &&
246 test_cmp expect output
248 test_expect_success 'status -s (status.showUntrackedFiles all)' '
249 git config status.showuntrackedfiles all
250 git status -s >output &&
251 rm -rf dir3 &&
252 git config --unset status.showuntrackedfiles &&
253 test_cmp expect output
256 cat >expect <<\EOF
257 # On branch master
258 # Changes to be committed:
259 # (use "git reset HEAD <file>..." to unstage)
261 # new file: ../dir2/added
263 # Changed but not updated:
264 # (use "git add <file>..." to update what will be committed)
265 # (use "git checkout -- <file>..." to discard changes in working directory)
267 # modified: modified
269 # Untracked files:
270 # (use "git add <file>..." to include in what will be committed)
272 # untracked
273 # ../dir2/modified
274 # ../dir2/untracked
275 # ../expect
276 # ../output
277 # ../untracked
280 test_expect_success 'status with relative paths' '
282 (cd dir1 && git status) >output &&
283 test_cmp expect output
287 cat >expect <<\EOF
288 M modified
289 A ../dir2/added
290 ?? untracked
291 ?? ../dir2/modified
292 ?? ../dir2/untracked
293 ?? ../expect
294 ?? ../output
295 ?? ../untracked
297 test_expect_success 'status -s with relative paths' '
299 (cd dir1 && git status -s) >output &&
300 test_cmp expect output
304 cat >expect <<\EOF
305 M dir1/modified
306 A dir2/added
307 ?? dir1/untracked
308 ?? dir2/modified
309 ?? dir2/untracked
310 ?? expect
311 ?? output
312 ?? untracked
315 test_expect_success 'status --porcelain ignores relative paths setting' '
317 (cd dir1 && git status --porcelain) >output &&
318 test_cmp expect output
322 test_expect_success 'setup unique colors' '
324 git config status.color.untracked blue
328 cat >expect <<\EOF
329 # On branch master
330 # Changes to be committed:
331 # (use "git reset HEAD <file>..." to unstage)
333 # <GREEN>new file: dir2/added<RESET>
335 # Changed but not updated:
336 # (use "git add <file>..." to update what will be committed)
337 # (use "git checkout -- <file>..." to discard changes in working directory)
339 # <RED>modified: dir1/modified<RESET>
341 # Untracked files:
342 # (use "git add <file>..." to include in what will be committed)
344 # <BLUE>dir1/untracked<RESET>
345 # <BLUE>dir2/modified<RESET>
346 # <BLUE>dir2/untracked<RESET>
347 # <BLUE>expect<RESET>
348 # <BLUE>output<RESET>
349 # <BLUE>untracked<RESET>
352 test_expect_success 'status with color.ui' '
354 git config color.ui always &&
355 git status | test_decode_color >output &&
356 test_cmp expect output
360 test_expect_success 'status with color.status' '
362 git config --unset color.ui &&
363 git config color.status always &&
364 git status | test_decode_color >output &&
365 test_cmp expect output
369 cat >expect <<\EOF
370 <RED>M<RESET> dir1/modified
371 <GREEN>A<RESET> dir2/added
372 <BLUE>??<RESET> dir1/untracked
373 <BLUE>??<RESET> dir2/modified
374 <BLUE>??<RESET> dir2/untracked
375 <BLUE>??<RESET> expect
376 <BLUE>??<RESET> output
377 <BLUE>??<RESET> untracked
380 test_expect_success 'status -s with color.ui' '
382 git config --unset color.status &&
383 git config color.ui always &&
384 git status -s | test_decode_color >output &&
385 test_cmp expect output
389 test_expect_success 'status -s with color.status' '
391 git config --unset color.ui &&
392 git config color.status always &&
393 git status -s | test_decode_color >output &&
394 test_cmp expect output
398 cat >expect <<\EOF
399 M dir1/modified
400 A dir2/added
401 ?? dir1/untracked
402 ?? dir2/modified
403 ?? dir2/untracked
404 ?? expect
405 ?? output
406 ?? untracked
409 test_expect_success 'status --porcelain ignores color.ui' '
411 git config --unset color.status &&
412 git config color.ui always &&
413 git status --porcelain | test_decode_color >output &&
414 test_cmp expect output
418 test_expect_success 'status --porcelain ignores color.status' '
420 git config --unset color.ui &&
421 git config color.status always &&
422 git status --porcelain | test_decode_color >output &&
423 test_cmp expect output
427 # recover unconditionally from color tests
428 git config --unset color.status
429 git config --unset color.ui
431 cat >expect <<\EOF
432 # On branch master
433 # Changes to be committed:
434 # (use "git reset HEAD <file>..." to unstage)
436 # new file: dir2/added
438 # Changed but not updated:
439 # (use "git add <file>..." to update what will be committed)
440 # (use "git checkout -- <file>..." to discard changes in working directory)
442 # modified: dir1/modified
444 # Untracked files:
445 # (use "git add <file>..." to include in what will be committed)
447 # dir1/untracked
448 # dir2/modified
449 # dir2/untracked
450 # expect
451 # output
452 # untracked
456 test_expect_success 'status without relative paths' '
458 git config status.relativePaths false
459 (cd dir1 && git status) >output &&
460 test_cmp expect output
464 cat >expect <<\EOF
465 M dir1/modified
466 A dir2/added
467 ?? dir1/untracked
468 ?? dir2/modified
469 ?? dir2/untracked
470 ?? expect
471 ?? output
472 ?? untracked
475 test_expect_success 'status -s without relative paths' '
477 (cd dir1 && git status -s) >output &&
478 test_cmp expect output
482 cat <<EOF >expect
483 # On branch master
484 # Changes to be committed:
485 # (use "git reset HEAD <file>..." to unstage)
487 # modified: dir1/modified
489 # Untracked files:
490 # (use "git add <file>..." to include in what will be committed)
492 # dir1/untracked
493 # dir2/
494 # expect
495 # output
496 # untracked
498 test_expect_success 'dry-run of partial commit excluding new file in index' '
499 git commit --dry-run dir1/modified >output &&
500 test_cmp expect output
503 test_expect_success 'setup status submodule summary' '
504 test_create_repo sm && (
505 cd sm &&
506 >foo &&
507 git add foo &&
508 git commit -m "Add foo"
509 ) &&
510 git add sm
513 cat >expect <<EOF
514 # On branch master
515 # Changes to be committed:
516 # (use "git reset HEAD <file>..." to unstage)
518 # new file: dir2/added
519 # new file: sm
521 # Changed but not updated:
522 # (use "git add <file>..." to update what will be committed)
523 # (use "git checkout -- <file>..." to discard changes in working directory)
525 # modified: dir1/modified
527 # Untracked files:
528 # (use "git add <file>..." to include in what will be committed)
530 # dir1/untracked
531 # dir2/modified
532 # dir2/untracked
533 # expect
534 # output
535 # untracked
537 test_expect_success 'status submodule summary is disabled by default' '
538 git status >output &&
539 test_cmp expect output
542 # we expect the same as the previous test
543 test_expect_success 'status --untracked-files=all does not show submodule' '
544 git status --untracked-files=all >output &&
545 test_cmp expect output
548 cat >expect <<EOF
549 M dir1/modified
550 A dir2/added
551 A sm
552 ?? dir1/untracked
553 ?? dir2/modified
554 ?? dir2/untracked
555 ?? expect
556 ?? output
557 ?? untracked
559 test_expect_success 'status -s submodule summary is disabled by default' '
560 git status -s >output &&
561 test_cmp expect output
564 # we expect the same as the previous test
565 test_expect_success 'status -s --untracked-files=all does not show submodule' '
566 git status -s --untracked-files=all >output &&
567 test_cmp expect output
570 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
572 cat >expect <<EOF
573 # On branch master
574 # Changes to be committed:
575 # (use "git reset HEAD <file>..." to unstage)
577 # new file: dir2/added
578 # new file: sm
580 # Changed but not updated:
581 # (use "git add <file>..." to update what will be committed)
582 # (use "git checkout -- <file>..." to discard changes in working directory)
584 # modified: dir1/modified
586 # Submodule changes to be committed:
588 # * sm 0000000...$head (1):
589 # > Add foo
591 # Untracked files:
592 # (use "git add <file>..." to include in what will be committed)
594 # dir1/untracked
595 # dir2/modified
596 # dir2/untracked
597 # expect
598 # output
599 # untracked
601 test_expect_success 'status submodule summary' '
602 git config status.submodulesummary 10 &&
603 git status >output &&
604 test_cmp expect output
607 cat >expect <<EOF
608 M dir1/modified
609 A dir2/added
610 A sm
611 ?? dir1/untracked
612 ?? dir2/modified
613 ?? dir2/untracked
614 ?? expect
615 ?? output
616 ?? untracked
618 test_expect_success 'status -s submodule summary' '
619 git status -s >output &&
620 test_cmp expect output
623 cat >expect <<EOF
624 # On branch master
625 # Changed but not updated:
626 # (use "git add <file>..." to update what will be committed)
627 # (use "git checkout -- <file>..." to discard changes in working directory)
629 # modified: dir1/modified
631 # Untracked files:
632 # (use "git add <file>..." to include in what will be committed)
634 # dir1/untracked
635 # dir2/modified
636 # dir2/untracked
637 # expect
638 # output
639 # untracked
640 no changes added to commit (use "git add" and/or "git commit -a")
642 test_expect_success 'status submodule summary (clean submodule)' '
643 git commit -m "commit submodule" &&
644 git config status.submodulesummary 10 &&
645 test_must_fail git commit --dry-run >output &&
646 test_cmp expect output &&
647 git status >output &&
648 test_cmp expect output
651 cat >expect <<EOF
652 M dir1/modified
653 ?? dir1/untracked
654 ?? dir2/modified
655 ?? dir2/untracked
656 ?? expect
657 ?? output
658 ?? untracked
660 test_expect_success 'status -s submodule summary (clean submodule)' '
661 git status -s >output &&
662 test_cmp expect output
665 cat >expect <<EOF
666 # On branch master
667 # Changes to be committed:
668 # (use "git reset HEAD^1 <file>..." to unstage)
670 # new file: dir2/added
671 # new file: sm
673 # Changed but not updated:
674 # (use "git add <file>..." to update what will be committed)
675 # (use "git checkout -- <file>..." to discard changes in working directory)
677 # modified: dir1/modified
679 # Submodule changes to be committed:
681 # * sm 0000000...$head (1):
682 # > Add foo
684 # Untracked files:
685 # (use "git add <file>..." to include in what will be committed)
687 # dir1/untracked
688 # dir2/modified
689 # dir2/untracked
690 # expect
691 # output
692 # untracked
694 test_expect_success 'commit --dry-run submodule summary (--amend)' '
695 git config status.submodulesummary 10 &&
696 git commit --dry-run --amend >output &&
697 test_cmp expect output
700 test_done