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