]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7508-status.sh
Merge branch 'ab/detox-gettext-tests'
[thirdparty/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
01c94e90 9. "$TEST_DIRECTORY"/lib-terminal.sh
367c9886 10
5d3dd915 11test_expect_success 'status -h in broken repository' '
6a38ef2c 12 git config --global advice.statusuoption false &&
5d3dd915
NTND
13 mkdir broken &&
14 test_when_finished "rm -fr broken" &&
15 (
16 cd broken &&
17 git init &&
18 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
19 test_expect_code 129 git status -h >usage 2>&1
20 ) &&
cc6658e7 21 test_i18ngrep "[Uu]sage" broken/usage
5d3dd915
NTND
22'
23
24test_expect_success 'commit -h in broken repository' '
25 mkdir broken &&
26 test_when_finished "rm -fr broken" &&
27 (
28 cd broken &&
29 git init &&
30 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
31 test_expect_code 129 git commit -h >usage 2>&1
32 ) &&
cc6658e7 33 test_i18ngrep "[Uu]sage" broken/usage
5d3dd915
NTND
34'
35
75177c85
JK
36test_expect_success 'create upstream branch' '
37 git checkout -b upstream &&
38 test_commit upstream1 &&
39 test_commit upstream2 &&
1e2ae142 40 # leave the first commit on main as root because several
75177c85
JK
41 # tests depend on this case; for our upstream we only
42 # care about commit counts anyway, so a totally divergent
43 # history is OK
1e2ae142 44 git checkout --orphan main
75177c85
JK
45'
46
367c9886 47test_expect_success 'setup' '
68cfc6f5
MG
48 : >tracked &&
49 : >modified &&
367c9886 50 mkdir dir1 &&
68cfc6f5
MG
51 : >dir1/tracked &&
52 : >dir1/modified &&
367c9886 53 mkdir dir2 &&
68cfc6f5
MG
54 : >dir1/tracked &&
55 : >dir1/modified &&
367c9886 56 git add . &&
ff58b9aa
JK
57
58 git status >output &&
59
367c9886
JS
60 test_tick &&
61 git commit -m initial &&
68cfc6f5
MG
62 : >untracked &&
63 : >dir1/untracked &&
64 : >dir2/untracked &&
65 echo 1 >dir1/modified &&
66 echo 2 >dir2/modified &&
67 echo 3 >dir2/added &&
75177c85
JK
68 git add dir2/added &&
69
70 git branch --set-upstream-to=upstream
367c9886
JS
71'
72
cc6658e7
JH
73test_expect_success 'status (1)' '
74 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
ff58b9aa
JK
75'
76
2556b996 77strip_comments () {
2e582df0
ES
78 tab=' '
79 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
2556b996
MM
80 rm "$1" && mv "$1".tmp "$1"
81}
82
ec8a896e
JH
83cat >.gitignore <<\EOF
84.gitignore
85expect*
86output*
87EOF
88
323d0530 89test_expect_success 'status --column' '
323d0530 90 cat >expect <<\EOF &&
1e2ae142 91# On branch main
75177c85
JK
92# Your branch and '\''upstream'\'' have diverged,
93# and have 1 and 2 different commits each, respectively.
94# (use "git pull" to merge the remote branch into yours)
95#
323d0530 96# Changes to be committed:
80f537f7 97# (use "git restore --staged <file>..." to unstage)
323d0530
NTND
98# new file: dir2/added
99#
100# Changes not staged for commit:
101# (use "git add <file>..." to update what will be committed)
80f537f7 102# (use "git restore <file>..." to discard changes in working directory)
323d0530
NTND
103# modified: dir1/modified
104#
105# Untracked files:
106# (use "git add <file>..." to include in what will be committed)
ec8a896e
JH
107# dir1/untracked dir2/untracked
108# dir2/modified untracked
2f0f7f1c 109#
323d0530 110EOF
2556b996 111 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
1108cea7 112 test_cmp expect output
2556b996
MM
113'
114
115test_expect_success 'status --column status.displayCommentPrefix=false' '
116 strip_comments expect &&
117 COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
1108cea7 118 test_cmp expect output
323d0530
NTND
119'
120
68cfc6f5 121cat >expect <<\EOF
1e2ae142 122# On branch main
75177c85
JK
123# Your branch and 'upstream' have diverged,
124# and have 1 and 2 different commits each, respectively.
125# (use "git pull" to merge the remote branch into yours)
126#
367c9886 127# Changes to be committed:
80f537f7 128# (use "git restore --staged <file>..." to unstage)
367c9886
JS
129# new file: dir2/added
130#
8009d83c 131# Changes not staged for commit:
367c9886 132# (use "git add <file>..." to update what will be committed)
80f537f7 133# (use "git restore <file>..." to discard changes in working directory)
367c9886
JS
134# modified: dir1/modified
135#
136# Untracked files:
137# (use "git add <file>..." to include in what will be committed)
367c9886
JS
138# dir1/untracked
139# dir2/modified
140# dir2/untracked
367c9886 141# untracked
2f0f7f1c 142#
367c9886
JS
143EOF
144
2556b996
MM
145test_expect_success 'status with status.displayCommentPrefix=true' '
146 git -c status.displayCommentPrefix=true status >output &&
1108cea7 147 test_cmp expect output
2556b996
MM
148'
149
150test_expect_success 'status with status.displayCommentPrefix=false' '
151 strip_comments expect &&
152 git -c status.displayCommentPrefix=false status >output &&
1108cea7 153 test_cmp expect output
367c9886
JS
154'
155
f8c65c1f
MG
156test_expect_success 'status -v' '
157 (cat expect && git diff --cached) >expect-with-v &&
158 git status -v >output &&
1108cea7 159 test_cmp expect-with-v output
f8c65c1f
MG
160'
161
40555000
MG
162test_expect_success 'status -v -v' '
163 (cat expect &&
164 echo "Changes to be committed:" &&
165 git -c diff.mnemonicprefix=true diff --cached &&
166 echo "--------------------------------------------------" &&
167 echo "Changes not staged for commit:" &&
168 git -c diff.mnemonicprefix=true diff) >expect-with-v &&
169 git status -v -v >output &&
1108cea7 170 test_cmp expect-with-v output
40555000
MG
171'
172
2556b996
MM
173test_expect_success 'setup fake editor' '
174 cat >.git/editor <<-\EOF &&
175 #! /bin/sh
176 cp "$1" output
177EOF
178 chmod 755 .git/editor
179'
180
181commit_template_commented () {
182 (
183 EDITOR=.git/editor &&
184 export EDITOR &&
185 # Fails due to empty message
186 test_must_fail git commit
187 ) &&
188 ! grep '^[^#]' output
189}
190
191test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
192 commit_template_commented
193'
194
18f3b5a9 195cat >expect <<\EOF
1e2ae142 196On branch main
75177c85
JK
197Your branch and 'upstream' have diverged,
198and have 1 and 2 different commits each, respectively.
199
1c7969c9
MM
200Changes to be committed:
201 new file: dir2/added
202
203Changes not staged for commit:
204 modified: dir1/modified
205
206Untracked files:
207 dir1/untracked
208 dir2/modified
209 dir2/untracked
1c7969c9 210 untracked
2f0f7f1c 211
18f3b5a9
MG
212EOF
213
cc6658e7 214test_expect_success 'status (advice.statusHints false)' '
c63659dd 215 test_config advice.statusHints false &&
18f3b5a9 216 git status >output &&
1108cea7 217 test_cmp expect output
18f3b5a9
MG
218
219'
220
68cfc6f5 221cat >expect <<\EOF
14ed05dd
MG
222 M dir1/modified
223A dir2/added
224?? dir1/untracked
225?? dir2/modified
226?? dir2/untracked
14ed05dd
MG
227?? untracked
228EOF
229
46077fa5 230test_expect_success 'status -s' '
14ed05dd 231
68cfc6f5 232 git status -s >output &&
14ed05dd
MG
233 test_cmp expect output
234
235'
236
150b493a
JH
237test_expect_success 'status with gitignore' '
238 {
239 echo ".gitignore" &&
f8c65c1f 240 echo "expect*" &&
150b493a
JH
241 echo "output" &&
242 echo "untracked"
243 } >.gitignore &&
244
245 cat >expect <<-\EOF &&
246 M dir1/modified
247 A dir2/added
248 ?? dir2/modified
249 EOF
250 git status -s >output &&
251 test_cmp expect output &&
252
253 cat >expect <<-\EOF &&
254 M dir1/modified
255 A dir2/added
256 ?? dir2/modified
257 !! .gitignore
258 !! dir1/untracked
259 !! dir2/untracked
260 !! expect
f8c65c1f 261 !! expect-with-v
150b493a
JH
262 !! output
263 !! untracked
264 EOF
265 git status -s --ignored >output &&
266 test_cmp expect output &&
267
1c7969c9 268 cat >expect <<\EOF &&
1e2ae142 269On branch main
75177c85
JK
270Your branch and '\''upstream'\'' have diverged,
271and have 1 and 2 different commits each, respectively.
272 (use "git pull" to merge the remote branch into yours)
273
1c7969c9 274Changes to be committed:
80f537f7 275 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
276 new file: dir2/added
277
278Changes not staged for commit:
279 (use "git add <file>..." to update what will be committed)
80f537f7 280 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
281 modified: dir1/modified
282
283Untracked files:
284 (use "git add <file>..." to include in what will be committed)
1c7969c9 285 dir2/modified
2f0f7f1c 286
1c7969c9
MM
287Ignored files:
288 (use "git add -f <file>..." to include in what will be committed)
1c7969c9
MM
289 .gitignore
290 dir1/untracked
291 dir2/untracked
292 expect
f8c65c1f 293 expect-with-v
1c7969c9
MM
294 output
295 untracked
2f0f7f1c 296
1c7969c9 297EOF
150b493a 298 git status --ignored >output &&
1108cea7 299 test_cmp expect output
150b493a
JH
300'
301
302test_expect_success 'status with gitignore (nothing untracked)' '
303 {
304 echo ".gitignore" &&
f8c65c1f 305 echo "expect*" &&
150b493a
JH
306 echo "dir2/modified" &&
307 echo "output" &&
308 echo "untracked"
309 } >.gitignore &&
310
311 cat >expect <<-\EOF &&
312 M dir1/modified
313 A dir2/added
314 EOF
315 git status -s >output &&
316 test_cmp expect output &&
317
318 cat >expect <<-\EOF &&
319 M dir1/modified
320 A dir2/added
321 !! .gitignore
322 !! dir1/untracked
323 !! dir2/modified
324 !! dir2/untracked
325 !! expect
f8c65c1f 326 !! expect-with-v
150b493a
JH
327 !! output
328 !! untracked
329 EOF
330 git status -s --ignored >output &&
331 test_cmp expect output &&
332
1c7969c9 333 cat >expect <<\EOF &&
1e2ae142 334On branch main
75177c85
JK
335Your branch and '\''upstream'\'' have diverged,
336and have 1 and 2 different commits each, respectively.
337 (use "git pull" to merge the remote branch into yours)
338
1c7969c9 339Changes to be committed:
80f537f7 340 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
341 new file: dir2/added
342
343Changes not staged for commit:
344 (use "git add <file>..." to update what will be committed)
80f537f7 345 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
346 modified: dir1/modified
347
348Ignored files:
349 (use "git add -f <file>..." to include in what will be committed)
1c7969c9
MM
350 .gitignore
351 dir1/untracked
352 dir2/modified
353 dir2/untracked
354 expect
f8c65c1f 355 expect-with-v
1c7969c9
MM
356 output
357 untracked
2f0f7f1c 358
1c7969c9 359EOF
150b493a 360 git status --ignored >output &&
1108cea7 361 test_cmp expect output
150b493a
JH
362'
363
ec8a896e
JH
364cat >.gitignore <<\EOF
365.gitignore
366expect*
367output*
368EOF
150b493a 369
46077fa5 370cat >expect <<\EOF
1e2ae142 371## main...upstream [ahead 1, behind 2]
46077fa5
MG
372 M dir1/modified
373A dir2/added
374?? dir1/untracked
375?? dir2/modified
376?? dir2/untracked
46077fa5
MG
377?? untracked
378EOF
379
380test_expect_success 'status -s -b' '
381
382 git status -s -b >output &&
1108cea7 383 test_cmp expect output
46077fa5
MG
384
385'
386
a5985237
JK
387test_expect_success 'status -s -z -b' '
388 tr "\\n" Q <expect >expect.q &&
389 mv expect.q expect &&
390 git status -s -z -b >output &&
391 nul_to_q <output >output.q &&
392 mv output.q output &&
1108cea7 393 test_cmp expect output
a5985237
JK
394'
395
355ec7a1
ÆAB
396test_expect_success 'setup dir3' '
397 mkdir dir3 &&
398 : >dir3/untracked1 &&
399 : >dir3/untracked2
400'
401
cc6658e7 402test_expect_success 'status -uno' '
1c7969c9 403 cat >expect <<EOF &&
1e2ae142 404On branch main
75177c85
JK
405Your branch and '\''upstream'\'' have diverged,
406and have 1 and 2 different commits each, respectively.
407 (use "git pull" to merge the remote branch into yours)
408
1c7969c9 409Changes to be committed:
80f537f7 410 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
411 new file: dir2/added
412
413Changes not staged for commit:
414 (use "git add <file>..." to update what will be committed)
80f537f7 415 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
416 modified: dir1/modified
417
418Untracked files not listed (use -u option to show untracked files)
419EOF
6c2ce048 420 git status -uno >output &&
1108cea7 421 test_cmp expect output
6c2ce048
MSO
422'
423
cc6658e7 424test_expect_success 'status (status.showUntrackedFiles no)' '
c63659dd 425 test_config status.showuntrackedfiles no &&
d6293d1f 426 git status >output &&
1108cea7 427 test_cmp expect output
d6293d1f
MSO
428'
429
cc6658e7 430test_expect_success 'status -uno (advice.statusHints false)' '
1c7969c9 431 cat >expect <<EOF &&
1e2ae142 432On branch main
75177c85
JK
433Your branch and '\''upstream'\'' have diverged,
434and have 1 and 2 different commits each, respectively.
435
1c7969c9
MM
436Changes to be committed:
437 new file: dir2/added
438
439Changes not staged for commit:
440 modified: dir1/modified
441
442Untracked files not listed
443EOF
c63659dd 444 test_config advice.statusHints false &&
18f3b5a9 445 git status -uno >output &&
1108cea7 446 test_cmp expect output
18f3b5a9 447'
18f3b5a9 448
14ed05dd
MG
449cat >expect << EOF
450 M dir1/modified
451A dir2/added
452EOF
453test_expect_success 'status -s -uno' '
14ed05dd
MG
454 git status -s -uno >output &&
455 test_cmp expect output
456'
457
458test_expect_success 'status -s (status.showUntrackedFiles no)' '
99094a7a 459 git config status.showuntrackedfiles no &&
14ed05dd
MG
460 git status -s >output &&
461 test_cmp expect output
462'
463
cc6658e7 464test_expect_success 'status -unormal' '
1c7969c9 465 cat >expect <<EOF &&
1e2ae142 466On branch main
75177c85
JK
467Your branch and '\''upstream'\'' have diverged,
468and have 1 and 2 different commits each, respectively.
469 (use "git pull" to merge the remote branch into yours)
470
1c7969c9 471Changes to be committed:
80f537f7 472 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
473 new file: dir2/added
474
475Changes not staged for commit:
476 (use "git add <file>..." to update what will be committed)
80f537f7 477 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
478 modified: dir1/modified
479
480Untracked files:
481 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
482 dir1/untracked
483 dir2/modified
484 dir2/untracked
485 dir3/
1c7969c9 486 untracked
2f0f7f1c 487
1c7969c9 488EOF
4bfee30a 489 git status -unormal >output &&
1108cea7 490 test_cmp expect output
4bfee30a
MSO
491'
492
cc6658e7 493test_expect_success 'status (status.showUntrackedFiles normal)' '
99094a7a 494 test_config status.showuntrackedfiles normal &&
d6293d1f 495 git status >output &&
1108cea7 496 test_cmp expect output
d6293d1f
MSO
497'
498
14ed05dd
MG
499cat >expect <<EOF
500 M dir1/modified
501A dir2/added
502?? dir1/untracked
503?? dir2/modified
504?? dir2/untracked
505?? dir3/
14ed05dd
MG
506?? untracked
507EOF
508test_expect_success 'status -s -unormal' '
14ed05dd
MG
509 git status -s -unormal >output &&
510 test_cmp expect output
511'
512
513test_expect_success 'status -s (status.showUntrackedFiles normal)' '
99094a7a 514 git config status.showuntrackedfiles normal &&
14ed05dd
MG
515 git status -s >output &&
516 test_cmp expect output
517'
518
cc6658e7 519test_expect_success 'status -uall' '
1c7969c9 520 cat >expect <<EOF &&
1e2ae142 521On branch main
75177c85
JK
522Your branch and '\''upstream'\'' have diverged,
523and have 1 and 2 different commits each, respectively.
524 (use "git pull" to merge the remote branch into yours)
525
1c7969c9 526Changes to be committed:
80f537f7 527 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
528 new file: dir2/added
529
530Changes not staged for commit:
531 (use "git add <file>..." to update what will be committed)
80f537f7 532 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
533 modified: dir1/modified
534
535Untracked files:
536 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
537 dir1/untracked
538 dir2/modified
539 dir2/untracked
540 dir3/untracked1
541 dir3/untracked2
1c7969c9 542 untracked
2f0f7f1c 543
1c7969c9 544EOF
4bfee30a 545 git status -uall >output &&
1108cea7 546 test_cmp expect output
d6293d1f 547'
cc6658e7
JH
548
549test_expect_success 'status (status.showUntrackedFiles all)' '
99094a7a 550 test_config status.showuntrackedfiles all &&
d6293d1f 551 git status >output &&
1108cea7 552 test_cmp expect output
4bfee30a
MSO
553'
554
355ec7a1
ÆAB
555test_expect_success 'teardown dir3' '
556 rm -rf dir3
557'
558
14ed05dd
MG
559cat >expect <<EOF
560 M dir1/modified
561A dir2/added
562?? dir1/untracked
563?? dir2/modified
564?? dir2/untracked
14ed05dd
MG
565?? untracked
566EOF
567test_expect_success 'status -s -uall' '
a6a4a88a 568 test_unconfig status.showuntrackedfiles &&
14ed05dd
MG
569 git status -s -uall >output &&
570 test_cmp expect output
571'
572test_expect_success 'status -s (status.showUntrackedFiles all)' '
c63659dd 573 test_config status.showuntrackedfiles all &&
14ed05dd
MG
574 git status -s >output &&
575 rm -rf dir3 &&
14ed05dd
MG
576 test_cmp expect output
577'
578
cc6658e7 579test_expect_success 'status with relative paths' '
1c7969c9 580 cat >expect <<\EOF &&
1e2ae142 581On branch main
75177c85
JK
582Your branch and '\''upstream'\'' have diverged,
583and have 1 and 2 different commits each, respectively.
584 (use "git pull" to merge the remote branch into yours)
585
1c7969c9 586Changes to be committed:
80f537f7 587 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
588 new file: ../dir2/added
589
590Changes not staged for commit:
591 (use "git add <file>..." to update what will be committed)
80f537f7 592 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
593 modified: modified
594
595Untracked files:
596 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
597 untracked
598 ../dir2/modified
599 ../dir2/untracked
1c7969c9 600 ../untracked
2f0f7f1c 601
1c7969c9 602EOF
68cfc6f5 603 (cd dir1 && git status) >output &&
1108cea7 604 test_cmp expect output
367c9886
JS
605'
606
68cfc6f5 607cat >expect <<\EOF
14ed05dd
MG
608 M modified
609A ../dir2/added
610?? untracked
611?? ../dir2/modified
612?? ../dir2/untracked
14ed05dd
MG
613?? ../untracked
614EOF
615test_expect_success 'status -s with relative paths' '
616
68cfc6f5 617 (cd dir1 && git status -s) >output &&
14ed05dd
MG
618 test_cmp expect output
619
620'
621
68cfc6f5 622cat >expect <<\EOF
c521bb71
MG
623 M dir1/modified
624A dir2/added
625?? dir1/untracked
626?? dir2/modified
627?? dir2/untracked
c521bb71
MG
628?? untracked
629EOF
630
631test_expect_success 'status --porcelain ignores relative paths setting' '
632
68cfc6f5 633 (cd dir1 && git status --porcelain) >output &&
c521bb71
MG
634 test_cmp expect output
635
636'
637
68cfc6f5
MG
638test_expect_success 'setup unique colors' '
639
1d282327 640 git config status.color.untracked blue &&
93fdf301
SK
641 git config status.color.branch green &&
642 git config status.color.localBranch yellow &&
643 git config status.color.remoteBranch cyan
68cfc6f5
MG
644
645'
646
01c94e90 647test_expect_success TTY 'status with color.ui' '
1c7969c9 648 cat >expect <<\EOF &&
1e2ae142 649On branch <GREEN>main<RESET>
75177c85
JK
650Your branch and '\''upstream'\'' have diverged,
651and have 1 and 2 different commits each, respectively.
652 (use "git pull" to merge the remote branch into yours)
653
1c7969c9 654Changes to be committed:
80f537f7 655 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
656 <GREEN>new file: dir2/added<RESET>
657
658Changes not staged for commit:
659 (use "git add <file>..." to update what will be committed)
80f537f7 660 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
661 <RED>modified: dir1/modified<RESET>
662
663Untracked files:
664 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
665 <BLUE>dir1/untracked<RESET>
666 <BLUE>dir2/modified<RESET>
667 <BLUE>dir2/untracked<RESET>
1c7969c9 668 <BLUE>untracked<RESET>
2f0f7f1c 669
1c7969c9 670EOF
01c94e90
JK
671 test_config color.ui auto &&
672 test_terminal git status | test_decode_color >output &&
1108cea7 673 test_cmp expect output
68cfc6f5
MG
674'
675
01c94e90
JK
676test_expect_success TTY 'status with color.status' '
677 test_config color.status auto &&
678 test_terminal git status | test_decode_color >output &&
1108cea7 679 test_cmp expect output
68cfc6f5
MG
680'
681
682cat >expect <<\EOF
683 <RED>M<RESET> dir1/modified
684<GREEN>A<RESET> dir2/added
685<BLUE>??<RESET> dir1/untracked
686<BLUE>??<RESET> dir2/modified
687<BLUE>??<RESET> dir2/untracked
68cfc6f5
MG
688<BLUE>??<RESET> untracked
689EOF
690
01c94e90 691test_expect_success TTY 'status -s with color.ui' '
68cfc6f5 692
01c94e90
JK
693 git config color.ui auto &&
694 test_terminal git status -s | test_decode_color >output &&
68cfc6f5
MG
695 test_cmp expect output
696
697'
698
01c94e90 699test_expect_success TTY 'status -s with color.status' '
68cfc6f5
MG
700
701 git config --unset color.ui &&
01c94e90
JK
702 git config color.status auto &&
703 test_terminal git status -s | test_decode_color >output &&
68cfc6f5
MG
704 test_cmp expect output
705
706'
707
46077fa5 708cat >expect <<\EOF
1e2ae142 709## <YELLOW>main<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
46077fa5
MG
710 <RED>M<RESET> dir1/modified
711<GREEN>A<RESET> dir2/added
712<BLUE>??<RESET> dir1/untracked
713<BLUE>??<RESET> dir2/modified
714<BLUE>??<RESET> dir2/untracked
46077fa5
MG
715<BLUE>??<RESET> untracked
716EOF
717
01c94e90 718test_expect_success TTY 'status -s -b with color.status' '
46077fa5 719
01c94e90 720 test_terminal git status -s -b | test_decode_color >output &&
1108cea7 721 test_cmp expect output
46077fa5
MG
722
723'
724
68cfc6f5
MG
725cat >expect <<\EOF
726 M dir1/modified
727A dir2/added
728?? dir1/untracked
729?? dir2/modified
730?? dir2/untracked
68cfc6f5
MG
731?? untracked
732EOF
733
01c94e90 734test_expect_success TTY 'status --porcelain ignores color.ui' '
68cfc6f5
MG
735
736 git config --unset color.status &&
01c94e90
JK
737 git config color.ui auto &&
738 test_terminal git status --porcelain | test_decode_color >output &&
68cfc6f5
MG
739 test_cmp expect output
740
741'
742
01c94e90 743test_expect_success TTY 'status --porcelain ignores color.status' '
68cfc6f5
MG
744
745 git config --unset color.ui &&
01c94e90
JK
746 git config color.status auto &&
747 test_terminal git status --porcelain | test_decode_color >output &&
68cfc6f5
MG
748 test_cmp expect output
749
750'
751
752# recover unconditionally from color tests
753git config --unset color.status
754git config --unset color.ui
755
d4a6bf1f 756test_expect_success 'status --porcelain respects -b' '
46077fa5
MG
757
758 git status --porcelain -b >output &&
d4a6bf1f 759 {
1e2ae142 760 echo "## main...upstream [ahead 1, behind 2]" &&
d4a6bf1f
JK
761 cat expect
762 } >tmp &&
763 mv tmp expect &&
46077fa5
MG
764 test_cmp expect output
765
766'
767
46f721c8 768
68cfc6f5 769
cc6658e7 770test_expect_success 'status without relative paths' '
1c7969c9 771 cat >expect <<\EOF &&
1e2ae142 772On branch main
75177c85
JK
773Your branch and '\''upstream'\'' have diverged,
774and have 1 and 2 different commits each, respectively.
775 (use "git pull" to merge the remote branch into yours)
776
1c7969c9 777Changes to be committed:
80f537f7 778 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
779 new file: dir2/added
780
781Changes not staged for commit:
782 (use "git add <file>..." to update what will be committed)
80f537f7 783 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
784 modified: dir1/modified
785
786Untracked files:
787 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
788 dir1/untracked
789 dir2/modified
790 dir2/untracked
1c7969c9 791 untracked
2f0f7f1c 792
1c7969c9 793EOF
c63659dd 794 test_config status.relativePaths false &&
68cfc6f5 795 (cd dir1 && git status) >output &&
1108cea7 796 test_cmp expect output
46f721c8
JK
797
798'
799
68cfc6f5 800cat >expect <<\EOF
14ed05dd
MG
801 M dir1/modified
802A dir2/added
803?? dir1/untracked
804?? dir2/modified
805?? dir2/untracked
14ed05dd
MG
806?? untracked
807EOF
808
809test_expect_success 'status -s without relative paths' '
810
c63659dd 811 test_config status.relativePaths false &&
68cfc6f5 812 (cd dir1 && git status -s) >output &&
14ed05dd
MG
813 test_cmp expect output
814
815'
816
a361dd3f
JH
817cat >expect <<\EOF
818 M dir1/modified
819A dir2/added
820A "file with spaces"
821?? dir1/untracked
822?? dir2/modified
823?? dir2/untracked
824?? "file with spaces 2"
825?? untracked
826EOF
827
828test_expect_success 'status -s without relative paths' '
829 test_when_finished "git rm --cached \"file with spaces\"; rm -f file*" &&
830 >"file with spaces" &&
831 >"file with spaces 2" &&
832 >"expect with spaces" &&
833 git add "file with spaces" &&
834
835 git status -s >output &&
836 test_cmp expect output &&
837
838 git status -s --ignored >output &&
839 grep "^!! \"expect with spaces\"$" output &&
840 grep -v "^!! " output >output-wo-ignored &&
841 test_cmp expect output-wo-ignored
842'
843
9e4b7ab6 844test_expect_success 'dry-run of partial commit excluding new file in index' '
1c7969c9 845 cat >expect <<EOF &&
1e2ae142 846On branch main
75177c85
JK
847Your branch and '\''upstream'\'' have diverged,
848and have 1 and 2 different commits each, respectively.
849 (use "git pull" to merge the remote branch into yours)
850
1c7969c9 851Changes to be committed:
80f537f7 852 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
853 modified: dir1/modified
854
855Untracked files:
856 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
857 dir1/untracked
858 dir2/
1c7969c9 859 untracked
2f0f7f1c 860
1c7969c9 861EOF
cc6658e7 862 git commit --dry-run dir1/modified >output &&
1108cea7 863 test_cmp expect output
959ba670
JK
864'
865
4c926b37 866cat >expect <<EOF
a5587b85 867:100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified
4c926b37 868EOF
4bb6644d 869test_expect_success 'status refreshes the index' '
4c926b37
MH
870 touch dir2/added &&
871 git status &&
872 git diff-files >output &&
873 test_cmp expect output
874'
875
f24c30e0
JT
876test_expect_success 'status shows detached HEAD properly after checking out non-local upstream branch' '
877 test_when_finished rm -rf upstream downstream actual &&
878
879 test_create_repo upstream &&
880 test_commit -C upstream foo &&
881
882 git clone upstream downstream &&
883 git -C downstream checkout @{u} &&
884 git -C downstream status >actual &&
885 test_i18ngrep "HEAD detached at [0-9a-f]\\+" actual
886'
887
e5e4a7f2
PY
888test_expect_success 'setup status submodule summary' '
889 test_create_repo sm && (
890 cd sm &&
891 >foo &&
892 git add foo &&
893 git commit -m "Add foo"
894 ) &&
895 git add sm
896'
897
cc6658e7 898test_expect_success 'status submodule summary is disabled by default' '
1c7969c9 899 cat >expect <<EOF &&
1e2ae142 900On branch main
75177c85
JK
901Your branch and '\''upstream'\'' have diverged,
902and have 1 and 2 different commits each, respectively.
903 (use "git pull" to merge the remote branch into yours)
904
1c7969c9 905Changes to be committed:
80f537f7 906 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
907 new file: dir2/added
908 new file: sm
909
910Changes not staged for commit:
911 (use "git add <file>..." to update what will be committed)
80f537f7 912 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
913 modified: dir1/modified
914
915Untracked files:
916 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
917 dir1/untracked
918 dir2/modified
919 dir2/untracked
1c7969c9 920 untracked
2f0f7f1c 921
1c7969c9 922EOF
e5e4a7f2 923 git status >output &&
1108cea7 924 test_cmp expect output
e5e4a7f2
PY
925'
926
98fa4738 927# we expect the same as the previous test
cc6658e7 928test_expect_success 'status --untracked-files=all does not show submodule' '
98fa4738 929 git status --untracked-files=all >output &&
1108cea7 930 test_cmp expect output
e5e4a7f2
PY
931'
932
14ed05dd
MG
933cat >expect <<EOF
934 M dir1/modified
935A dir2/added
936A sm
937?? dir1/untracked
938?? dir2/modified
939?? dir2/untracked
14ed05dd
MG
940?? untracked
941EOF
942test_expect_success 'status -s submodule summary is disabled by default' '
943 git status -s >output &&
944 test_cmp expect output
945'
946
947# we expect the same as the previous test
948test_expect_success 'status -s --untracked-files=all does not show submodule' '
949 git status -s --untracked-files=all >output &&
950 test_cmp expect output
951'
952
e5e4a7f2
PY
953head=$(cd sm && git rev-parse --short=7 --verify HEAD)
954
cc6658e7 955test_expect_success 'status submodule summary' '
1c7969c9 956 cat >expect <<EOF &&
1e2ae142 957On branch main
75177c85
JK
958Your branch and '\''upstream'\'' have diverged,
959and have 1 and 2 different commits each, respectively.
960 (use "git pull" to merge the remote branch into yours)
961
1c7969c9 962Changes to be committed:
80f537f7 963 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
964 new file: dir2/added
965 new file: sm
966
967Changes not staged for commit:
968 (use "git add <file>..." to update what will be committed)
80f537f7 969 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
970 modified: dir1/modified
971
972Submodule changes to be committed:
973
974* sm 0000000...$head (1):
975 > Add foo
976
977Untracked files:
978 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
979 dir1/untracked
980 dir2/modified
981 dir2/untracked
1c7969c9 982 untracked
2f0f7f1c 983
1c7969c9 984EOF
e5e4a7f2
PY
985 git config status.submodulesummary 10 &&
986 git status >output &&
1108cea7 987 test_cmp expect output
e5e4a7f2
PY
988'
989
2556b996
MM
990test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
991 strip_comments expect &&
992 git -c status.displayCommentPrefix=false status >output &&
1108cea7 993 test_cmp expect output
2556b996
MM
994'
995
996test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
997 commit_template_commented
998'
999
14ed05dd
MG
1000cat >expect <<EOF
1001 M dir1/modified
1002A dir2/added
1003A sm
1004?? dir1/untracked
1005?? dir2/modified
1006?? dir2/untracked
14ed05dd
MG
1007?? untracked
1008EOF
1009test_expect_success 'status -s submodule summary' '
1010 git status -s >output &&
1011 test_cmp expect output
1012'
e5e4a7f2 1013
1c7969c9
MM
1014test_expect_success 'status submodule summary (clean submodule): commit' '
1015 cat >expect <<EOF &&
1e2ae142 1016On branch main
75177c85
JK
1017Your branch and '\''upstream'\'' have diverged,
1018and have 2 and 2 different commits each, respectively.
1019 (use "git pull" to merge the remote branch into yours)
1020
1c7969c9
MM
1021Changes not staged for commit:
1022 (use "git add <file>..." to update what will be committed)
80f537f7 1023 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
1024 modified: dir1/modified
1025
1026Untracked files:
1027 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1028 dir1/untracked
1029 dir2/modified
1030 dir2/untracked
1c7969c9 1031 untracked
2f0f7f1c 1032
e5e4a7f2
PY
1033no changes added to commit (use "git add" and/or "git commit -a")
1034EOF
cc6658e7 1035 git commit -m "commit submodule" &&
e5e4a7f2 1036 git config status.submodulesummary 10 &&
9e4b7ab6 1037 test_must_fail git commit --dry-run >output &&
1108cea7 1038 test_cmp expect output &&
9e4b7ab6 1039 git status >output &&
1108cea7 1040 test_cmp expect output
e5e4a7f2
PY
1041'
1042
14ed05dd
MG
1043cat >expect <<EOF
1044 M dir1/modified
1045?? dir1/untracked
1046?? dir2/modified
1047?? dir2/untracked
14ed05dd
MG
1048?? untracked
1049EOF
1050test_expect_success 'status -s submodule summary (clean submodule)' '
1051 git status -s >output &&
1052 test_cmp expect output
1053'
1054
000f97bd 1055test_expect_success 'status -z implies porcelain' '
95b9f9f9 1056 git status --porcelain |
94221d22 1057 perl -pe "s/\012/\000/g" >expect &&
95b9f9f9
BC
1058 git status -z >output &&
1059 test_cmp expect output
1060'
1061
cc6658e7 1062test_expect_success 'commit --dry-run submodule summary (--amend)' '
1c7969c9 1063 cat >expect <<EOF &&
1e2ae142 1064On branch main
75177c85
JK
1065Your branch and '\''upstream'\'' have diverged,
1066and have 2 and 2 different commits each, respectively.
1067 (use "git pull" to merge the remote branch into yours)
1068
1c7969c9 1069Changes to be committed:
80f537f7 1070 (use "git restore --source=HEAD^1 --staged <file>..." to unstage)
1c7969c9
MM
1071 new file: dir2/added
1072 new file: sm
1073
1074Changes not staged for commit:
1075 (use "git add <file>..." to update what will be committed)
80f537f7 1076 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
1077 modified: dir1/modified
1078
1079Submodule changes to be committed:
1080
1081* sm 0000000...$head (1):
1082 > Add foo
1083
1084Untracked files:
1085 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1086 dir1/untracked
1087 dir2/modified
1088 dir2/untracked
1c7969c9 1089 untracked
2f0f7f1c 1090
1c7969c9 1091EOF
e5e4a7f2 1092 git config status.submodulesummary 10 &&
9e4b7ab6 1093 git commit --dry-run --amend >output &&
1108cea7 1094 test_cmp expect output
e5e4a7f2
PY
1095'
1096
c91cfd19 1097test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
03771425 1098 test_when_finished "chmod 775 .git" &&
b2f6fd95
MH
1099 (
1100 chmod a-w .git &&
1101 # make dir1/tracked stat-dirty
1102 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1103 git status -s >output &&
1104 ! grep dir1/tracked output &&
1105 # make sure "status" succeeded without writing index out
1106 git diff-files | grep dir1/tracked
1107 )
b2f6fd95
MH
1108'
1109
c2e0940b 1110(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
aee9c7d6
JL
1111new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1112touch .gitmodules
1113
cc6658e7 1114test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1c7969c9 1115 cat > expect << EOF &&
1e2ae142 1116On branch main
75177c85
JK
1117Your branch and '\''upstream'\'' have diverged,
1118and have 2 and 2 different commits each, respectively.
1119 (use "git pull" to merge the remote branch into yours)
1120
1c7969c9 1121Changes to be committed:
80f537f7 1122 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
1123 modified: sm
1124
1125Changes not staged for commit:
1126 (use "git add <file>..." to update what will be committed)
80f537f7 1127 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
1128 modified: dir1/modified
1129
1130Submodule changes to be committed:
1131
1132* sm $head...$new_head (1):
1133 > Add bar
1134
1135Untracked files:
1136 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1137 .gitmodules
1138 dir1/untracked
1139 dir2/modified
1140 dir2/untracked
1c7969c9 1141 untracked
2f0f7f1c 1142
1c7969c9 1143EOF
cc6658e7
JH
1144 echo modified sm/untracked &&
1145 git status --ignore-submodules=untracked >output &&
1108cea7 1146 test_cmp expect output
46a958b3
JL
1147'
1148
cc6658e7 1149test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
c63659dd 1150 test_config diff.ignoreSubmodules dirty &&
90e14525 1151 git status >output &&
1108cea7 1152 test_cmp expect output &&
302ad7a9
JL
1153 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1154 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1155 git status >output &&
1108cea7 1156 test_cmp expect output &&
c63659dd 1157 git config -f .gitmodules --remove-section submodule.subname
302ad7a9
JL
1158'
1159
cc6658e7 1160test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
302ad7a9
JL
1161 git config --add -f .gitmodules submodule.subname.ignore none &&
1162 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1163 git config --add submodule.subname.ignore untracked &&
1164 git config --add submodule.subname.path sm &&
cc6658e7 1165 git status >output &&
1108cea7 1166 test_cmp expect output &&
302ad7a9
JL
1167 git config --remove-section submodule.subname &&
1168 git config --remove-section -f .gitmodules submodule.subname
aee9c7d6
JL
1169'
1170
cc6658e7
JH
1171test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1172 git status --ignore-submodules=dirty >output &&
1108cea7 1173 test_cmp expect output
46a958b3
JL
1174'
1175
cc6658e7 1176test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
c63659dd 1177 test_config diff.ignoreSubmodules dirty &&
90e14525
JL
1178 git status >output &&
1179 ! test -s actual &&
302ad7a9
JL
1180 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1181 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1182 git status >output &&
1108cea7 1183 test_cmp expect output &&
c63659dd 1184 git config -f .gitmodules --remove-section submodule.subname
302ad7a9
JL
1185'
1186
cc6658e7 1187test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
302ad7a9
JL
1188 git config --add -f .gitmodules submodule.subname.ignore none &&
1189 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1190 git config --add submodule.subname.ignore dirty &&
1191 git config --add submodule.subname.path sm &&
cc6658e7 1192 git status >output &&
1108cea7 1193 test_cmp expect output &&
302ad7a9
JL
1194 git config --remove-section submodule.subname &&
1195 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1196'
1197
cc6658e7
JH
1198test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1199 echo modified >sm/foo &&
1200 git status --ignore-submodules=dirty >output &&
1108cea7 1201 test_cmp expect output
46a958b3
JL
1202'
1203
cc6658e7 1204test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
302ad7a9
JL
1205 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1206 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1207 git status >output &&
1108cea7 1208 test_cmp expect output &&
302ad7a9
JL
1209 git config -f .gitmodules --remove-section submodule.subname
1210'
1211
cc6658e7 1212test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
302ad7a9
JL
1213 git config --add -f .gitmodules submodule.subname.ignore none &&
1214 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1215 git config --add submodule.subname.ignore dirty &&
1216 git config --add submodule.subname.path sm &&
cc6658e7 1217 git status >output &&
1108cea7 1218 test_cmp expect output &&
302ad7a9
JL
1219 git config --remove-section submodule.subname &&
1220 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1221'
1222
cc6658e7 1223test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1c7969c9 1224 cat > expect << EOF &&
1e2ae142 1225On branch main
75177c85
JK
1226Your branch and '\''upstream'\'' have diverged,
1227and have 2 and 2 different commits each, respectively.
1228 (use "git pull" to merge the remote branch into yours)
1229
1c7969c9 1230Changes to be committed:
80f537f7 1231 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
1232 modified: sm
1233
1234Changes not staged for commit:
1235 (use "git add <file>..." to update what will be committed)
80f537f7 1236 (use "git restore <file>..." to discard changes in working directory)
1c7969c9 1237 (commit or discard the untracked or modified content in submodules)
1c7969c9
MM
1238 modified: dir1/modified
1239 modified: sm (modified content)
1240
1241Submodule changes to be committed:
1242
1243* sm $head...$new_head (1):
1244 > Add bar
1245
1246Untracked files:
1247 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1248 .gitmodules
1249 dir1/untracked
1250 dir2/modified
1251 dir2/untracked
1c7969c9 1252 untracked
2f0f7f1c 1253
1c7969c9 1254EOF
46a958b3 1255 git status --ignore-submodules=untracked > output &&
1108cea7 1256 test_cmp expect output
46a958b3
JL
1257'
1258
cc6658e7 1259test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
302ad7a9
JL
1260 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1261 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1262 git status >output &&
1108cea7 1263 test_cmp expect output &&
302ad7a9
JL
1264 git config -f .gitmodules --remove-section submodule.subname
1265'
1266
cc6658e7 1267test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
302ad7a9
JL
1268 git config --add -f .gitmodules submodule.subname.ignore none &&
1269 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1270 git config --add submodule.subname.ignore untracked &&
1271 git config --add submodule.subname.path sm &&
cc6658e7 1272 git status >output &&
1108cea7 1273 test_cmp expect output &&
302ad7a9
JL
1274 git config --remove-section submodule.subname &&
1275 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1276'
1277
46a958b3
JL
1278head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1279
cc6658e7 1280test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1c7969c9 1281 cat > expect << EOF &&
1e2ae142 1282On branch main
75177c85
JK
1283Your branch and '\''upstream'\'' have diverged,
1284and have 2 and 2 different commits each, respectively.
1285 (use "git pull" to merge the remote branch into yours)
1286
1c7969c9 1287Changes to be committed:
80f537f7 1288 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
1289 modified: sm
1290
1291Changes not staged for commit:
1292 (use "git add <file>..." to update what will be committed)
80f537f7 1293 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
1294 modified: dir1/modified
1295 modified: sm (new commits)
1296
1297Submodule changes to be committed:
1298
1299* sm $head...$new_head (1):
1300 > Add bar
1301
1302Submodules changed but not updated:
1303
1304* sm $new_head...$head2 (1):
1305 > 2nd commit
1306
1307Untracked files:
1308 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1309 .gitmodules
1310 dir1/untracked
1311 dir2/modified
1312 dir2/untracked
1c7969c9 1313 untracked
2f0f7f1c 1314
1c7969c9 1315EOF
46a958b3 1316 git status --ignore-submodules=untracked > output &&
1108cea7 1317 test_cmp expect output
46a958b3
JL
1318'
1319
cc6658e7 1320test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
302ad7a9
JL
1321 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1322 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1323 git status >output &&
1108cea7 1324 test_cmp expect output &&
302ad7a9
JL
1325 git config -f .gitmodules --remove-section submodule.subname
1326'
1327
cc6658e7 1328test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
302ad7a9
JL
1329 git config --add -f .gitmodules submodule.subname.ignore none &&
1330 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1331 git config --add submodule.subname.ignore untracked &&
1332 git config --add submodule.subname.path sm &&
cc6658e7 1333 git status >output &&
1108cea7 1334 test_cmp expect output &&
302ad7a9
JL
1335 git config --remove-section submodule.subname &&
1336 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1337'
1338
cc6658e7 1339test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
46a958b3 1340 git status --ignore-submodules=dirty > output &&
1108cea7 1341 test_cmp expect output
46a958b3 1342'
cc6658e7 1343test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
302ad7a9
JL
1344 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1345 git config --add -f .gitmodules submodule.subname.path sm &&
cc6658e7 1346 git status >output &&
1108cea7 1347 test_cmp expect output &&
302ad7a9
JL
1348 git config -f .gitmodules --remove-section submodule.subname
1349'
46a958b3 1350
cc6658e7 1351test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
302ad7a9
JL
1352 git config --add -f .gitmodules submodule.subname.ignore none &&
1353 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1354 git config --add submodule.subname.ignore dirty &&
1355 git config --add submodule.subname.path sm &&
cc6658e7 1356 git status >output &&
1108cea7 1357 test_cmp expect output &&
302ad7a9
JL
1358 git config --remove-section submodule.subname &&
1359 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1360'
1361
eff80a9f 1362cat > expect << EOF
1e2ae142 1363; On branch main
75177c85
JK
1364; Your branch and 'upstream' have diverged,
1365; and have 2 and 2 different commits each, respectively.
1366; (use "git pull" to merge the remote branch into yours)
1367;
eff80a9f 1368; Changes to be committed:
80f537f7 1369; (use "git restore --staged <file>..." to unstage)
eff80a9f
JH
1370; modified: sm
1371;
1372; Changes not staged for commit:
1373; (use "git add <file>..." to update what will be committed)
80f537f7 1374; (use "git restore <file>..." to discard changes in working directory)
eff80a9f
JH
1375; modified: dir1/modified
1376; modified: sm (new commits)
1377;
1378; Submodule changes to be committed:
1379;
1380; * sm $head...$new_head (1):
1381; > Add bar
1382;
1383; Submodules changed but not updated:
1384;
1385; * sm $new_head...$head2 (1):
1386; > 2nd commit
1387;
1388; Untracked files:
1389; (use "git add <file>..." to include in what will be committed)
eff80a9f
JH
1390; .gitmodules
1391; dir1/untracked
1392; dir2/modified
1393; dir2/untracked
eff80a9f 1394; untracked
2f0f7f1c 1395;
eff80a9f
JH
1396EOF
1397
1398test_expect_success "status (core.commentchar with submodule summary)" '
c63659dd 1399 test_config core.commentchar ";" &&
1c7969c9 1400 git -c status.displayCommentPrefix=true status >output &&
1108cea7 1401 test_cmp expect output
eff80a9f
JH
1402'
1403
1404test_expect_success "status (core.commentchar with two chars with submodule summary)" '
c63659dd 1405 test_config core.commentchar ";;" &&
50b54fd7 1406 test_must_fail git -c status.displayCommentPrefix=true status
eff80a9f
JH
1407'
1408
1c7969c9
MM
1409test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1410 cat > expect << EOF &&
1e2ae142 1411On branch main
75177c85
JK
1412Your branch and '\''upstream'\'' have diverged,
1413and have 2 and 2 different commits each, respectively.
1414 (use "git pull" to merge the remote branch into yours)
1415
1c7969c9
MM
1416Changes not staged for commit:
1417 (use "git add <file>..." to update what will be committed)
80f537f7 1418 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
1419 modified: dir1/modified
1420
1421Untracked files:
1422 (use "git add <file>..." to include in what will be committed)
1c7969c9
MM
1423 .gitmodules
1424 dir1/untracked
1425 dir2/modified
1426 dir2/untracked
1c7969c9 1427 untracked
2f0f7f1c 1428
46a958b3
JL
1429no changes added to commit (use "git add" and/or "git commit -a")
1430EOF
46a958b3 1431 git status --ignore-submodules=all > output &&
1108cea7 1432 test_cmp expect output
46a958b3
JL
1433'
1434
1d2f393a
JL
1435test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1436 cat > expect << EOF &&
1e2ae142 1437On branch main
75177c85
JK
1438Your branch and '\''upstream'\'' have diverged,
1439and have 2 and 2 different commits each, respectively.
1440 (use "git pull" to merge the remote branch into yours)
1441
1d2f393a 1442Changes to be committed:
80f537f7 1443 (use "git restore --staged <file>..." to unstage)
1d2f393a
JL
1444 modified: sm
1445
1446Changes not staged for commit:
1447 (use "git add <file>..." to update what will be committed)
80f537f7 1448 (use "git restore <file>..." to discard changes in working directory)
1d2f393a
JL
1449 modified: dir1/modified
1450
1451Untracked files:
1452 (use "git add <file>..." to include in what will be committed)
1d2f393a
JL
1453 .gitmodules
1454 dir1/untracked
1455 dir2/modified
1456 dir2/untracked
1d2f393a
JL
1457 untracked
1458
1459EOF
302ad7a9
JL
1460 git config --add -f .gitmodules submodule.subname.ignore all &&
1461 git config --add -f .gitmodules submodule.subname.path sm &&
1462 git status > output &&
1108cea7 1463 test_cmp expect output &&
302ad7a9
JL
1464 git config -f .gitmodules --remove-section submodule.subname
1465'
1466
1d2f393a 1467test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
302ad7a9
JL
1468 git config --add -f .gitmodules submodule.subname.ignore none &&
1469 git config --add -f .gitmodules submodule.subname.path sm &&
aee9c7d6
JL
1470 git config --add submodule.subname.ignore all &&
1471 git config --add submodule.subname.path sm &&
1472 git status > output &&
1108cea7 1473 test_cmp expect output &&
302ad7a9
JL
1474 git config --remove-section submodule.subname &&
1475 git config -f .gitmodules --remove-section submodule.subname
aee9c7d6
JL
1476'
1477
4fb5166a
JJGG
1478test_expect_success 'setup of test environment' '
1479 git config status.showUntrackedFiles no &&
1480 git status -s >expected_short &&
1481 git status --no-short >expected_noshort
1482'
1483
1484test_expect_success '"status.short=true" same as "-s"' '
1485 git -c status.short=true status >actual &&
1486 test_cmp expected_short actual
1487'
1488
1489test_expect_success '"status.short=true" weaker than "--no-short"' '
1490 git -c status.short=true status --no-short >actual &&
1491 test_cmp expected_noshort actual
1492'
1493
1494test_expect_success '"status.short=false" same as "--no-short"' '
1495 git -c status.short=false status >actual &&
1496 test_cmp expected_noshort actual
1497'
1498
1499test_expect_success '"status.short=false" weaker than "-s"' '
1500 git -c status.short=false status -s >actual &&
1501 test_cmp expected_short actual
1502'
1503
ec85d070
JJGG
1504test_expect_success '"status.branch=true" same as "-b"' '
1505 git status -sb >expected_branch &&
1506 git -c status.branch=true status -s >actual &&
1507 test_cmp expected_branch actual
1508'
1509
1510test_expect_success '"status.branch=true" different from "--no-branch"' '
1511 git status -s --no-branch >expected_nobranch &&
1512 git -c status.branch=true status -s >actual &&
e8a5f07d 1513 ! test_cmp expected_nobranch actual
ec85d070
JJGG
1514'
1515
1516test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1517 git -c status.branch=true status -s --no-branch >actual &&
1518 test_cmp expected_nobranch actual
1519'
1520
84b4202d
JH
1521test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1522 git -c status.branch=true status --porcelain >actual &&
1523 test_cmp expected_nobranch actual
1524'
1525
ec85d070
JJGG
1526test_expect_success '"status.branch=false" same as "--no-branch"' '
1527 git -c status.branch=false status -s >actual &&
1528 test_cmp expected_nobranch actual
1529'
1530
1531test_expect_success '"status.branch=false" weaker than "-b"' '
1532 git -c status.branch=false status -sb >actual &&
1533 test_cmp expected_branch actual
1534'
1535
4fb5166a
JJGG
1536test_expect_success 'Restore default test environment' '
1537 git config --unset status.showUntrackedFiles
1538'
1539
1d2f393a
JL
1540test_expect_success 'git commit will commit a staged but ignored submodule' '
1541 git config --add -f .gitmodules submodule.subname.ignore all &&
1542 git config --add -f .gitmodules submodule.subname.path sm &&
1543 git config --add submodule.subname.ignore all &&
1544 git status -s --ignore-submodules=dirty >output &&
1545 test_i18ngrep "^M. sm" output &&
1546 GIT_EDITOR="echo hello >>\"\$1\"" &&
1547 export GIT_EDITOR &&
1548 git commit -uno &&
1549 git status -s --ignore-submodules=dirty >output &&
1550 test_i18ngrep ! "^M. sm" output
1551'
1552
1553test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
1554 git reset HEAD^ &&
1555 git add sm &&
1556 cat >expect << EOF &&
1e2ae142 1557On branch main
75177c85
JK
1558Your branch and '\''upstream'\'' have diverged,
1559and have 2 and 2 different commits each, respectively.
1560 (use "git pull" to merge the remote branch into yours)
1561
1d2f393a 1562Changes to be committed:
80f537f7 1563 (use "git restore --staged <file>..." to unstage)
1d2f393a
JL
1564 modified: sm
1565
1566Changes not staged for commit:
1567 (use "git add <file>..." to update what will be committed)
80f537f7 1568 (use "git restore <file>..." to discard changes in working directory)
1d2f393a
JL
1569 modified: dir1/modified
1570
1571Untracked files not listed (use -u option to show untracked files)
1572EOF
1573 git commit -uno --dry-run >output &&
1108cea7 1574 test_cmp expect output &&
1d2f393a
JL
1575 git status -s --ignore-submodules=dirty >output &&
1576 test_i18ngrep "^M. sm" output
1577'
1578
c215d3d2 1579test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1d2f393a
JL
1580 git commit -uno -m message &&
1581 git status -s --ignore-submodules=dirty >output &&
4fced247 1582 test_i18ngrep ! "^M. sm" output &&
1d2f393a
JL
1583 git config --remove-section submodule.subname &&
1584 git config -f .gitmodules --remove-section submodule.subname
1585'
1586
c1b5d019
LB
1587test_expect_success 'show stash info with "--show-stash"' '
1588 git reset --hard &&
1589 git stash clear &&
1590 echo 1 >file &&
1591 git add file &&
1592 git stash &&
1593 git status >expected_default &&
1594 git status --show-stash >expected_with_stash &&
1595 test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash
1596'
1597
1598test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
1599 git status --show-stash --no-show-stash >expected_without_stash &&
1600 test_cmp expected_default expected_without_stash
1601'
1602
1603test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
1604 git -c status.showStash=false status --show-stash >actual &&
1605 test_cmp expected_with_stash actual
1606'
1607
1608test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
1609 git -c status.showStash=true status --no-show-stash >actual &&
1610 test_cmp expected_without_stash actual
1611'
1612
4dc8b1c1 1613test_expect_success 'no additional info if no stash entries' '
c1b5d019
LB
1614 git stash clear &&
1615 git -c status.showStash=true status >actual &&
1616 test_cmp expected_without_stash actual
1617'
1618
4ddb1354
KS
1619test_expect_success '"No commits yet" should be noted in status output' '
1620 git checkout --orphan empty-branch-1 &&
1621 git status >output &&
1622 test_i18ngrep "No commits yet" output
1623'
1624
1625test_expect_success '"No commits yet" should not be noted in status output' '
1626 git checkout --orphan empty-branch-2 &&
1627 test_commit test-commit-1 &&
1628 git status >output &&
1629 test_i18ngrep ! "No commits yet" output
1630'
1631
1632test_expect_success '"Initial commit" should be noted in commit template' '
1633 git checkout --orphan empty-branch-3 &&
1634 touch to_be_committed_1 &&
1635 git add to_be_committed_1 &&
1636 git commit --dry-run >output &&
1637 test_i18ngrep "Initial commit" output
1638'
1639
1640test_expect_success '"Initial commit" should not be noted in commit template' '
1641 git checkout --orphan empty-branch-4 &&
1642 test_commit test-commit-2 &&
1643 touch to_be_committed_2 &&
1644 git add to_be_committed_2 &&
1645 git commit --dry-run >output &&
1646 test_i18ngrep ! "Initial commit" output
1647'
1648
27344d6a 1649test_expect_success '--no-optional-locks prevents index update' '
0e496492 1650 test-tool chmtime =1234567890 .git/index &&
27344d6a 1651 git --no-optional-locks status &&
deb9845a 1652 test-tool chmtime --get .git/index >out &&
27344d6a
JK
1653 grep ^1234567890 out &&
1654 git status &&
deb9845a 1655 test-tool chmtime --get .git/index >out &&
27344d6a
JK
1656 ! grep ^1234567890 out
1657'
1658
367c9886 1659test_done