branch: add --column
[git/git.git] / t / t7508-status.sh
CommitLineData
367c9886
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
47a528ad 6test_description='git status'
367c9886
JS
7
8. ./test-lib.sh
9
5d3dd915
NTND
10test_expect_success 'status -h in broken repository' '
11 mkdir broken &&
12 test_when_finished "rm -fr broken" &&
13 (
14 cd broken &&
15 git init &&
16 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
17 test_expect_code 129 git status -h >usage 2>&1
18 ) &&
cc6658e7 19 test_i18ngrep "[Uu]sage" broken/usage
5d3dd915
NTND
20'
21
22test_expect_success 'commit -h in broken repository' '
23 mkdir broken &&
24 test_when_finished "rm -fr broken" &&
25 (
26 cd broken &&
27 git init &&
28 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
29 test_expect_code 129 git commit -h >usage 2>&1
30 ) &&
cc6658e7 31 test_i18ngrep "[Uu]sage" broken/usage
5d3dd915
NTND
32'
33
367c9886 34test_expect_success 'setup' '
68cfc6f5
MG
35 : >tracked &&
36 : >modified &&
367c9886 37 mkdir dir1 &&
68cfc6f5
MG
38 : >dir1/tracked &&
39 : >dir1/modified &&
367c9886 40 mkdir dir2 &&
68cfc6f5
MG
41 : >dir1/tracked &&
42 : >dir1/modified &&
367c9886 43 git add . &&
ff58b9aa
JK
44
45 git status >output &&
46
367c9886
JS
47 test_tick &&
48 git commit -m initial &&
68cfc6f5
MG
49 : >untracked &&
50 : >dir1/untracked &&
51 : >dir2/untracked &&
52 echo 1 >dir1/modified &&
53 echo 2 >dir2/modified &&
54 echo 3 >dir2/added &&
367c9886
JS
55 git add dir2/added
56'
57
cc6658e7
JH
58test_expect_success 'status (1)' '
59 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
ff58b9aa
JK
60'
61
68cfc6f5 62cat >expect <<\EOF
367c9886
JS
63# On branch master
64# Changes to be committed:
65# (use "git reset HEAD <file>..." to unstage)
66#
67# new file: dir2/added
68#
8009d83c 69# Changes not staged for commit:
367c9886 70# (use "git add <file>..." to update what will be committed)
4d6e4c4d 71# (use "git checkout -- <file>..." to discard changes in working directory)
367c9886
JS
72#
73# modified: dir1/modified
74#
75# Untracked files:
76# (use "git add <file>..." to include in what will be committed)
77#
78# dir1/untracked
79# dir2/modified
80# dir2/untracked
81# expect
82# output
83# untracked
84EOF
85
cc6658e7 86test_expect_success 'status (2)' '
68cfc6f5 87 git status >output &&
cc6658e7 88 test_i18ncmp expect output
367c9886
JS
89'
90
18f3b5a9
MG
91cat >expect <<\EOF
92# On branch master
93# Changes to be committed:
94# new file: dir2/added
95#
8009d83c 96# Changes not staged for commit:
18f3b5a9
MG
97# modified: dir1/modified
98#
99# Untracked files:
100# dir1/untracked
101# dir2/modified
102# dir2/untracked
103# expect
104# output
105# untracked
106EOF
107
cc6658e7
JH
108test_expect_success 'status (advice.statusHints false)' '
109 test_when_finished "git config --unset advice.statusHints" &&
110 git config advice.statusHints false &&
18f3b5a9 111 git status >output &&
cc6658e7 112 test_i18ncmp expect output
18f3b5a9
MG
113
114'
115
68cfc6f5 116cat >expect <<\EOF
14ed05dd
MG
117 M dir1/modified
118A dir2/added
119?? dir1/untracked
120?? dir2/modified
121?? dir2/untracked
122?? expect
123?? output
124?? untracked
125EOF
126
46077fa5 127test_expect_success 'status -s' '
14ed05dd 128
68cfc6f5 129 git status -s >output &&
14ed05dd
MG
130 test_cmp expect output
131
132'
133
150b493a
JH
134test_expect_success 'status with gitignore' '
135 {
136 echo ".gitignore" &&
137 echo "expect" &&
138 echo "output" &&
139 echo "untracked"
140 } >.gitignore &&
141
142 cat >expect <<-\EOF &&
143 M dir1/modified
144 A dir2/added
145 ?? dir2/modified
146 EOF
147 git status -s >output &&
148 test_cmp expect output &&
149
150 cat >expect <<-\EOF &&
151 M dir1/modified
152 A dir2/added
153 ?? dir2/modified
154 !! .gitignore
155 !! dir1/untracked
156 !! dir2/untracked
157 !! expect
158 !! output
159 !! untracked
160 EOF
161 git status -s --ignored >output &&
162 test_cmp expect output &&
163
164 cat >expect <<-\EOF &&
165 # On branch master
166 # Changes to be committed:
167 # (use "git reset HEAD <file>..." to unstage)
168 #
169 # new file: dir2/added
170 #
50cebdad 171 # Changes not staged for commit:
150b493a
JH
172 # (use "git add <file>..." to update what will be committed)
173 # (use "git checkout -- <file>..." to discard changes in working directory)
174 #
175 # modified: dir1/modified
176 #
177 # Untracked files:
178 # (use "git add <file>..." to include in what will be committed)
179 #
180 # dir2/modified
181 # Ignored files:
182 # (use "git add -f <file>..." to include in what will be committed)
183 #
184 # .gitignore
185 # dir1/untracked
186 # dir2/untracked
187 # expect
188 # output
189 # untracked
190 EOF
191 git status --ignored >output &&
ca0f515d 192 test_i18ncmp expect output
150b493a
JH
193'
194
195test_expect_success 'status with gitignore (nothing untracked)' '
196 {
197 echo ".gitignore" &&
198 echo "expect" &&
199 echo "dir2/modified" &&
200 echo "output" &&
201 echo "untracked"
202 } >.gitignore &&
203
204 cat >expect <<-\EOF &&
205 M dir1/modified
206 A dir2/added
207 EOF
208 git status -s >output &&
209 test_cmp expect output &&
210
211 cat >expect <<-\EOF &&
212 M dir1/modified
213 A dir2/added
214 !! .gitignore
215 !! dir1/untracked
216 !! dir2/modified
217 !! dir2/untracked
218 !! expect
219 !! output
220 !! untracked
221 EOF
222 git status -s --ignored >output &&
223 test_cmp expect output &&
224
225 cat >expect <<-\EOF &&
226 # On branch master
227 # Changes to be committed:
228 # (use "git reset HEAD <file>..." to unstage)
229 #
230 # new file: dir2/added
231 #
50cebdad 232 # Changes not staged for commit:
150b493a
JH
233 # (use "git add <file>..." to update what will be committed)
234 # (use "git checkout -- <file>..." to discard changes in working directory)
235 #
236 # modified: dir1/modified
237 #
238 # Ignored files:
239 # (use "git add -f <file>..." to include in what will be committed)
240 #
241 # .gitignore
242 # dir1/untracked
243 # dir2/modified
244 # dir2/untracked
245 # expect
246 # output
247 # untracked
248 EOF
249 git status --ignored >output &&
ca0f515d 250 test_i18ncmp expect output
150b493a
JH
251'
252
253rm -f .gitignore
254
46077fa5
MG
255cat >expect <<\EOF
256## master
257 M dir1/modified
258A dir2/added
259?? dir1/untracked
260?? dir2/modified
261?? dir2/untracked
262?? expect
263?? output
264?? untracked
265EOF
266
267test_expect_success 'status -s -b' '
268
269 git status -s -b >output &&
270 test_cmp expect output
271
272'
273
355ec7a1
ÆAB
274test_expect_success 'setup dir3' '
275 mkdir dir3 &&
276 : >dir3/untracked1 &&
277 : >dir3/untracked2
278'
279
6c2ce048
MSO
280cat >expect <<EOF
281# On branch master
282# Changes to be committed:
283# (use "git reset HEAD <file>..." to unstage)
284#
285# new file: dir2/added
286#
8009d83c 287# Changes not staged for commit:
6c2ce048 288# (use "git add <file>..." to update what will be committed)
4d6e4c4d 289# (use "git checkout -- <file>..." to discard changes in working directory)
6c2ce048
MSO
290#
291# modified: dir1/modified
292#
293# Untracked files not listed (use -u option to show untracked files)
294EOF
cc6658e7 295test_expect_success 'status -uno' '
6c2ce048 296 git status -uno >output &&
cc6658e7 297 test_i18ncmp expect output
6c2ce048
MSO
298'
299
cc6658e7 300test_expect_success 'status (status.showUntrackedFiles no)' '
d6293d1f 301 git config status.showuntrackedfiles no
355ec7a1 302 test_when_finished "git config --unset status.showuntrackedfiles" &&
d6293d1f 303 git status >output &&
cc6658e7 304 test_i18ncmp expect output
d6293d1f
MSO
305'
306
18f3b5a9
MG
307cat >expect <<EOF
308# On branch master
309# Changes to be committed:
310# new file: dir2/added
311#
8009d83c 312# Changes not staged for commit:
18f3b5a9
MG
313# modified: dir1/modified
314#
980bde38 315# Untracked files not listed
18f3b5a9
MG
316EOF
317git config advice.statusHints false
cc6658e7 318test_expect_success 'status -uno (advice.statusHints false)' '
18f3b5a9 319 git status -uno >output &&
cc6658e7 320 test_i18ncmp expect output
18f3b5a9
MG
321'
322git config --unset advice.statusHints
323
14ed05dd
MG
324cat >expect << EOF
325 M dir1/modified
326A dir2/added
327EOF
328test_expect_success 'status -s -uno' '
14ed05dd
MG
329 git status -s -uno >output &&
330 test_cmp expect output
331'
332
333test_expect_success 'status -s (status.showUntrackedFiles no)' '
334 git config status.showuntrackedfiles no
335 git status -s >output &&
336 test_cmp expect output
337'
338
4bfee30a
MSO
339cat >expect <<EOF
340# On branch master
341# Changes to be committed:
342# (use "git reset HEAD <file>..." to unstage)
343#
344# new file: dir2/added
345#
8009d83c 346# Changes not staged for commit:
4bfee30a 347# (use "git add <file>..." to update what will be committed)
4d6e4c4d 348# (use "git checkout -- <file>..." to discard changes in working directory)
4bfee30a
MSO
349#
350# modified: dir1/modified
351#
352# Untracked files:
353# (use "git add <file>..." to include in what will be committed)
354#
355# dir1/untracked
356# dir2/modified
357# dir2/untracked
358# dir3/
359# expect
360# output
361# untracked
362EOF
cc6658e7 363test_expect_success 'status -unormal' '
4bfee30a 364 git status -unormal >output &&
cc6658e7 365 test_i18ncmp expect output
4bfee30a
MSO
366'
367
cc6658e7 368test_expect_success 'status (status.showUntrackedFiles normal)' '
d6293d1f 369 git config status.showuntrackedfiles normal
355ec7a1 370 test_when_finished "git config --unset status.showuntrackedfiles" &&
d6293d1f 371 git status >output &&
cc6658e7 372 test_i18ncmp expect output
d6293d1f
MSO
373'
374
14ed05dd
MG
375cat >expect <<EOF
376 M dir1/modified
377A dir2/added
378?? dir1/untracked
379?? dir2/modified
380?? dir2/untracked
381?? dir3/
382?? expect
383?? output
384?? untracked
385EOF
386test_expect_success 'status -s -unormal' '
14ed05dd
MG
387 git status -s -unormal >output &&
388 test_cmp expect output
389'
390
391test_expect_success 'status -s (status.showUntrackedFiles normal)' '
392 git config status.showuntrackedfiles normal
393 git status -s >output &&
394 test_cmp expect output
395'
396
4bfee30a
MSO
397cat >expect <<EOF
398# On branch master
399# Changes to be committed:
400# (use "git reset HEAD <file>..." to unstage)
401#
402# new file: dir2/added
403#
8009d83c 404# Changes not staged for commit:
4bfee30a 405# (use "git add <file>..." to update what will be committed)
4d6e4c4d 406# (use "git checkout -- <file>..." to discard changes in working directory)
4bfee30a
MSO
407#
408# modified: dir1/modified
409#
410# Untracked files:
411# (use "git add <file>..." to include in what will be committed)
412#
413# dir1/untracked
414# dir2/modified
415# dir2/untracked
416# dir3/untracked1
417# dir3/untracked2
418# expect
419# output
420# untracked
421EOF
cc6658e7 422test_expect_success 'status -uall' '
4bfee30a 423 git status -uall >output &&
cc6658e7 424 test_i18ncmp expect output
d6293d1f 425'
cc6658e7
JH
426
427test_expect_success 'status (status.showUntrackedFiles all)' '
d6293d1f 428 git config status.showuntrackedfiles all
355ec7a1 429 test_when_finished "git config --unset status.showuntrackedfiles" &&
d6293d1f 430 git status >output &&
cc6658e7 431 test_i18ncmp expect output
4bfee30a
MSO
432'
433
355ec7a1
ÆAB
434test_expect_success 'teardown dir3' '
435 rm -rf dir3
436'
437
14ed05dd
MG
438cat >expect <<EOF
439 M dir1/modified
440A dir2/added
441?? dir1/untracked
442?? dir2/modified
443?? dir2/untracked
444?? expect
445?? output
446?? untracked
447EOF
448test_expect_success 'status -s -uall' '
449 git config --unset status.showuntrackedfiles
450 git status -s -uall >output &&
451 test_cmp expect output
452'
453test_expect_success 'status -s (status.showUntrackedFiles all)' '
454 git config status.showuntrackedfiles all
455 git status -s >output &&
456 rm -rf dir3 &&
457 git config --unset status.showuntrackedfiles &&
458 test_cmp expect output
459'
460
68cfc6f5 461cat >expect <<\EOF
367c9886
JS
462# On branch master
463# Changes to be committed:
464# (use "git reset HEAD <file>..." to unstage)
465#
466# new file: ../dir2/added
467#
8009d83c 468# Changes not staged for commit:
367c9886 469# (use "git add <file>..." to update what will be committed)
4d6e4c4d 470# (use "git checkout -- <file>..." to discard changes in working directory)
367c9886 471#
69e74918 472# modified: modified
367c9886
JS
473#
474# Untracked files:
475# (use "git add <file>..." to include in what will be committed)
476#
477# untracked
478# ../dir2/modified
479# ../dir2/untracked
480# ../expect
481# ../output
482# ../untracked
483EOF
484
cc6658e7 485test_expect_success 'status with relative paths' '
68cfc6f5 486 (cd dir1 && git status) >output &&
cc6658e7 487 test_i18ncmp expect output
367c9886
JS
488'
489
68cfc6f5 490cat >expect <<\EOF
14ed05dd
MG
491 M modified
492A ../dir2/added
493?? untracked
494?? ../dir2/modified
495?? ../dir2/untracked
496?? ../expect
497?? ../output
498?? ../untracked
499EOF
500test_expect_success 'status -s with relative paths' '
501
68cfc6f5 502 (cd dir1 && git status -s) >output &&
14ed05dd
MG
503 test_cmp expect output
504
505'
506
68cfc6f5 507cat >expect <<\EOF
c521bb71
MG
508 M dir1/modified
509A dir2/added
510?? dir1/untracked
511?? dir2/modified
512?? dir2/untracked
513?? expect
514?? output
515?? untracked
516EOF
517
518test_expect_success 'status --porcelain ignores relative paths setting' '
519
68cfc6f5 520 (cd dir1 && git status --porcelain) >output &&
c521bb71
MG
521 test_cmp expect output
522
523'
524
68cfc6f5
MG
525test_expect_success 'setup unique colors' '
526
1d282327
AA
527 git config status.color.untracked blue &&
528 git config status.color.branch green
68cfc6f5
MG
529
530'
531
532cat >expect <<\EOF
1d282327 533# On branch <GREEN>master<RESET>
68cfc6f5
MG
534# Changes to be committed:
535# (use "git reset HEAD <file>..." to unstage)
536#
537# <GREEN>new file: dir2/added<RESET>
538#
8009d83c 539# Changes not staged for commit:
68cfc6f5
MG
540# (use "git add <file>..." to update what will be committed)
541# (use "git checkout -- <file>..." to discard changes in working directory)
542#
543# <RED>modified: dir1/modified<RESET>
544#
545# Untracked files:
546# (use "git add <file>..." to include in what will be committed)
547#
548# <BLUE>dir1/untracked<RESET>
549# <BLUE>dir2/modified<RESET>
550# <BLUE>dir2/untracked<RESET>
551# <BLUE>expect<RESET>
552# <BLUE>output<RESET>
553# <BLUE>untracked<RESET>
554EOF
555
cc6658e7 556test_expect_success 'status with color.ui' '
68cfc6f5 557 git config color.ui always &&
355ec7a1 558 test_when_finished "git config --unset color.ui" &&
68cfc6f5 559 git status | test_decode_color >output &&
cc6658e7 560 test_i18ncmp expect output
68cfc6f5
MG
561'
562
cc6658e7 563test_expect_success 'status with color.status' '
68cfc6f5 564 git config color.status always &&
355ec7a1 565 test_when_finished "git config --unset color.status" &&
68cfc6f5 566 git status | test_decode_color >output &&
cc6658e7 567 test_i18ncmp expect output
68cfc6f5
MG
568'
569
570cat >expect <<\EOF
571 <RED>M<RESET> dir1/modified
572<GREEN>A<RESET> dir2/added
573<BLUE>??<RESET> dir1/untracked
574<BLUE>??<RESET> dir2/modified
575<BLUE>??<RESET> dir2/untracked
576<BLUE>??<RESET> expect
577<BLUE>??<RESET> output
578<BLUE>??<RESET> untracked
579EOF
580
581test_expect_success 'status -s with color.ui' '
582
68cfc6f5
MG
583 git config color.ui always &&
584 git status -s | test_decode_color >output &&
585 test_cmp expect output
586
587'
588
589test_expect_success 'status -s with color.status' '
590
591 git config --unset color.ui &&
592 git config color.status always &&
593 git status -s | test_decode_color >output &&
594 test_cmp expect output
595
596'
597
46077fa5
MG
598cat >expect <<\EOF
599## <GREEN>master<RESET>
600 <RED>M<RESET> dir1/modified
601<GREEN>A<RESET> dir2/added
602<BLUE>??<RESET> dir1/untracked
603<BLUE>??<RESET> dir2/modified
604<BLUE>??<RESET> dir2/untracked
605<BLUE>??<RESET> expect
606<BLUE>??<RESET> output
607<BLUE>??<RESET> untracked
608EOF
609
610test_expect_success 'status -s -b with color.status' '
611
612 git status -s -b | test_decode_color >output &&
613 test_cmp expect output
614
615'
616
68cfc6f5
MG
617cat >expect <<\EOF
618 M dir1/modified
619A dir2/added
620?? dir1/untracked
621?? dir2/modified
622?? dir2/untracked
623?? expect
624?? output
625?? untracked
626EOF
627
628test_expect_success 'status --porcelain ignores color.ui' '
629
630 git config --unset color.status &&
631 git config color.ui always &&
632 git status --porcelain | test_decode_color >output &&
633 test_cmp expect output
634
635'
636
637test_expect_success 'status --porcelain ignores color.status' '
638
639 git config --unset color.ui &&
640 git config color.status always &&
641 git status --porcelain | test_decode_color >output &&
642 test_cmp expect output
643
644'
645
646# recover unconditionally from color tests
647git config --unset color.status
648git config --unset color.ui
649
46077fa5
MG
650test_expect_success 'status --porcelain ignores -b' '
651
652 git status --porcelain -b >output &&
653 test_cmp expect output
654
655'
656
68cfc6f5 657cat >expect <<\EOF
46f721c8
JK
658# On branch master
659# Changes to be committed:
660# (use "git reset HEAD <file>..." to unstage)
661#
662# new file: dir2/added
663#
8009d83c 664# Changes not staged for commit:
46f721c8 665# (use "git add <file>..." to update what will be committed)
4d6e4c4d 666# (use "git checkout -- <file>..." to discard changes in working directory)
46f721c8
JK
667#
668# modified: dir1/modified
669#
670# Untracked files:
671# (use "git add <file>..." to include in what will be committed)
672#
673# dir1/untracked
674# dir2/modified
675# dir2/untracked
676# expect
677# output
678# untracked
679EOF
680
68cfc6f5 681
cc6658e7 682test_expect_success 'status without relative paths' '
46f721c8 683
355ec7a1
ÆAB
684 git config status.relativePaths false &&
685 test_when_finished "git config --unset status.relativePaths" &&
68cfc6f5 686 (cd dir1 && git status) >output &&
cc6658e7 687 test_i18ncmp expect output
46f721c8
JK
688
689'
690
68cfc6f5 691cat >expect <<\EOF
14ed05dd
MG
692 M dir1/modified
693A dir2/added
694?? dir1/untracked
695?? dir2/modified
696?? dir2/untracked
697?? expect
698?? output
699?? untracked
700EOF
701
702test_expect_success 'status -s without relative paths' '
703
355ec7a1
ÆAB
704 git config status.relativePaths false &&
705 test_when_finished "git config --unset status.relativePaths" &&
68cfc6f5 706 (cd dir1 && git status -s) >output &&
14ed05dd
MG
707 test_cmp expect output
708
709'
710
959ba670
JK
711cat <<EOF >expect
712# On branch master
713# Changes to be committed:
714# (use "git reset HEAD <file>..." to unstage)
715#
716# modified: dir1/modified
717#
718# Untracked files:
719# (use "git add <file>..." to include in what will be committed)
720#
721# dir1/untracked
722# dir2/
723# expect
724# output
725# untracked
726EOF
9e4b7ab6 727test_expect_success 'dry-run of partial commit excluding new file in index' '
cc6658e7
JH
728 git commit --dry-run dir1/modified >output &&
729 test_i18ncmp expect output
959ba670
JK
730'
731
4c926b37
MH
732cat >expect <<EOF
733:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
734EOF
4bb6644d 735test_expect_success 'status refreshes the index' '
4c926b37
MH
736 touch dir2/added &&
737 git status &&
738 git diff-files >output &&
739 test_cmp expect output
740'
741
e5e4a7f2
PY
742test_expect_success 'setup status submodule summary' '
743 test_create_repo sm && (
744 cd sm &&
745 >foo &&
746 git add foo &&
747 git commit -m "Add foo"
748 ) &&
749 git add sm
750'
751
752cat >expect <<EOF
753# On branch master
754# Changes to be committed:
755# (use "git reset HEAD <file>..." to unstage)
756#
757# new file: dir2/added
758# new file: sm
759#
8009d83c 760# Changes not staged for commit:
e5e4a7f2 761# (use "git add <file>..." to update what will be committed)
4d6e4c4d 762# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
763#
764# modified: dir1/modified
765#
766# Untracked files:
767# (use "git add <file>..." to include in what will be committed)
768#
769# dir1/untracked
770# dir2/modified
771# dir2/untracked
772# expect
773# output
774# untracked
775EOF
cc6658e7 776test_expect_success 'status submodule summary is disabled by default' '
e5e4a7f2 777 git status >output &&
cc6658e7 778 test_i18ncmp expect output
e5e4a7f2
PY
779'
780
98fa4738 781# we expect the same as the previous test
cc6658e7 782test_expect_success 'status --untracked-files=all does not show submodule' '
98fa4738 783 git status --untracked-files=all >output &&
cc6658e7 784 test_i18ncmp expect output
e5e4a7f2
PY
785'
786
14ed05dd
MG
787cat >expect <<EOF
788 M dir1/modified
789A dir2/added
790A sm
791?? dir1/untracked
792?? dir2/modified
793?? dir2/untracked
794?? expect
795?? output
796?? untracked
797EOF
798test_expect_success 'status -s submodule summary is disabled by default' '
799 git status -s >output &&
800 test_cmp expect output
801'
802
803# we expect the same as the previous test
804test_expect_success 'status -s --untracked-files=all does not show submodule' '
805 git status -s --untracked-files=all >output &&
806 test_cmp expect output
807'
808
e5e4a7f2
PY
809head=$(cd sm && git rev-parse --short=7 --verify HEAD)
810
811cat >expect <<EOF
812# On branch master
813# Changes to be committed:
814# (use "git reset HEAD <file>..." to unstage)
815#
816# new file: dir2/added
817# new file: sm
818#
8009d83c 819# Changes not staged for commit:
e5e4a7f2 820# (use "git add <file>..." to update what will be committed)
4d6e4c4d 821# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
822#
823# modified: dir1/modified
824#
f17a5d34 825# Submodule changes to be committed:
e5e4a7f2
PY
826#
827# * sm 0000000...$head (1):
828# > Add foo
829#
830# Untracked files:
831# (use "git add <file>..." to include in what will be committed)
832#
833# dir1/untracked
834# dir2/modified
835# dir2/untracked
836# expect
837# output
838# untracked
839EOF
cc6658e7 840test_expect_success 'status submodule summary' '
e5e4a7f2
PY
841 git config status.submodulesummary 10 &&
842 git status >output &&
cc6658e7 843 test_i18ncmp expect output
e5e4a7f2
PY
844'
845
14ed05dd
MG
846cat >expect <<EOF
847 M dir1/modified
848A dir2/added
849A sm
850?? dir1/untracked
851?? dir2/modified
852?? dir2/untracked
853?? expect
854?? output
855?? untracked
856EOF
857test_expect_success 'status -s submodule summary' '
858 git status -s >output &&
859 test_cmp expect output
860'
e5e4a7f2
PY
861
862cat >expect <<EOF
863# On branch master
8009d83c 864# Changes not staged for commit:
e5e4a7f2 865# (use "git add <file>..." to update what will be committed)
4d6e4c4d 866# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
867#
868# modified: dir1/modified
869#
870# Untracked files:
871# (use "git add <file>..." to include in what will be committed)
872#
873# dir1/untracked
874# dir2/modified
875# dir2/untracked
876# expect
877# output
878# untracked
879no changes added to commit (use "git add" and/or "git commit -a")
880EOF
355ec7a1 881test_expect_success 'status submodule summary (clean submodule): commit' '
cc6658e7 882 git commit -m "commit submodule" &&
e5e4a7f2 883 git config status.submodulesummary 10 &&
9e4b7ab6 884 test_must_fail git commit --dry-run >output &&
cc6658e7 885 test_i18ncmp expect output &&
9e4b7ab6 886 git status >output &&
cc6658e7 887 test_i18ncmp expect output
e5e4a7f2
PY
888'
889
14ed05dd
MG
890cat >expect <<EOF
891 M dir1/modified
892?? dir1/untracked
893?? dir2/modified
894?? dir2/untracked
895?? expect
896?? output
897?? untracked
898EOF
899test_expect_success 'status -s submodule summary (clean submodule)' '
900 git status -s >output &&
901 test_cmp expect output
902'
903
000f97bd 904test_expect_success 'status -z implies porcelain' '
95b9f9f9
BC
905 git status --porcelain |
906 perl -pe "s/\012/\000/g" >expect &&
907 git status -z >output &&
908 test_cmp expect output
909'
910
e5e4a7f2
PY
911cat >expect <<EOF
912# On branch master
913# Changes to be committed:
914# (use "git reset HEAD^1 <file>..." to unstage)
915#
916# new file: dir2/added
917# new file: sm
918#
8009d83c 919# Changes not staged for commit:
e5e4a7f2 920# (use "git add <file>..." to update what will be committed)
4d6e4c4d 921# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
922#
923# modified: dir1/modified
924#
f17a5d34 925# Submodule changes to be committed:
e5e4a7f2
PY
926#
927# * sm 0000000...$head (1):
928# > Add foo
929#
930# Untracked files:
931# (use "git add <file>..." to include in what will be committed)
932#
933# dir1/untracked
934# dir2/modified
935# dir2/untracked
936# expect
937# output
938# untracked
939EOF
cc6658e7 940test_expect_success 'commit --dry-run submodule summary (--amend)' '
e5e4a7f2 941 git config status.submodulesummary 10 &&
9e4b7ab6 942 git commit --dry-run --amend >output &&
cc6658e7 943 test_i18ncmp expect output
e5e4a7f2
PY
944'
945
c91cfd19 946test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
b2f6fd95
MH
947 (
948 chmod a-w .git &&
949 # make dir1/tracked stat-dirty
950 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
951 git status -s >output &&
952 ! grep dir1/tracked output &&
953 # make sure "status" succeeded without writing index out
954 git diff-files | grep dir1/tracked
955 )
956 status=$?
957 chmod 775 .git
958 (exit $status)
959'
960
c2e0940b 961(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
aee9c7d6
JL
962new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
963touch .gitmodules
964
46a958b3
JL
965cat > expect << EOF
966# On branch master
aee9c7d6
JL
967# Changes to be committed:
968# (use "git reset HEAD <file>..." to unstage)
969#
970# modified: sm
971#
8009d83c 972# Changes not staged for commit:
46a958b3
JL
973# (use "git add <file>..." to update what will be committed)
974# (use "git checkout -- <file>..." to discard changes in working directory)
975#
976# modified: dir1/modified
977#
aee9c7d6
JL
978# Submodule changes to be committed:
979#
980# * sm $head...$new_head (1):
981# > Add bar
982#
46a958b3
JL
983# Untracked files:
984# (use "git add <file>..." to include in what will be committed)
985#
aee9c7d6 986# .gitmodules
46a958b3
JL
987# dir1/untracked
988# dir2/modified
989# dir2/untracked
990# expect
991# output
992# untracked
46a958b3
JL
993EOF
994
cc6658e7
JH
995test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
996 echo modified sm/untracked &&
997 git status --ignore-submodules=untracked >output &&
998 test_i18ncmp expect output
46a958b3
JL
999'
1000
cc6658e7 1001test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
90e14525
JL
1002 git config diff.ignoreSubmodules dirty &&
1003 git status >output &&
cc6658e7 1004 test_i18ncmp expect output &&
302ad7a9
JL
1005 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1006 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1007 git status >output &&
1008 test_i18ncmp expect output &&
90e14525
JL
1009 git config -f .gitmodules --remove-section submodule.subname &&
1010 git config --unset diff.ignoreSubmodules
302ad7a9
JL
1011'
1012
cc6658e7 1013test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
302ad7a9
JL
1014 git config --add -f .gitmodules submodule.subname.ignore none &&
1015 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1016 git config --add submodule.subname.ignore untracked &&
1017 git config --add submodule.subname.path sm &&
cc6658e7
JH
1018 git status >output &&
1019 test_i18ncmp expect output &&
302ad7a9
JL
1020 git config --remove-section submodule.subname &&
1021 git config --remove-section -f .gitmodules submodule.subname
aee9c7d6
JL
1022'
1023
cc6658e7
JH
1024test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1025 git status --ignore-submodules=dirty >output &&
1026 test_i18ncmp expect output
46a958b3
JL
1027'
1028
cc6658e7 1029test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
90e14525
JL
1030 git config diff.ignoreSubmodules dirty &&
1031 git status >output &&
1032 ! test -s actual &&
302ad7a9
JL
1033 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1034 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1035 git status >output &&
1036 test_i18ncmp expect output &&
90e14525
JL
1037 git config -f .gitmodules --remove-section submodule.subname &&
1038 git config --unset diff.ignoreSubmodules
302ad7a9
JL
1039'
1040
cc6658e7 1041test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
302ad7a9
JL
1042 git config --add -f .gitmodules submodule.subname.ignore none &&
1043 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1044 git config --add submodule.subname.ignore dirty &&
1045 git config --add submodule.subname.path sm &&
cc6658e7
JH
1046 git status >output &&
1047 test_i18ncmp expect output &&
302ad7a9
JL
1048 git config --remove-section submodule.subname &&
1049 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1050'
1051
cc6658e7
JH
1052test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1053 echo modified >sm/foo &&
1054 git status --ignore-submodules=dirty >output &&
1055 test_i18ncmp expect output
46a958b3
JL
1056'
1057
cc6658e7 1058test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
302ad7a9
JL
1059 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1060 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1061 git status >output &&
1062 test_i18ncmp expect output &&
302ad7a9
JL
1063 git config -f .gitmodules --remove-section submodule.subname
1064'
1065
cc6658e7 1066test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
302ad7a9
JL
1067 git config --add -f .gitmodules submodule.subname.ignore none &&
1068 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1069 git config --add submodule.subname.ignore dirty &&
1070 git config --add submodule.subname.path sm &&
cc6658e7
JH
1071 git status >output &&
1072 test_i18ncmp expect output &&
302ad7a9
JL
1073 git config --remove-section submodule.subname &&
1074 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1075'
1076
46a958b3
JL
1077cat > expect << EOF
1078# On branch master
aee9c7d6
JL
1079# Changes to be committed:
1080# (use "git reset HEAD <file>..." to unstage)
1081#
1082# modified: sm
1083#
8009d83c 1084# Changes not staged for commit:
46a958b3
JL
1085# (use "git add <file>..." to update what will be committed)
1086# (use "git checkout -- <file>..." to discard changes in working directory)
1087# (commit or discard the untracked or modified content in submodules)
1088#
1089# modified: dir1/modified
1090# modified: sm (modified content)
1091#
aee9c7d6
JL
1092# Submodule changes to be committed:
1093#
1094# * sm $head...$new_head (1):
1095# > Add bar
1096#
46a958b3
JL
1097# Untracked files:
1098# (use "git add <file>..." to include in what will be committed)
1099#
aee9c7d6 1100# .gitmodules
46a958b3
JL
1101# dir1/untracked
1102# dir2/modified
1103# dir2/untracked
1104# expect
1105# output
1106# untracked
46a958b3
JL
1107EOF
1108
cc6658e7 1109test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
46a958b3 1110 git status --ignore-submodules=untracked > output &&
cc6658e7 1111 test_i18ncmp expect output
46a958b3
JL
1112'
1113
cc6658e7 1114test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
302ad7a9
JL
1115 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1116 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1117 git status >output &&
1118 test_i18ncmp expect output &&
302ad7a9
JL
1119 git config -f .gitmodules --remove-section submodule.subname
1120'
1121
cc6658e7 1122test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
302ad7a9
JL
1123 git config --add -f .gitmodules submodule.subname.ignore none &&
1124 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1125 git config --add submodule.subname.ignore untracked &&
1126 git config --add submodule.subname.path sm &&
cc6658e7
JH
1127 git status >output &&
1128 test_i18ncmp expect output &&
302ad7a9
JL
1129 git config --remove-section submodule.subname &&
1130 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1131'
1132
46a958b3
JL
1133head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1134
1135cat > expect << EOF
1136# On branch master
aee9c7d6
JL
1137# Changes to be committed:
1138# (use "git reset HEAD <file>..." to unstage)
1139#
1140# modified: sm
1141#
8009d83c 1142# Changes not staged for commit:
46a958b3
JL
1143# (use "git add <file>..." to update what will be committed)
1144# (use "git checkout -- <file>..." to discard changes in working directory)
1145#
1146# modified: dir1/modified
1147# modified: sm (new commits)
1148#
aee9c7d6
JL
1149# Submodule changes to be committed:
1150#
1151# * sm $head...$new_head (1):
1152# > Add bar
1153#
46a958b3
JL
1154# Submodules changed but not updated:
1155#
aee9c7d6 1156# * sm $new_head...$head2 (1):
46a958b3
JL
1157# > 2nd commit
1158#
1159# Untracked files:
1160# (use "git add <file>..." to include in what will be committed)
1161#
aee9c7d6 1162# .gitmodules
46a958b3
JL
1163# dir1/untracked
1164# dir2/modified
1165# dir2/untracked
1166# expect
1167# output
1168# untracked
46a958b3
JL
1169EOF
1170
cc6658e7 1171test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
46a958b3 1172 git status --ignore-submodules=untracked > output &&
cc6658e7 1173 test_i18ncmp expect output
46a958b3
JL
1174'
1175
cc6658e7 1176test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
302ad7a9
JL
1177 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1178 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1179 git status >output &&
1180 test_i18ncmp expect output &&
302ad7a9
JL
1181 git config -f .gitmodules --remove-section submodule.subname
1182'
1183
cc6658e7 1184test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
302ad7a9
JL
1185 git config --add -f .gitmodules submodule.subname.ignore none &&
1186 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1187 git config --add submodule.subname.ignore untracked &&
1188 git config --add submodule.subname.path sm &&
cc6658e7
JH
1189 git status >output &&
1190 test_i18ncmp expect output &&
302ad7a9
JL
1191 git config --remove-section submodule.subname &&
1192 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1193'
1194
cc6658e7 1195test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
46a958b3 1196 git status --ignore-submodules=dirty > output &&
cc6658e7 1197 test_i18ncmp expect output
46a958b3 1198'
cc6658e7 1199test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
302ad7a9
JL
1200 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1201 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7
JH
1202 git status >output &&
1203 test_i18ncmp expect output &&
302ad7a9
JL
1204 git config -f .gitmodules --remove-section submodule.subname
1205'
46a958b3 1206
cc6658e7 1207test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
302ad7a9
JL
1208 git config --add -f .gitmodules submodule.subname.ignore none &&
1209 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1210 git config --add submodule.subname.ignore dirty &&
1211 git config --add submodule.subname.path sm &&
cc6658e7
JH
1212 git status >output &&
1213 test_i18ncmp expect output &&
302ad7a9
JL
1214 git config --remove-section submodule.subname &&
1215 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1216'
1217
46a958b3
JL
1218cat > expect << EOF
1219# On branch master
8009d83c 1220# Changes not staged for commit:
46a958b3
JL
1221# (use "git add <file>..." to update what will be committed)
1222# (use "git checkout -- <file>..." to discard changes in working directory)
1223#
1224# modified: dir1/modified
1225#
1226# Untracked files:
1227# (use "git add <file>..." to include in what will be committed)
1228#
aee9c7d6 1229# .gitmodules
46a958b3
JL
1230# dir1/untracked
1231# dir2/modified
1232# dir2/untracked
1233# expect
1234# output
1235# untracked
1236no changes added to commit (use "git add" and/or "git commit -a")
1237EOF
1238
cc6658e7 1239test_expect_success "--ignore-submodules=all suppresses submodule summary" '
46a958b3 1240 git status --ignore-submodules=all > output &&
cc6658e7 1241 test_i18ncmp expect output
46a958b3
JL
1242'
1243
302ad7a9
JL
1244test_expect_failure '.gitmodules ignore=all suppresses submodule summary' '
1245 git config --add -f .gitmodules submodule.subname.ignore all &&
1246 git config --add -f .gitmodules submodule.subname.path sm &&
1247 git status > output &&
1248 test_cmp expect output &&
1249 git config -f .gitmodules --remove-section submodule.subname
1250'
1251
aee9c7d6 1252test_expect_failure '.git/config ignore=all suppresses submodule summary' '
302ad7a9
JL
1253 git config --add -f .gitmodules submodule.subname.ignore none &&
1254 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1255 git config --add submodule.subname.ignore all &&
1256 git config --add submodule.subname.path sm &&
1257 git status > output &&
1258 test_cmp expect output &&
302ad7a9
JL
1259 git config --remove-section submodule.subname &&
1260 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1261'
1262
367c9886 1263test_done