3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='git status'
10 test_expect_success
'setup' '
24 git commit -m initial &&
28 echo 1 >dir1/modified &&
29 echo 2 >dir2/modified &&
34 test_expect_success
'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
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
54 # (use "git add <file>..." to include in what will be committed)
64 test_expect_success
'status (2)' '
67 test_cmp expect output
73 # Changes to be committed:
74 # new file: dir2/added
76 # Changed but not updated:
77 # modified: dir1/modified
88 git config advice.statusHints false
90 test_expect_success
'status (advice.statusHints false)' '
93 test_cmp expect output
97 git config
--unset advice.statusHints
110 test_expect_success
'status -s (2)' '
112 git status -s >output &&
113 test_cmp expect output
119 # Changes to be committed:
120 # (use "git reset HEAD <file>..." to unstage)
122 # new file: dir2/added
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)
128 # modified: dir1/modified
130 # Untracked files not listed (use -u option to show untracked files)
132 test_expect_success
'status -uno' '
134 : >dir3/untracked1 &&
135 : >dir3/untracked2 &&
136 git status -uno >output &&
137 test_cmp expect output
140 test_expect_success
'status (status.showUntrackedFiles no)' '
141 git config status.showuntrackedfiles no
142 git status >output &&
143 test_cmp expect output
148 # Changes to be committed:
149 # new file: dir2/added
151 # Changed but not updated:
152 # modified: dir1/modified
154 # Untracked files not listed
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
161 git config
--unset advice.statusHints
167 test_expect_success
'status -s -uno' '
168 git config --unset status.showuntrackedfiles
169 git status -s -uno >output &&
170 test_cmp expect output
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
181 # Changes to be committed:
182 # (use "git reset HEAD <file>..." to unstage)
184 # new file: dir2/added
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)
190 # modified: dir1/modified
193 # (use "git add <file>..." to include in what will be committed)
203 test_expect_success
'status -unormal' '
204 git status -unormal >output &&
205 test_cmp expect output
208 test_expect_success
'status (status.showUntrackedFiles normal)' '
209 git config status.showuntrackedfiles normal
210 git status >output &&
211 test_cmp expect output
225 test_expect_success
'status -s -unormal' '
226 git config --unset status.showuntrackedfiles
227 git status -s -unormal >output &&
228 test_cmp expect output
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
239 # Changes to be committed:
240 # (use "git reset HEAD <file>..." to unstage)
242 # new file: dir2/added
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)
248 # modified: dir1/modified
251 # (use "git add <file>..." to include in what will be committed)
262 test_expect_success
'status -uall' '
263 git status -uall >output &&
264 test_cmp expect output
266 test_expect_success
'status (status.showUntrackedFiles all)' '
267 git config status.showuntrackedfiles all
268 git status >output &&
270 git config --unset status.showuntrackedfiles &&
271 test_cmp expect output
284 test_expect_success
'status -s -uall' '
285 git config --unset status.showuntrackedfiles
286 git status -s -uall >output &&
287 test_cmp expect output
289 test_expect_success
'status -s (status.showUntrackedFiles all)' '
290 git config status.showuntrackedfiles all
291 git status -s >output &&
293 git config --unset status.showuntrackedfiles &&
294 test_cmp expect output
299 # Changes to be committed:
300 # (use "git reset HEAD <file>..." to unstage)
302 # new file: ../dir2/added
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)
311 # (use "git add <file>..." to include in what will be committed)
321 test_expect_success
'status with relative paths' '
323 (cd dir1 && git status) >output &&
324 test_cmp expect output
338 test_expect_success
'status -s with relative paths' '
340 (cd dir1 && git status -s) >output &&
341 test_cmp expect output
356 test_expect_success
'status --porcelain ignores relative paths setting' '
358 (cd dir1 && git status --porcelain) >output &&
359 test_cmp expect output
363 test_expect_success
'setup unique colors' '
365 git config status.color.untracked blue
371 # Changes to be committed:
372 # (use "git reset HEAD <file>..." to unstage)
374 # <GREEN>new file: dir2/added<RESET>
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)
380 # <RED>modified: dir1/modified<RESET>
383 # (use "git add <file>..." to include in what will be committed)
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>
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
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
411 <RED
>M
<RESET
> dir
1/modified
412 <GREEN
>A
<RESET
> dir
2/added
413 <BLUE
>??
<RESET
> dir
1/untracked
414 <BLUE
>??
<RESET
> dir
2/modified
415 <BLUE
>??
<RESET
> dir
2/untracked
416 <BLUE
>??
<RESET
> expect
417 <BLUE
>??
<RESET
> output
418 <BLUE
>??
<RESET
> untracked
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
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
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
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
468 # recover unconditionally from color tests
469 git config
--unset color.status
470 git config
--unset color.ui
474 # Changes to be committed:
475 # (use "git reset HEAD <file>..." to unstage)
477 # new file: dir2/added
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)
483 # modified: dir1/modified
486 # (use "git add <file>..." to include in what will be committed)
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
516 test_expect_success
'status -s without relative paths' '
518 (cd dir1 && git status -s) >output &&
519 test_cmp expect output
525 # Changes to be committed:
526 # (use "git reset HEAD <file>..." to unstage)
528 # modified: dir1/modified
531 # (use "git add <file>..." to include in what will be committed)
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
545 :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
547 test_expect_success
'status refreshes the index' '
550 git diff-files >output &&
551 test_cmp expect output
554 test_expect_success
'setup status submodule summary' '
555 test_create_repo sm && (
559 git commit -m "Add foo"
566 # Changes to be committed:
567 # (use "git reset HEAD <file>..." to unstage)
569 # new file: dir2/added
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)
576 # modified: dir1/modified
579 # (use "git add <file>..." to include in what will be committed)
588 test_expect_success
'status submodule summary is disabled by default' '
589 git status >output &&
590 test_cmp expect output
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
610 test_expect_success
'status -s submodule summary is disabled by default' '
611 git status -s >output &&
612 test_cmp expect output
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
621 head=$
(cd sm
&& git rev-parse
--short=7 --verify HEAD
)
625 # Changes to be committed:
626 # (use "git reset HEAD <file>..." to unstage)
628 # new file: dir2/added
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 # Submodule changes to be committed:
639 # * sm 0000000...$head (1):
643 # (use "git add <file>..." to include in what will be committed)
652 test_expect_success
'status submodule summary' '
653 git config status.submodulesummary 10 &&
654 git status >output &&
655 test_cmp expect output
669 test_expect_success
'status -s submodule summary' '
670 git status -s >output &&
671 test_cmp expect output
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)
680 # modified: dir1/modified
683 # (use "git add <file>..." to include in what will be committed)
691 no changes added to commit (use "git add" and/or "git commit -a")
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
711 test_expect_success
'status -s submodule summary (clean submodule)' '
712 git status -s >output &&
713 test_cmp expect output
718 # Changes to be committed:
719 # (use "git reset HEAD^1 <file>..." to unstage)
721 # new file: dir2/added
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)
728 # modified: dir1/modified
730 # Submodule changes to be committed:
732 # * sm 0000000...$head (1):
736 # (use "git add <file>..." to include in what will be committed)
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
751 test_expect_success POSIXPERM
'status succeeds in a read-only repository' '
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