1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='git status'
7
8. ./test-lib.sh
9
10test_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 . &&
20
21 git status >output &&
22
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'
33
34test_expect_success 'status (1)' '
35
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
37
38'
39
40cat >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
62EOF
63
64test_expect_success 'status (2)' '
65
66 git status >output &&
67 test_cmp expect output
68
69'
70
71cat >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
86EOF
87
88git config advice.statusHints false
89
90test_expect_success 'status (advice.statusHints false)' '
91
92 git status >output &&
93 test_cmp expect output
94
95'
96
97git config --unset advice.statusHints
98
99cat >expect <<\EOF
100 M dir1/modified
101A dir2/added
102?? dir1/untracked
103?? dir2/modified
104?? dir2/untracked
105?? expect
106?? output
107?? untracked
108EOF
109
110test_expect_success 'status -s (2)' '
111
112 git status -s >output &&
113 test_cmp expect output
114
115'
116
117cat >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)
131EOF
132test_expect_success 'status -uno' '
133 mkdir dir3 &&
134 : >dir3/untracked1 &&
135 : >dir3/untracked2 &&
136 git status -uno >output &&
137 test_cmp expect output
138'
139
140test_expect_success 'status (status.showUntrackedFiles no)' '
141 git config status.showuntrackedfiles no
142 git status >output &&
143 test_cmp expect output
144'
145
146cat >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
155EOF
156git config advice.statusHints false
157test_expect_success 'status -uno (advice.statusHints false)' '
158 git status -uno >output &&
159 test_cmp expect output
160'
161git config --unset advice.statusHints
162
163cat >expect << EOF
164 M dir1/modified
165A dir2/added
166EOF
167test_expect_success 'status -s -uno' '
168 git config --unset status.showuntrackedfiles
169 git status -s -uno >output &&
170 test_cmp expect output
171'
172
173test_expect_success 'status -s (status.showUntrackedFiles no)' '
174 git config status.showuntrackedfiles no
175 git status -s >output &&
176 test_cmp expect output
177'
178
179cat >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
202EOF
203test_expect_success 'status -unormal' '
204 git status -unormal >output &&
205 test_cmp expect output
206'
207
208test_expect_success 'status (status.showUntrackedFiles normal)' '
209 git config status.showuntrackedfiles normal
210 git status >output &&
211 test_cmp expect output
212'
213
214cat >expect <<EOF
215 M dir1/modified
216A dir2/added
217?? dir1/untracked
218?? dir2/modified
219?? dir2/untracked
220?? dir3/
221?? expect
222?? output
223?? untracked
224EOF
225test_expect_success 'status -s -unormal' '
226 git config --unset status.showuntrackedfiles
227 git status -s -unormal >output &&
228 test_cmp expect output
229'
230
231test_expect_success 'status -s (status.showUntrackedFiles normal)' '
232 git config status.showuntrackedfiles normal
233 git status -s >output &&
234 test_cmp expect output
235'
236
237cat >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
261EOF
262test_expect_success 'status -uall' '
263 git status -uall >output &&
264 test_cmp expect output
265'
266test_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'
273
274cat >expect <<EOF
275 M dir1/modified
276A dir2/added
277?? dir1/untracked
278?? dir2/modified
279?? dir2/untracked
280?? expect
281?? output
282?? untracked
283EOF
284test_expect_success 'status -s -uall' '
285 git config --unset status.showuntrackedfiles
286 git status -s -uall >output &&
287 test_cmp expect output
288'
289test_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'
296
297cat >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
319EOF
320
321test_expect_success 'status with relative paths' '
322
323 (cd dir1 && git status) >output &&
324 test_cmp expect output
325
326'
327
328cat >expect <<\EOF
329 M modified
330A ../dir2/added
331?? untracked
332?? ../dir2/modified
333?? ../dir2/untracked
334?? ../expect
335?? ../output
336?? ../untracked
337EOF
338test_expect_success 'status -s with relative paths' '
339
340 (cd dir1 && git status -s) >output &&
341 test_cmp expect output
342
343'
344
345cat >expect <<\EOF
346 M dir1/modified
347A dir2/added
348?? dir1/untracked
349?? dir2/modified
350?? dir2/untracked
351?? expect
352?? output
353?? untracked
354EOF
355
356test_expect_success 'status --porcelain ignores relative paths setting' '
357
358 (cd dir1 && git status --porcelain) >output &&
359 test_cmp expect output
360
361'
362
363test_expect_success 'setup unique colors' '
364
365 git config status.color.untracked blue
366
367'
368
369cat >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>
391EOF
392
393test_expect_success 'status with color.ui' '
394
395 git config color.ui always &&
396 git status | test_decode_color >output &&
397 test_cmp expect output
398
399'
400
401test_expect_success 'status with color.status' '
402
403 git config --unset color.ui &&
404 git config color.status always &&
405 git status | test_decode_color >output &&
406 test_cmp expect output
407
408'
409
410cat >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
419EOF
420
421test_expect_success 'status -s with color.ui' '
422
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
427
428'
429
430test_expect_success 'status -s with color.status' '
431
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
436
437'
438
439cat >expect <<\EOF
440 M dir1/modified
441A dir2/added
442?? dir1/untracked
443?? dir2/modified
444?? dir2/untracked
445?? expect
446?? output
447?? untracked
448EOF
449
450test_expect_success 'status --porcelain ignores color.ui' '
451
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
456
457'
458
459test_expect_success 'status --porcelain ignores color.status' '
460
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
465
466'
467
468# recover unconditionally from color tests
469git config --unset color.status
470git config --unset color.ui
471
472cat >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
494EOF
495
496
497test_expect_success 'status without relative paths' '
498
499 git config status.relativePaths false
500 (cd dir1 && git status) >output &&
501 test_cmp expect output
502
503'
504
505cat >expect <<\EOF
506 M dir1/modified
507A dir2/added
508?? dir1/untracked
509?? dir2/modified
510?? dir2/untracked
511?? expect
512?? output
513?? untracked
514EOF
515
516test_expect_success 'status -s without relative paths' '
517
518 (cd dir1 && git status -s) >output &&
519 test_cmp expect output
520
521'
522
523cat <<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
538EOF
539test_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'
543
544test_expect_success 'setup status submodule summary' '
545 test_create_repo sm && (
546 cd sm &&
547 >foo &&
548 git add foo &&
549 git commit -m "Add foo"
550 ) &&
551 git add sm
552'
553
554cat >expect <<EOF
555# On branch master
556# Changes to be committed:
557# (use "git reset HEAD <file>..." to unstage)
558#
559# new file: dir2/added
560# new file: sm
561#
562# Changed but not updated:
563# (use "git add <file>..." to update what will be committed)
564# (use "git checkout -- <file>..." to discard changes in working directory)
565#
566# modified: dir1/modified
567#
568# Untracked files:
569# (use "git add <file>..." to include in what will be committed)
570#
571# dir1/untracked
572# dir2/modified
573# dir2/untracked
574# expect
575# output
576# untracked
577EOF
578test_expect_success 'status submodule summary is disabled by default' '
579 git status >output &&
580 test_cmp expect output
581'
582
583# we expect the same as the previous test
584test_expect_success 'status --untracked-files=all does not show submodule' '
585 git status --untracked-files=all >output &&
586 test_cmp expect output
587'
588
589cat >expect <<EOF
590 M dir1/modified
591A dir2/added
592A sm
593?? dir1/untracked
594?? dir2/modified
595?? dir2/untracked
596?? expect
597?? output
598?? untracked
599EOF
600test_expect_success 'status -s submodule summary is disabled by default' '
601 git status -s >output &&
602 test_cmp expect output
603'
604
605# we expect the same as the previous test
606test_expect_success 'status -s --untracked-files=all does not show submodule' '
607 git status -s --untracked-files=all >output &&
608 test_cmp expect output
609'
610
611head=$(cd sm && git rev-parse --short=7 --verify HEAD)
612
613cat >expect <<EOF
614# On branch master
615# Changes to be committed:
616# (use "git reset HEAD <file>..." to unstage)
617#
618# new file: dir2/added
619# new file: sm
620#
621# Changed but not updated:
622# (use "git add <file>..." to update what will be committed)
623# (use "git checkout -- <file>..." to discard changes in working directory)
624#
625# modified: dir1/modified
626#
627# Submodule changes to be committed:
628#
629# * sm 0000000...$head (1):
630# > Add foo
631#
632# Untracked files:
633# (use "git add <file>..." to include in what will be committed)
634#
635# dir1/untracked
636# dir2/modified
637# dir2/untracked
638# expect
639# output
640# untracked
641EOF
642test_expect_success 'status submodule summary' '
643 git config status.submodulesummary 10 &&
644 git status >output &&
645 test_cmp expect output
646'
647
648cat >expect <<EOF
649 M dir1/modified
650A dir2/added
651A sm
652?? dir1/untracked
653?? dir2/modified
654?? dir2/untracked
655?? expect
656?? output
657?? untracked
658EOF
659test_expect_success 'status -s submodule summary' '
660 git status -s >output &&
661 test_cmp expect output
662'
663
664cat >expect <<EOF
665# On branch master
666# Changed but not updated:
667# (use "git add <file>..." to update what will be committed)
668# (use "git checkout -- <file>..." to discard changes in working directory)
669#
670# modified: dir1/modified
671#
672# Untracked files:
673# (use "git add <file>..." to include in what will be committed)
674#
675# dir1/untracked
676# dir2/modified
677# dir2/untracked
678# expect
679# output
680# untracked
681no changes added to commit (use "git add" and/or "git commit -a")
682EOF
683test_expect_success 'status submodule summary (clean submodule)' '
684 git commit -m "commit submodule" &&
685 git config status.submodulesummary 10 &&
686 test_must_fail git commit --dry-run >output &&
687 test_cmp expect output &&
688 git status >output &&
689 test_cmp expect output
690'
691
692cat >expect <<EOF
693 M dir1/modified
694?? dir1/untracked
695?? dir2/modified
696?? dir2/untracked
697?? expect
698?? output
699?? untracked
700EOF
701test_expect_success 'status -s submodule summary (clean submodule)' '
702 git status -s >output &&
703 test_cmp expect output
704'
705
706cat >expect <<EOF
707# On branch master
708# Changes to be committed:
709# (use "git reset HEAD^1 <file>..." to unstage)
710#
711# new file: dir2/added
712# new file: sm
713#
714# Changed but not updated:
715# (use "git add <file>..." to update what will be committed)
716# (use "git checkout -- <file>..." to discard changes in working directory)
717#
718# modified: dir1/modified
719#
720# Submodule changes to be committed:
721#
722# * sm 0000000...$head (1):
723# > Add foo
724#
725# Untracked files:
726# (use "git add <file>..." to include in what will be committed)
727#
728# dir1/untracked
729# dir2/modified
730# dir2/untracked
731# expect
732# output
733# untracked
734EOF
735test_expect_success 'commit --dry-run submodule summary (--amend)' '
736 git config status.submodulesummary 10 &&
737 git commit --dry-run --amend >output &&
738 test_cmp expect output
739'
740
741test_done