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