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