Git 2.45
[git/gitster.git] / t / t7508-status.sh
blob773383fefb50a9ac673b84d89ebd63ba92792d3b
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git status'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-terminal.sh
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" &&
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_grep "[Uu]sage" broken/usage
25 test_expect_success 'commit -h in broken repository' '
26 mkdir broken &&
27 test_when_finished "rm -fr broken" &&
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_grep "[Uu]sage" broken/usage
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
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 . &&
59 git status >output &&
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 &&
71 git branch --set-upstream-to=upstream
74 test_expect_success 'status (1)' '
75 test_grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
78 strip_comments () {
79 tab=' '
80 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
81 rm "$1" && mv "$1".tmp "$1"
84 cat >.gitignore <<\EOF
85 .gitignore
86 expect*
87 output*
88 EOF
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" if you want to integrate the remote branch with yours)
97 # Changes to be committed:
98 # (use "git restore --staged <file>..." to unstage)
99 # new file: dir2/added
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
106 # Untracked files:
107 # (use "git add <file>..." to include in what will be committed)
108 # dir1/untracked dir2/untracked
109 # dir2/modified untracked
112 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
113 test_cmp expect output
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
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" if you want to integrate the remote branch with yours)
128 # Changes to be committed:
129 # (use "git restore --staged <file>..." to unstage)
130 # new file: dir2/added
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
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
146 test_expect_success 'status with status.displayCommentPrefix=true' '
147 git -c status.displayCommentPrefix=true status >output &&
148 test_cmp expect output
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
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
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
174 test_expect_success 'setup fake editor' '
175 cat >.git/editor <<-\EOF &&
176 #! /bin/sh
177 cp "$1" output
179 chmod 755 .git/editor
182 commit_template_commented () {
184 EDITOR=.git/editor &&
185 export EDITOR &&
186 # Fails due to empty message
187 test_must_fail git commit
188 ) &&
189 ! grep '^[^#]' output
192 test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
193 commit_template_commented
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.
201 Changes to be committed:
202 new file: dir2/added
204 Changes not staged for commit:
205 modified: dir1/modified
207 Untracked files:
208 dir1/untracked
209 dir2/modified
210 dir2/untracked
211 untracked
215 test_expect_success 'status (advice.statusHints false)' '
216 test_config advice.statusHints false &&
217 git status >output &&
218 test_cmp expect output
222 cat >expect <<\EOF
223 M dir1/modified
224 A dir2/added
225 ?? dir1/untracked
226 ?? dir2/modified
227 ?? dir2/untracked
228 ?? untracked
231 test_expect_success 'status -s' '
233 git status -s >output &&
234 test_cmp expect output
238 test_expect_success 'status with gitignore' '
240 echo ".gitignore" &&
241 echo "expect*" &&
242 echo "output" &&
243 echo "untracked"
244 } >.gitignore &&
246 cat >expect <<-\EOF &&
247 M dir1/modified
248 A dir2/added
249 ?? dir2/modified
251 git status -s >output &&
252 test_cmp expect output &&
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
266 git status -s --ignored >output &&
267 test_cmp expect output &&
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" if you want to integrate the remote branch with yours)
275 Changes to be committed:
276 (use "git restore --staged <file>..." to unstage)
277 new file: dir2/added
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
284 Untracked files:
285 (use "git add <file>..." to include in what will be committed)
286 dir2/modified
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
299 git status --ignored >output &&
300 test_cmp expect output
303 test_expect_success 'status with gitignore (nothing untracked)' '
305 echo ".gitignore" &&
306 echo "expect*" &&
307 echo "dir2/modified" &&
308 echo "output" &&
309 echo "untracked"
310 } >.gitignore &&
312 cat >expect <<-\EOF &&
313 M dir1/modified
314 A dir2/added
316 git status -s >output &&
317 test_cmp expect output &&
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
331 git status -s --ignored >output &&
332 test_cmp expect output &&
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" if you want to integrate the remote branch with yours)
340 Changes to be committed:
341 (use "git restore --staged <file>..." to unstage)
342 new file: dir2/added
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
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
361 git status --ignored >output &&
362 test_cmp expect output
365 cat >.gitignore <<\EOF
366 .gitignore
367 expect*
368 output*
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
381 test_expect_success 'status -s -b' '
383 git status -s -b >output &&
384 test_cmp expect output
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
397 test_expect_success 'setup dir3' '
398 mkdir dir3 &&
399 : >dir3/untracked1 &&
400 : >dir3/untracked2
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" if you want to integrate the remote branch with yours)
410 Changes to be committed:
411 (use "git restore --staged <file>..." to unstage)
412 new file: dir2/added
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
419 Untracked files not listed (use -u option to show untracked files)
421 git status -uno >output &&
422 test_cmp expect output &&
423 git status -ufalse >output &&
424 test_cmp expect output
427 for no in no false 0
429 test_expect_success "status (status.showUntrackedFiles $no)" '
430 test_config status.showuntrackedfiles "$no" &&
431 git status >output &&
432 test_cmp expect output
434 done
436 test_expect_success 'status -uno (advice.statusHints false)' '
437 cat >expect <<EOF &&
438 On branch main
439 Your branch and '\''upstream'\'' have diverged,
440 and have 1 and 2 different commits each, respectively.
442 Changes to be committed:
443 new file: dir2/added
445 Changes not staged for commit:
446 modified: dir1/modified
448 Untracked files not listed
450 test_config advice.statusHints false &&
451 git status -uno >output &&
452 test_cmp expect output
455 cat >expect << EOF
456 M dir1/modified
457 A dir2/added
459 test_expect_success 'status -s -uno' '
460 git status -s -uno >output &&
461 test_cmp expect output
464 test_expect_success 'status -s (status.showUntrackedFiles no)' '
465 git config status.showuntrackedfiles no &&
466 git status -s >output &&
467 test_cmp expect output
470 test_expect_success 'status -unormal' '
471 cat >expect <<EOF &&
472 On branch main
473 Your branch and '\''upstream'\'' have diverged,
474 and have 1 and 2 different commits each, respectively.
475 (use "git pull" if you want to integrate the remote branch with yours)
477 Changes to be committed:
478 (use "git restore --staged <file>..." to unstage)
479 new file: dir2/added
481 Changes not staged for commit:
482 (use "git add <file>..." to update what will be committed)
483 (use "git restore <file>..." to discard changes in working directory)
484 modified: dir1/modified
486 Untracked files:
487 (use "git add <file>..." to include in what will be committed)
488 dir1/untracked
489 dir2/modified
490 dir2/untracked
491 dir3/
492 untracked
495 git status -unormal >output &&
496 test_cmp expect output &&
497 git status -utrue >output &&
498 test_cmp expect output &&
499 git status -uyes >output &&
500 test_cmp expect output
503 for normal in normal true 1
505 test_expect_success "status (status.showUntrackedFiles $normal)" '
506 test_config status.showuntrackedfiles $normal &&
507 git status >output &&
508 test_cmp expect output
510 done
512 cat >expect <<EOF
513 M dir1/modified
514 A dir2/added
515 ?? dir1/untracked
516 ?? dir2/modified
517 ?? dir2/untracked
518 ?? dir3/
519 ?? untracked
521 test_expect_success 'status -s -unormal' '
522 git status -s -unormal >output &&
523 test_cmp expect output
526 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
527 git config status.showuntrackedfiles normal &&
528 git status -s >output &&
529 test_cmp expect output
532 test_expect_success 'status -uall' '
533 cat >expect <<EOF &&
534 On branch main
535 Your branch and '\''upstream'\'' have diverged,
536 and have 1 and 2 different commits each, respectively.
537 (use "git pull" if you want to integrate the remote branch with yours)
539 Changes to be committed:
540 (use "git restore --staged <file>..." to unstage)
541 new file: dir2/added
543 Changes not staged for commit:
544 (use "git add <file>..." to update what will be committed)
545 (use "git restore <file>..." to discard changes in working directory)
546 modified: dir1/modified
548 Untracked files:
549 (use "git add <file>..." to include in what will be committed)
550 dir1/untracked
551 dir2/modified
552 dir2/untracked
553 dir3/untracked1
554 dir3/untracked2
555 untracked
558 git status -uall >output &&
559 test_cmp expect output
562 test_expect_success 'status (status.showUntrackedFiles all)' '
563 test_config status.showuntrackedfiles all &&
564 git status >output &&
565 test_cmp expect output
568 test_expect_success 'teardown dir3' '
569 rm -rf dir3
572 cat >expect <<EOF
573 M dir1/modified
574 A dir2/added
575 ?? dir1/untracked
576 ?? dir2/modified
577 ?? dir2/untracked
578 ?? untracked
580 test_expect_success 'status -s -uall' '
581 test_unconfig status.showuntrackedfiles &&
582 git status -s -uall >output &&
583 test_cmp expect output
585 test_expect_success 'status -s (status.showUntrackedFiles all)' '
586 test_config status.showuntrackedfiles all &&
587 git status -s >output &&
588 rm -rf dir3 &&
589 test_cmp expect output
592 test_expect_success 'status with relative paths' '
593 cat >expect <<\EOF &&
594 On branch main
595 Your branch and '\''upstream'\'' have diverged,
596 and have 1 and 2 different commits each, respectively.
597 (use "git pull" if you want to integrate the remote branch with yours)
599 Changes to be committed:
600 (use "git restore --staged <file>..." to unstage)
601 new file: ../dir2/added
603 Changes not staged for commit:
604 (use "git add <file>..." to update what will be committed)
605 (use "git restore <file>..." to discard changes in working directory)
606 modified: modified
608 Untracked files:
609 (use "git add <file>..." to include in what will be committed)
610 untracked
611 ../dir2/modified
612 ../dir2/untracked
613 ../untracked
616 (cd dir1 && git status) >output &&
617 test_cmp expect output
620 cat >expect <<\EOF
621 M modified
622 A ../dir2/added
623 ?? untracked
624 ?? ../dir2/modified
625 ?? ../dir2/untracked
626 ?? ../untracked
628 test_expect_success 'status -s with relative paths' '
630 (cd dir1 && git status -s) >output &&
631 test_cmp expect output
635 cat >expect <<\EOF
636 M dir1/modified
637 A dir2/added
638 ?? dir1/untracked
639 ?? dir2/modified
640 ?? dir2/untracked
641 ?? untracked
644 test_expect_success 'status --porcelain ignores relative paths setting' '
646 (cd dir1 && git status --porcelain) >output &&
647 test_cmp expect output
651 test_expect_success 'setup unique colors' '
653 git config status.color.untracked blue &&
654 git config status.color.branch green &&
655 git config status.color.localBranch yellow &&
656 git config status.color.remoteBranch cyan
660 test_expect_success TTY 'status with color.ui' '
661 cat >expect <<\EOF &&
662 On branch <GREEN>main<RESET>
663 Your branch and '\''upstream'\'' have diverged,
664 and have 1 and 2 different commits each, respectively.
665 (use "git pull" if you want to integrate the remote branch with yours)
667 Changes to be committed:
668 (use "git restore --staged <file>..." to unstage)
669 <GREEN>new file: dir2/added<RESET>
671 Changes not staged for commit:
672 (use "git add <file>..." to update what will be committed)
673 (use "git restore <file>..." to discard changes in working directory)
674 <RED>modified: dir1/modified<RESET>
676 Untracked files:
677 (use "git add <file>..." to include in what will be committed)
678 <BLUE>dir1/untracked<RESET>
679 <BLUE>dir2/modified<RESET>
680 <BLUE>dir2/untracked<RESET>
681 <BLUE>untracked<RESET>
684 test_config color.ui auto &&
685 test_terminal git status | test_decode_color >output &&
686 test_cmp expect output
689 test_expect_success TTY 'status with color.status' '
690 test_config color.status auto &&
691 test_terminal git status | test_decode_color >output &&
692 test_cmp expect output
695 cat >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
701 <BLUE>??<RESET> untracked
704 test_expect_success TTY 'status -s with color.ui' '
706 git config color.ui auto &&
707 test_terminal git status -s | test_decode_color >output &&
708 test_cmp expect output
712 test_expect_success TTY 'status -s with color.status' '
714 git config --unset color.ui &&
715 git config color.status auto &&
716 test_terminal git status -s | test_decode_color >output &&
717 test_cmp expect output
721 cat >expect <<\EOF
722 ## <YELLOW>main<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
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
728 <BLUE>??<RESET> untracked
731 test_expect_success TTY 'status -s -b with color.status' '
733 test_terminal git status -s -b | test_decode_color >output &&
734 test_cmp expect output
738 cat >expect <<\EOF
739 M dir1/modified
740 A dir2/added
741 ?? dir1/untracked
742 ?? dir2/modified
743 ?? dir2/untracked
744 ?? untracked
747 test_expect_success TTY 'status --porcelain ignores color.ui' '
749 git config --unset color.status &&
750 git config color.ui auto &&
751 test_terminal git status --porcelain | test_decode_color >output &&
752 test_cmp expect output
756 test_expect_success TTY 'status --porcelain ignores color.status' '
758 git config --unset color.ui &&
759 git config color.status auto &&
760 test_terminal git status --porcelain | test_decode_color >output &&
761 test_cmp expect output
765 # recover unconditionally from color tests
766 git config --unset color.status
767 git config --unset color.ui
769 test_expect_success 'status --porcelain respects -b' '
771 git status --porcelain -b >output &&
773 echo "## main...upstream [ahead 1, behind 2]" &&
774 cat expect
775 } >tmp &&
776 mv tmp expect &&
777 test_cmp expect output
783 test_expect_success 'status without relative paths' '
784 cat >expect <<\EOF &&
785 On branch main
786 Your branch and '\''upstream'\'' have diverged,
787 and have 1 and 2 different commits each, respectively.
788 (use "git pull" if you want to integrate the remote branch with yours)
790 Changes to be committed:
791 (use "git restore --staged <file>..." to unstage)
792 new file: dir2/added
794 Changes not staged for commit:
795 (use "git add <file>..." to update what will be committed)
796 (use "git restore <file>..." to discard changes in working directory)
797 modified: dir1/modified
799 Untracked files:
800 (use "git add <file>..." to include in what will be committed)
801 dir1/untracked
802 dir2/modified
803 dir2/untracked
804 untracked
807 test_config status.relativePaths false &&
808 (cd dir1 && git status) >output &&
809 test_cmp expect output
813 cat >expect <<\EOF
814 M dir1/modified
815 A dir2/added
816 ?? dir1/untracked
817 ?? dir2/modified
818 ?? dir2/untracked
819 ?? untracked
822 test_expect_success 'status -s without relative paths' '
824 test_config status.relativePaths false &&
825 (cd dir1 && git status -s) >output &&
826 test_cmp expect output
830 cat >expect <<\EOF
831 M dir1/modified
832 A dir2/added
833 A "file with spaces"
834 ?? dir1/untracked
835 ?? dir2/modified
836 ?? dir2/untracked
837 ?? "file with spaces 2"
838 ?? untracked
841 test_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" &&
848 git status -s >output &&
849 test_cmp expect output &&
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
857 test_expect_success 'dry-run of partial commit excluding new file in index' '
858 cat >expect <<EOF &&
859 On branch main
860 Your branch and '\''upstream'\'' have diverged,
861 and have 1 and 2 different commits each, respectively.
863 Changes to be committed:
864 (use "git restore --staged <file>..." to unstage)
865 modified: dir1/modified
867 Untracked files:
868 (use "git add <file>..." to include in what will be committed)
869 dir1/untracked
870 dir2/
871 untracked
874 git commit --dry-run dir1/modified >output &&
875 test_cmp expect output
878 cat >expect <<EOF
879 :100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified
881 test_expect_success 'status refreshes the index' '
882 touch dir2/added &&
883 git status &&
884 git diff-files >output &&
885 test_cmp expect output
888 test_expect_success 'status shows detached HEAD properly after checking out non-local upstream branch' '
889 test_when_finished rm -rf upstream downstream actual &&
891 test_create_repo upstream &&
892 test_commit -C upstream foo &&
894 git clone upstream downstream &&
895 git -C downstream checkout @{u} &&
896 git -C downstream status >actual &&
897 grep -E "HEAD detached at [0-9a-f]+" actual
900 test_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
910 test_expect_success 'status submodule summary is disabled by default' '
911 cat >expect <<EOF &&
912 On branch main
913 Your branch and '\''upstream'\'' have diverged,
914 and have 1 and 2 different commits each, respectively.
915 (use "git pull" if you want to integrate the remote branch with yours)
917 Changes to be committed:
918 (use "git restore --staged <file>..." to unstage)
919 new file: dir2/added
920 new file: sm
922 Changes not staged for commit:
923 (use "git add <file>..." to update what will be committed)
924 (use "git restore <file>..." to discard changes in working directory)
925 modified: dir1/modified
927 Untracked files:
928 (use "git add <file>..." to include in what will be committed)
929 dir1/untracked
930 dir2/modified
931 dir2/untracked
932 untracked
935 git status >output &&
936 test_cmp expect output
939 # we expect the same as the previous test
940 test_expect_success 'status --untracked-files=all does not show submodule' '
941 git status --untracked-files=all >output &&
942 test_cmp expect output
945 cat >expect <<EOF
946 M dir1/modified
947 A dir2/added
948 A sm
949 ?? dir1/untracked
950 ?? dir2/modified
951 ?? dir2/untracked
952 ?? untracked
954 test_expect_success 'status -s submodule summary is disabled by default' '
955 git status -s >output &&
956 test_cmp expect output
959 # we expect the same as the previous test
960 test_expect_success 'status -s --untracked-files=all does not show submodule' '
961 git status -s --untracked-files=all >output &&
962 test_cmp expect output
965 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
967 test_expect_success 'status submodule summary' '
968 cat >expect <<EOF &&
969 On branch main
970 Your branch and '\''upstream'\'' have diverged,
971 and have 1 and 2 different commits each, respectively.
972 (use "git pull" if you want to integrate the remote branch with yours)
974 Changes to be committed:
975 (use "git restore --staged <file>..." to unstage)
976 new file: dir2/added
977 new file: sm
979 Changes not staged for commit:
980 (use "git add <file>..." to update what will be committed)
981 (use "git restore <file>..." to discard changes in working directory)
982 modified: dir1/modified
984 Submodule changes to be committed:
986 * sm 0000000...$head (1):
987 > Add foo
989 Untracked files:
990 (use "git add <file>..." to include in what will be committed)
991 dir1/untracked
992 dir2/modified
993 dir2/untracked
994 untracked
997 git config status.submodulesummary 10 &&
998 git status >output &&
999 test_cmp expect output
1002 test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
1003 strip_comments expect &&
1004 git -c status.displayCommentPrefix=false status >output &&
1005 test_cmp expect output
1008 test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
1009 commit_template_commented
1012 cat >expect <<EOF
1013 M dir1/modified
1014 A dir2/added
1015 A sm
1016 ?? dir1/untracked
1017 ?? dir2/modified
1018 ?? dir2/untracked
1019 ?? untracked
1021 test_expect_success 'status -s submodule summary' '
1022 git status -s >output &&
1023 test_cmp expect output
1026 test_expect_success 'status submodule summary (clean submodule): commit' '
1027 cat >expect-status <<EOF &&
1028 On branch main
1029 Your branch and '\''upstream'\'' have diverged,
1030 and have 2 and 2 different commits each, respectively.
1031 (use "git pull" if you want to integrate the remote branch with yours)
1033 Changes not staged for commit:
1034 (use "git add <file>..." to update what will be committed)
1035 (use "git restore <file>..." to discard changes in working directory)
1036 modified: dir1/modified
1038 Untracked files:
1039 (use "git add <file>..." to include in what will be committed)
1040 dir1/untracked
1041 dir2/modified
1042 dir2/untracked
1043 untracked
1045 no changes added to commit (use "git add" and/or "git commit -a")
1047 sed "/git pull/d" expect-status > expect-commit &&
1048 git commit -m "commit submodule" &&
1049 git config status.submodulesummary 10 &&
1050 test_must_fail git commit --dry-run >output &&
1051 test_cmp expect-commit output &&
1052 git status >output &&
1053 test_cmp expect-status output
1056 cat >expect <<EOF
1057 M dir1/modified
1058 ?? dir1/untracked
1059 ?? dir2/modified
1060 ?? dir2/untracked
1061 ?? untracked
1063 test_expect_success 'status -s submodule summary (clean submodule)' '
1064 git status -s >output &&
1065 test_cmp expect output
1068 test_expect_success 'status -z implies porcelain' '
1069 git status --porcelain |
1070 perl -pe "s/\012/\000/g" >expect &&
1071 git status -z >output &&
1072 test_cmp expect output
1075 test_expect_success 'commit --dry-run submodule summary (--amend)' '
1076 cat >expect <<EOF &&
1077 On branch main
1078 Your branch and '\''upstream'\'' have diverged,
1079 and have 2 and 2 different commits each, respectively.
1081 Changes to be committed:
1082 (use "git restore --source=HEAD^1 --staged <file>..." to unstage)
1083 new file: dir2/added
1084 new file: sm
1086 Changes not staged for commit:
1087 (use "git add <file>..." to update what will be committed)
1088 (use "git restore <file>..." to discard changes in working directory)
1089 modified: dir1/modified
1091 Submodule changes to be committed:
1093 * sm 0000000...$head (1):
1094 > Add foo
1096 Untracked files:
1097 (use "git add <file>..." to include in what will be committed)
1098 dir1/untracked
1099 dir2/modified
1100 dir2/untracked
1101 untracked
1104 git config status.submodulesummary 10 &&
1105 git commit --dry-run --amend >output &&
1106 test_cmp expect output
1109 test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
1110 test_when_finished "chmod 775 .git" &&
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
1122 (cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
1123 new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1124 touch .gitmodules
1126 test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
1127 cat > expect << EOF &&
1128 On branch main
1129 Your branch and '\''upstream'\'' have diverged,
1130 and have 2 and 2 different commits each, respectively.
1131 (use "git pull" if you want to integrate the remote branch with yours)
1133 Changes to be committed:
1134 (use "git restore --staged <file>..." to unstage)
1135 modified: sm
1137 Changes not staged for commit:
1138 (use "git add <file>..." to update what will be committed)
1139 (use "git restore <file>..." to discard changes in working directory)
1140 modified: dir1/modified
1142 Submodule changes to be committed:
1144 * sm $head...$new_head (1):
1145 > Add bar
1147 Untracked files:
1148 (use "git add <file>..." to include in what will be committed)
1149 .gitmodules
1150 dir1/untracked
1151 dir2/modified
1152 dir2/untracked
1153 untracked
1156 echo modified sm/untracked &&
1157 git status --ignore-submodules=untracked >output &&
1158 test_cmp expect output
1161 test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
1162 test_config diff.ignoreSubmodules dirty &&
1163 git status >output &&
1164 test_cmp expect output &&
1165 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1166 git config --add -f .gitmodules submodule.subname.path sm &&
1167 git status >output &&
1168 test_cmp expect output &&
1169 git config -f .gitmodules --remove-section submodule.subname
1172 test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
1173 git config --add -f .gitmodules submodule.subname.ignore none &&
1174 git config --add -f .gitmodules submodule.subname.path sm &&
1175 git config --add submodule.subname.ignore untracked &&
1176 git config --add submodule.subname.path sm &&
1177 git status >output &&
1178 test_cmp expect output &&
1179 git config --remove-section submodule.subname &&
1180 git config --remove-section -f .gitmodules submodule.subname
1183 test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1184 git status --ignore-submodules=dirty >output &&
1185 test_cmp expect output
1188 test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
1189 test_config diff.ignoreSubmodules dirty &&
1190 git status >output &&
1191 ! test -s actual &&
1192 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1193 git config --add -f .gitmodules submodule.subname.path sm &&
1194 git status >output &&
1195 test_cmp expect output &&
1196 git config -f .gitmodules --remove-section submodule.subname
1199 test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
1200 git config --add -f .gitmodules submodule.subname.ignore none &&
1201 git config --add -f .gitmodules submodule.subname.path sm &&
1202 git config --add submodule.subname.ignore dirty &&
1203 git config --add submodule.subname.path sm &&
1204 git status >output &&
1205 test_cmp expect output &&
1206 git config --remove-section submodule.subname &&
1207 git config -f .gitmodules --remove-section submodule.subname
1210 test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1211 echo modified >sm/foo &&
1212 git status --ignore-submodules=dirty >output &&
1213 test_cmp expect output
1216 test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
1217 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1218 git config --add -f .gitmodules submodule.subname.path sm &&
1219 git status >output &&
1220 test_cmp expect output &&
1221 git config -f .gitmodules --remove-section submodule.subname
1224 test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
1225 git config --add -f .gitmodules submodule.subname.ignore none &&
1226 git config --add -f .gitmodules submodule.subname.path sm &&
1227 git config --add submodule.subname.ignore dirty &&
1228 git config --add submodule.subname.path sm &&
1229 git status >output &&
1230 test_cmp expect output &&
1231 git config --remove-section submodule.subname &&
1232 git config -f .gitmodules --remove-section submodule.subname
1235 test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
1236 cat > expect << EOF &&
1237 On branch main
1238 Your branch and '\''upstream'\'' have diverged,
1239 and have 2 and 2 different commits each, respectively.
1240 (use "git pull" if you want to integrate the remote branch with yours)
1242 Changes to be committed:
1243 (use "git restore --staged <file>..." to unstage)
1244 modified: sm
1246 Changes not staged for commit:
1247 (use "git add <file>..." to update what will be committed)
1248 (use "git restore <file>..." to discard changes in working directory)
1249 (commit or discard the untracked or modified content in submodules)
1250 modified: dir1/modified
1251 modified: sm (modified content)
1253 Submodule changes to be committed:
1255 * sm $head...$new_head (1):
1256 > Add bar
1258 Untracked files:
1259 (use "git add <file>..." to include in what will be committed)
1260 .gitmodules
1261 dir1/untracked
1262 dir2/modified
1263 dir2/untracked
1264 untracked
1267 git status --ignore-submodules=untracked > output &&
1268 test_cmp expect output
1271 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
1272 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1273 git config --add -f .gitmodules submodule.subname.path sm &&
1274 git status >output &&
1275 test_cmp expect output &&
1276 git config -f .gitmodules --remove-section submodule.subname
1279 test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
1280 git config --add -f .gitmodules submodule.subname.ignore none &&
1281 git config --add -f .gitmodules submodule.subname.path sm &&
1282 git config --add submodule.subname.ignore untracked &&
1283 git config --add submodule.subname.path sm &&
1284 git status >output &&
1285 test_cmp expect output &&
1286 git config --remove-section submodule.subname &&
1287 git config -f .gitmodules --remove-section submodule.subname
1290 head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1292 test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
1293 cat > expect << EOF &&
1294 On branch main
1295 Your branch and '\''upstream'\'' have diverged,
1296 and have 2 and 2 different commits each, respectively.
1297 (use "git pull" if you want to integrate the remote branch with yours)
1299 Changes to be committed:
1300 (use "git restore --staged <file>..." to unstage)
1301 modified: sm
1303 Changes not staged for commit:
1304 (use "git add <file>..." to update what will be committed)
1305 (use "git restore <file>..." to discard changes in working directory)
1306 modified: dir1/modified
1307 modified: sm (new commits)
1309 Submodule changes to be committed:
1311 * sm $head...$new_head (1):
1312 > Add bar
1314 Submodules changed but not updated:
1316 * sm $new_head...$head2 (1):
1317 > 2nd commit
1319 Untracked files:
1320 (use "git add <file>..." to include in what will be committed)
1321 .gitmodules
1322 dir1/untracked
1323 dir2/modified
1324 dir2/untracked
1325 untracked
1328 git status --ignore-submodules=untracked > output &&
1329 test_cmp expect output
1332 test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
1333 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1334 git config --add -f .gitmodules submodule.subname.path sm &&
1335 git status >output &&
1336 test_cmp expect output &&
1337 git config -f .gitmodules --remove-section submodule.subname
1340 test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
1341 git config --add -f .gitmodules submodule.subname.ignore none &&
1342 git config --add -f .gitmodules submodule.subname.path sm &&
1343 git config --add submodule.subname.ignore untracked &&
1344 git config --add submodule.subname.path sm &&
1345 git status >output &&
1346 test_cmp expect output &&
1347 git config --remove-section submodule.subname &&
1348 git config -f .gitmodules --remove-section submodule.subname
1351 test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
1352 git status --ignore-submodules=dirty > output &&
1353 test_cmp expect output
1355 test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
1356 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1357 git config --add -f .gitmodules submodule.subname.path sm &&
1358 git status >output &&
1359 test_cmp expect output &&
1360 git config -f .gitmodules --remove-section submodule.subname
1363 test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
1364 git config --add -f .gitmodules submodule.subname.ignore none &&
1365 git config --add -f .gitmodules submodule.subname.path sm &&
1366 git config --add submodule.subname.ignore dirty &&
1367 git config --add submodule.subname.path sm &&
1368 git status >output &&
1369 test_cmp expect output &&
1370 git config --remove-section submodule.subname &&
1371 git config -f .gitmodules --remove-section submodule.subname
1374 cat > expect << EOF
1375 ; On branch main
1376 ; Your branch and 'upstream' have diverged,
1377 ; and have 2 and 2 different commits each, respectively.
1378 ; (use "git pull" if you want to integrate the remote branch with yours)
1380 ; Changes to be committed:
1381 ; (use "git restore --staged <file>..." to unstage)
1382 ; modified: sm
1384 ; Changes not staged for commit:
1385 ; (use "git add <file>..." to update what will be committed)
1386 ; (use "git restore <file>..." to discard changes in working directory)
1387 ; modified: dir1/modified
1388 ; modified: sm (new commits)
1390 ; Submodule changes to be committed:
1392 ; * sm $head...$new_head (1):
1393 ; > Add bar
1395 ; Submodules changed but not updated:
1397 ; * sm $new_head...$head2 (1):
1398 ; > 2nd commit
1400 ; Untracked files:
1401 ; (use "git add <file>..." to include in what will be committed)
1402 ; .gitmodules
1403 ; dir1/untracked
1404 ; dir2/modified
1405 ; dir2/untracked
1406 ; untracked
1410 test_expect_success "status (core.commentchar with submodule summary)" '
1411 test_config core.commentchar ";" &&
1412 git -c status.displayCommentPrefix=true status >output &&
1413 test_cmp expect output
1416 test_expect_success "status (core.commentchar with two chars with submodule summary)" '
1417 test_config core.commentchar ";;" &&
1418 sed "s/^/;/" <expect >expect.double &&
1419 git -c status.displayCommentPrefix=true status >output &&
1420 test_cmp expect.double output
1423 test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1424 cat > expect << EOF &&
1425 On branch main
1426 Your branch and '\''upstream'\'' have diverged,
1427 and have 2 and 2 different commits each, respectively.
1428 (use "git pull" if you want to integrate the remote branch with yours)
1430 Changes not staged for commit:
1431 (use "git add <file>..." to update what will be committed)
1432 (use "git restore <file>..." to discard changes in working directory)
1433 modified: dir1/modified
1435 Untracked files:
1436 (use "git add <file>..." to include in what will be committed)
1437 .gitmodules
1438 dir1/untracked
1439 dir2/modified
1440 dir2/untracked
1441 untracked
1443 no changes added to commit (use "git add" and/or "git commit -a")
1445 git status --ignore-submodules=all > output &&
1446 test_cmp expect output
1449 test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1450 cat > expect << EOF &&
1451 On branch main
1452 Your branch and '\''upstream'\'' have diverged,
1453 and have 2 and 2 different commits each, respectively.
1454 (use "git pull" if you want to integrate the remote branch with yours)
1456 Changes to be committed:
1457 (use "git restore --staged <file>..." to unstage)
1458 modified: sm
1460 Changes not staged for commit:
1461 (use "git add <file>..." to update what will be committed)
1462 (use "git restore <file>..." to discard changes in working directory)
1463 modified: dir1/modified
1465 Untracked files:
1466 (use "git add <file>..." to include in what will be committed)
1467 .gitmodules
1468 dir1/untracked
1469 dir2/modified
1470 dir2/untracked
1471 untracked
1474 git config --add -f .gitmodules submodule.subname.ignore all &&
1475 git config --add -f .gitmodules submodule.subname.path sm &&
1476 git status > output &&
1477 test_cmp expect output &&
1478 git config -f .gitmodules --remove-section submodule.subname
1481 test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
1482 git config --add -f .gitmodules submodule.subname.ignore none &&
1483 git config --add -f .gitmodules submodule.subname.path sm &&
1484 git config --add submodule.subname.ignore all &&
1485 git config --add submodule.subname.path sm &&
1486 git status > output &&
1487 test_cmp expect output &&
1488 git config --remove-section submodule.subname &&
1489 git config -f .gitmodules --remove-section submodule.subname
1492 test_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
1498 test_expect_success '"status.short=true" same as "-s"' '
1499 git -c status.short=true status >actual &&
1500 test_cmp expected_short actual
1503 test_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
1508 test_expect_success '"status.short=false" same as "--no-short"' '
1509 git -c status.short=false status >actual &&
1510 test_cmp expected_noshort actual
1513 test_expect_success '"status.short=false" weaker than "-s"' '
1514 git -c status.short=false status -s >actual &&
1515 test_cmp expected_short actual
1518 test_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
1524 test_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 &&
1527 ! test_cmp expected_nobranch actual
1530 test_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
1535 test_expect_success '"status.branch=true" weaker than "--porcelain"' '
1536 git -c status.branch=true status --porcelain >actual &&
1537 test_cmp expected_nobranch actual
1540 test_expect_success '"status.branch=false" same as "--no-branch"' '
1541 git -c status.branch=false status -s >actual &&
1542 test_cmp expected_nobranch actual
1545 test_expect_success '"status.branch=false" weaker than "-b"' '
1546 git -c status.branch=false status -sb >actual &&
1547 test_cmp expected_branch actual
1550 test_expect_success 'Restore default test environment' '
1551 git config --unset status.showUntrackedFiles
1554 test_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 &&
1559 test_grep "^M. sm" output &&
1560 GIT_EDITOR="echo hello >>\"\$1\"" &&
1561 export GIT_EDITOR &&
1562 git commit -uno &&
1563 git status -s --ignore-submodules=dirty >output &&
1564 test_grep ! "^M. sm" output
1567 test_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 &&
1571 On branch main
1572 Your branch and '\''upstream'\'' have diverged,
1573 and have 2 and 2 different commits each, respectively.
1575 Changes to be committed:
1576 (use "git restore --staged <file>..." to unstage)
1577 modified: sm
1579 Changes not staged for commit:
1580 (use "git add <file>..." to update what will be committed)
1581 (use "git restore <file>..." to discard changes in working directory)
1582 modified: dir1/modified
1584 Untracked files not listed (use -u option to show untracked files)
1586 git commit -uno --dry-run >output &&
1587 test_cmp expect output &&
1588 git status -s --ignore-submodules=dirty >output &&
1589 test_grep "^M. sm" output
1592 test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1593 git commit -uno -m message &&
1594 git status -s --ignore-submodules=dirty >output &&
1595 test_grep ! "^M. sm" output &&
1596 git config --remove-section submodule.subname &&
1597 git config -f .gitmodules --remove-section submodule.subname
1600 test_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 &&
1608 test_grep "^Your stash currently has 1 entry$" expected_with_stash
1611 test_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
1616 test_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
1621 test_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
1626 test_expect_success 'no additional info if no stash entries' '
1627 git stash clear &&
1628 git -c status.showStash=true status >actual &&
1629 test_cmp expected_without_stash actual
1632 test_expect_success '"No commits yet" should be noted in status output' '
1633 git checkout --orphan empty-branch-1 &&
1634 git status >output &&
1635 test_grep "No commits yet" output
1638 test_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 &&
1642 test_grep ! "No commits yet" output
1645 test_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 &&
1650 test_grep "Initial commit" output
1653 test_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 &&
1659 test_grep ! "Initial commit" output
1662 test_expect_success '--no-optional-locks prevents index update' '
1663 test_set_magic_mtime .git/index &&
1664 git --no-optional-locks status &&
1665 test_is_magic_mtime .git/index &&
1666 git status &&
1667 ! test_is_magic_mtime .git/index
1670 test_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
1684 test_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
1692 test_expect_success 'setup slow status advice' '
1693 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main git init slowstatus &&
1695 cd slowstatus &&
1696 cat >.gitignore <<-\EOF &&
1697 /actual
1698 /expected
1699 /out
1701 git add .gitignore &&
1702 git commit -m "Add .gitignore" &&
1703 git config advice.statusuoption true
1707 test_expect_success 'slow status advice when core.untrackedCache and fsmonitor are unset' '
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
1716 It took 3.25 seconds to enumerate untracked files.
1717 See '\''git help status'\'' for information on how to improve this.
1719 nothing to commit, working tree clean
1721 test_cmp expected actual
1725 test_expect_success 'slow status advice when core.untrackedCache true, but not fsmonitor' '
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
1734 It took 3.25 seconds to enumerate untracked files.
1735 See '\''git help status'\'' for information on how to improve this.
1737 nothing to commit, working tree clean
1739 test_cmp expected actual
1743 test_expect_success 'slow status advice when core.untrackedCache true, and fsmonitor' '
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
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.
1756 nothing to commit, working tree clean
1758 test_cmp expected actual
1762 test_expect_success EXPENSIVE 'status does not re-read unchanged 4 or 8 GiB file' '
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
1778 test_done