blob: a3c18a4fc2764aa669556fe56961d254727bdab5 [file] [log] [blame]
Johannes Schindelin367c9882007-11-11 17:35:41 +00001#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09006test_description='git status'
Johannes Schindelin367c9882007-11-11 17:35:41 +00007
Rubén Justo80d32e82023-06-17 08:41:54 +02008TEST_PASSES_SANITIZE_LEAK=true
Johannes Schindelin367c9882007-11-11 17:35:41 +00009. ./test-lib.sh
Jeff King01c94e92017-10-03 09:43:29 -040010. "$TEST_DIRECTORY"/lib-terminal.sh
Johannes Schindelin367c9882007-11-11 17:35:41 +000011
Nguyễn Thái Ngọc Duy5d3dd912010-10-22 01:45:47 -050012test_expect_success 'status -h in broken repository' '
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 19:59:16 +070013 git config --global advice.statusuoption false &&
Nguyễn Thái Ngọc Duy5d3dd912010-10-22 01:45:47 -050014 mkdir broken &&
15 test_when_finished "rm -fr broken" &&
16 (
17 cd broken &&
18 git init &&
19 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
20 test_expect_code 129 git status -h >usage 2>&1
21 ) &&
Junio C Hamano67892752023-10-31 14:23:30 +090022 test_grep "[Uu]sage" broken/usage
Nguyễn Thái Ngọc Duy5d3dd912010-10-22 01:45:47 -050023'
24
25test_expect_success 'commit -h in broken repository' '
26 mkdir broken &&
27 test_when_finished "rm -fr broken" &&
28 (
29 cd broken &&
30 git init &&
31 echo "[status] showuntrackedfiles = CORRUPT" >>.git/config &&
32 test_expect_code 129 git commit -h >usage 2>&1
33 ) &&
Junio C Hamano67892752023-10-31 14:23:30 +090034 test_grep "[Uu]sage" broken/usage
Nguyễn Thái Ngọc Duy5d3dd912010-10-22 01:45:47 -050035'
36
Jeff King75177c82017-04-27 05:01:05 -040037test_expect_success 'create upstream branch' '
38 git checkout -b upstream &&
39 test_commit upstream1 &&
40 test_commit upstream2 &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000041 # leave the first commit on main as root because several
Jeff King75177c82017-04-27 05:01:05 -040042 # tests depend on this case; for our upstream we only
43 # care about commit counts anyway, so a totally divergent
44 # history is OK
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000045 git checkout --orphan main
Jeff King75177c82017-04-27 05:01:05 -040046'
47
Johannes Schindelin367c9882007-11-11 17:35:41 +000048test_expect_success 'setup' '
Michael J Gruber68cfc6f2009-12-08 11:12:02 +010049 : >tracked &&
50 : >modified &&
Johannes Schindelin367c9882007-11-11 17:35:41 +000051 mkdir dir1 &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +010052 : >dir1/tracked &&
53 : >dir1/modified &&
Johannes Schindelin367c9882007-11-11 17:35:41 +000054 mkdir dir2 &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +010055 : >dir1/tracked &&
56 : >dir1/modified &&
Johannes Schindelin367c9882007-11-11 17:35:41 +000057 git add . &&
Jeff Kingff58b9a2008-02-12 00:45:18 -050058
59 git status >output &&
60
Johannes Schindelin367c9882007-11-11 17:35:41 +000061 test_tick &&
62 git commit -m initial &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +010063 : >untracked &&
64 : >dir1/untracked &&
65 : >dir2/untracked &&
66 echo 1 >dir1/modified &&
67 echo 2 >dir2/modified &&
68 echo 3 >dir2/added &&
Jeff King75177c82017-04-27 05:01:05 -040069 git add dir2/added &&
70
71 git branch --set-upstream-to=upstream
Johannes Schindelin367c9882007-11-11 17:35:41 +000072'
73
Junio C Hamanocc6658e2011-04-14 13:56:14 -070074test_expect_success 'status (1)' '
Junio C Hamano67892752023-10-31 14:23:30 +090075 test_grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
Jeff Kingff58b9a2008-02-12 00:45:18 -050076'
77
Matthieu Moy2556b992013-09-06 19:43:07 +020078strip_comments () {
Eric Sunshine2e582df2013-09-14 00:47:12 -040079 tab=' '
80 sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp &&
Matthieu Moy2556b992013-09-06 19:43:07 +020081 rm "$1" && mv "$1".tmp "$1"
82}
83
Junio C Hamanoec8a8962015-03-06 10:43:33 +010084cat >.gitignore <<\EOF
85.gitignore
86expect*
87output*
88EOF
89
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +070090test_expect_success 'status --column' '
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +070091 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +000092# On branch main
Jeff King75177c82017-04-27 05:01:05 -040093# Your branch and '\''upstream'\'' have diverged,
94# and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -060095# (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -040096#
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +070097# Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +070098# (use "git restore --staged <file>..." to unstage)
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +070099# new file: dir2/added
100#
101# Changes not staged for commit:
102# (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700103# (use "git restore <file>..." to discard changes in working directory)
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +0700104# modified: dir1/modified
105#
106# Untracked files:
107# (use "git add <file>..." to include in what will be committed)
Junio C Hamanoec8a8962015-03-06 10:43:33 +0100108# dir1/untracked dir2/untracked
109# dir2/modified untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200110#
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +0700111EOF
Matthieu Moy2556b992013-09-06 19:43:07 +0200112 COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100113 test_cmp expect output
Matthieu Moy2556b992013-09-06 19:43:07 +0200114'
115
116test_expect_success 'status --column status.displayCommentPrefix=false' '
117 strip_comments expect &&
118 COLUMNS=49 git -c status.displayCommentPrefix=false status --column="column dense" >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100119 test_cmp expect output
Nguyễn Thái Ngọc Duy323d0532012-04-13 17:54:39 +0700120'
121
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100122cat >expect <<\EOF
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000123# On branch main
Jeff King75177c82017-04-27 05:01:05 -0400124# Your branch and 'upstream' have diverged,
125# and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600126# (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400127#
Johannes Schindelin367c9882007-11-11 17:35:41 +0000128# Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700129# (use "git restore --staged <file>..." to unstage)
Johannes Schindelin367c9882007-11-11 17:35:41 +0000130# new file: dir2/added
131#
Matthieu Moy8009d832010-11-02 16:31:19 +0100132# Changes not staged for commit:
Johannes Schindelin367c9882007-11-11 17:35:41 +0000133# (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700134# (use "git restore <file>..." to discard changes in working directory)
Johannes Schindelin367c9882007-11-11 17:35:41 +0000135# modified: dir1/modified
136#
137# Untracked files:
138# (use "git add <file>..." to include in what will be committed)
Johannes Schindelin367c9882007-11-11 17:35:41 +0000139# dir1/untracked
140# dir2/modified
141# dir2/untracked
Johannes Schindelin367c9882007-11-11 17:35:41 +0000142# untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200143#
Johannes Schindelin367c9882007-11-11 17:35:41 +0000144EOF
145
Matthieu Moy2556b992013-09-06 19:43:07 +0200146test_expect_success 'status with status.displayCommentPrefix=true' '
147 git -c status.displayCommentPrefix=true status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100148 test_cmp expect output
Johannes Schindelin367c9882007-11-11 17:35:41 +0000149'
150
Matthieu Moy2556b992013-09-06 19:43:07 +0200151test_expect_success 'status with status.displayCommentPrefix=false' '
152 strip_comments expect &&
153 git -c status.displayCommentPrefix=false status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100154 test_cmp expect output
Matthieu Moy2556b992013-09-06 19:43:07 +0200155'
156
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100157test_expect_success 'status -v' '
158 (cat expect && git diff --cached) >expect-with-v &&
159 git status -v >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100160 test_cmp expect-with-v output
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100161'
162
Michael J Gruber40555002015-03-06 10:43:35 +0100163test_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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100171 test_cmp expect-with-v output
Michael J Gruber40555002015-03-06 10:43:35 +0100172'
173
Matthieu Moy2556b992013-09-06 19:43:07 +0200174test_expect_success 'setup fake editor' '
175 cat >.git/editor <<-\EOF &&
176 #! /bin/sh
177 cp "$1" output
178EOF
179 chmod 755 .git/editor
180'
181
182commit_template_commented () {
183 (
184 EDITOR=.git/editor &&
185 export EDITOR &&
186 # Fails due to empty message
187 test_must_fail git commit
188 ) &&
189 ! grep '^[^#]' output
190}
191
192test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_EDITMSG' '
193 commit_template_commented
194'
195
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100196cat >expect <<\EOF
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000197On branch main
Jeff King75177c82017-04-27 05:01:05 -0400198Your branch and 'upstream' have diverged,
199and have 1 and 2 different commits each, respectively.
200
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200201Changes to be committed:
202 new file: dir2/added
203
204Changes not staged for commit:
205 modified: dir1/modified
206
207Untracked files:
208 dir1/untracked
209 dir2/modified
210 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200211 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200212
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200213EOF
214
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700215test_expect_success 'status (advice.statusHints false)' '
Yann Droneaudc63659d2013-03-24 22:06:11 +0100216 test_config advice.statusHints false &&
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200217 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100218 test_cmp expect output
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200219
220'
221
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200222cat >expect <<\EOF
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100223 M dir1/modified
224A dir2/added
225?? dir1/untracked
226?? dir2/modified
227?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100228?? untracked
229EOF
230
Michael J Gruber46077fa2010-05-25 16:52:03 +0200231test_expect_success 'status -s' '
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100232
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100233 git status -s >output &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100234 test_cmp expect output
235
236'
237
Junio C Hamano150b4932011-06-02 09:07:11 -0700238test_expect_success 'status with gitignore' '
239 {
240 echo ".gitignore" &&
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100241 echo "expect*" &&
Junio C Hamano150b4932011-06-02 09:07:11 -0700242 echo "output" &&
243 echo "untracked"
244 } >.gitignore &&
245
246 cat >expect <<-\EOF &&
247 M dir1/modified
248 A dir2/added
249 ?? dir2/modified
250 EOF
251 git status -s >output &&
252 test_cmp expect output &&
253
254 cat >expect <<-\EOF &&
255 M dir1/modified
256 A dir2/added
257 ?? dir2/modified
258 !! .gitignore
259 !! dir1/untracked
260 !! dir2/untracked
261 !! expect
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100262 !! expect-with-v
Junio C Hamano150b4932011-06-02 09:07:11 -0700263 !! output
264 !! untracked
265 EOF
266 git status -s --ignored >output &&
267 test_cmp expect output &&
268
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200269 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000270On branch main
Jeff King75177c82017-04-27 05:01:05 -0400271Your branch and '\''upstream'\'' have diverged,
272and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600273 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400274
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200275Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700276 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200277 new file: dir2/added
278
279Changes not staged for commit:
280 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700281 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200282 modified: dir1/modified
283
284Untracked files:
285 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200286 dir2/modified
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200287
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200288Ignored files:
289 (use "git add -f <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200290 .gitignore
291 dir1/untracked
292 dir2/untracked
293 expect
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100294 expect-with-v
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200295 output
296 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200297
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200298EOF
Junio C Hamano150b4932011-06-02 09:07:11 -0700299 git status --ignored >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100300 test_cmp expect output
Junio C Hamano150b4932011-06-02 09:07:11 -0700301'
302
303test_expect_success 'status with gitignore (nothing untracked)' '
304 {
305 echo ".gitignore" &&
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100306 echo "expect*" &&
Junio C Hamano150b4932011-06-02 09:07:11 -0700307 echo "dir2/modified" &&
308 echo "output" &&
309 echo "untracked"
310 } >.gitignore &&
311
312 cat >expect <<-\EOF &&
313 M dir1/modified
314 A dir2/added
315 EOF
316 git status -s >output &&
317 test_cmp expect output &&
318
319 cat >expect <<-\EOF &&
320 M dir1/modified
321 A dir2/added
322 !! .gitignore
323 !! dir1/untracked
324 !! dir2/modified
325 !! dir2/untracked
326 !! expect
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100327 !! expect-with-v
Junio C Hamano150b4932011-06-02 09:07:11 -0700328 !! output
329 !! untracked
330 EOF
331 git status -s --ignored >output &&
332 test_cmp expect output &&
333
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200334 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000335On branch main
Jeff King75177c82017-04-27 05:01:05 -0400336Your branch and '\''upstream'\'' have diverged,
337and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600338 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400339
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200340Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700341 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200342 new file: dir2/added
343
344Changes not staged for commit:
345 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700346 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200347 modified: dir1/modified
348
349Ignored files:
350 (use "git add -f <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200351 .gitignore
352 dir1/untracked
353 dir2/modified
354 dir2/untracked
355 expect
Michael J Gruberf8c65c12015-03-06 10:43:34 +0100356 expect-with-v
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200357 output
358 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200359
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200360EOF
Junio C Hamano150b4932011-06-02 09:07:11 -0700361 git status --ignored >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100362 test_cmp expect output
Junio C Hamano150b4932011-06-02 09:07:11 -0700363'
364
Junio C Hamanoec8a8962015-03-06 10:43:33 +0100365cat >.gitignore <<\EOF
366.gitignore
367expect*
368output*
369EOF
Junio C Hamano150b4932011-06-02 09:07:11 -0700370
Michael J Gruber46077fa2010-05-25 16:52:03 +0200371cat >expect <<\EOF
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000372## main...upstream [ahead 1, behind 2]
Michael J Gruber46077fa2010-05-25 16:52:03 +0200373 M dir1/modified
374A dir2/added
375?? dir1/untracked
376?? dir2/modified
377?? dir2/untracked
Michael J Gruber46077fa2010-05-25 16:52:03 +0200378?? untracked
379EOF
380
381test_expect_success 'status -s -b' '
382
383 git status -s -b >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100384 test_cmp expect output
Michael J Gruber46077fa2010-05-25 16:52:03 +0200385
386'
387
Jeff Kinga5985232012-05-07 17:02:18 -0400388test_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 &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100394 test_cmp expect output
Jeff Kinga5985232012-05-07 17:02:18 -0400395'
396
Ævar Arnfjörð Bjarmason355ec7a2011-02-22 23:42:13 +0000397test_expect_success 'setup dir3' '
398 mkdir dir3 &&
399 : >dir3/untracked1 &&
400 : >dir3/untracked2
401'
402
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700403test_expect_success 'status -uno' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200404 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000405On branch main
Jeff King75177c82017-04-27 05:01:05 -0400406Your branch and '\''upstream'\'' have diverged,
407and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600408 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400409
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200410Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700411 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200412 new file: dir2/added
413
414Changes not staged for commit:
415 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700416 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200417 modified: dir1/modified
418
419Untracked files not listed (use -u option to show untracked files)
420EOF
Marius Storm-Olsen6c2ce042008-06-05 14:22:56 +0200421 git status -uno >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100422 test_cmp expect output
Marius Storm-Olsen6c2ce042008-06-05 14:22:56 +0200423'
424
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700425test_expect_success 'status (status.showUntrackedFiles no)' '
Yann Droneaudc63659d2013-03-24 22:06:11 +0100426 test_config status.showuntrackedfiles no &&
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200427 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100428 test_cmp expect output
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200429'
430
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700431test_expect_success 'status -uno (advice.statusHints false)' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200432 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000433On branch main
Jeff King75177c82017-04-27 05:01:05 -0400434Your branch and '\''upstream'\'' have diverged,
435and have 1 and 2 different commits each, respectively.
436
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200437Changes to be committed:
438 new file: dir2/added
439
440Changes not staged for commit:
441 modified: dir1/modified
442
443Untracked files not listed
444EOF
Yann Droneaudc63659d2013-03-24 22:06:11 +0100445 test_config advice.statusHints false &&
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200446 git status -uno >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100447 test_cmp expect output
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200448'
Michael J Gruber18f3b5a2010-04-22 22:30:19 +0200449
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100450cat >expect << EOF
451 M dir1/modified
452A dir2/added
453EOF
454test_expect_success 'status -s -uno' '
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100455 git status -s -uno >output &&
456 test_cmp expect output
457'
458
459test_expect_success 'status -s (status.showUntrackedFiles no)' '
Jeff King99094a72015-03-20 06:07:15 -0400460 git config status.showuntrackedfiles no &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100461 git status -s >output &&
462 test_cmp expect output
463'
464
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700465test_expect_success 'status -unormal' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200466 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000467On branch main
Jeff King75177c82017-04-27 05:01:05 -0400468Your branch and '\''upstream'\'' have diverged,
469and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600470 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400471
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200472Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700473 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200474 new file: dir2/added
475
476Changes not staged for commit:
477 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700478 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200479 modified: dir1/modified
480
481Untracked files:
482 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200483 dir1/untracked
484 dir2/modified
485 dir2/untracked
486 dir3/
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200487 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200488
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200489EOF
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +0200490 git status -unormal >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100491 test_cmp expect output
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +0200492'
493
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700494test_expect_success 'status (status.showUntrackedFiles normal)' '
Jeff King99094a72015-03-20 06:07:15 -0400495 test_config status.showuntrackedfiles normal &&
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200496 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100497 test_cmp expect output
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200498'
499
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +0200500cat >expect <<EOF
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100501 M dir1/modified
502A dir2/added
503?? dir1/untracked
504?? dir2/modified
505?? dir2/untracked
506?? dir3/
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100507?? untracked
508EOF
509test_expect_success 'status -s -unormal' '
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100510 git status -s -unormal >output &&
511 test_cmp expect output
512'
513
514test_expect_success 'status -s (status.showUntrackedFiles normal)' '
Jeff King99094a72015-03-20 06:07:15 -0400515 git config status.showuntrackedfiles normal &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100516 git status -s >output &&
517 test_cmp expect output
518'
519
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700520test_expect_success 'status -uall' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200521 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000522On branch main
Jeff King75177c82017-04-27 05:01:05 -0400523Your branch and '\''upstream'\'' have diverged,
524and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600525 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400526
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200527Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700528 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200529 new file: dir2/added
530
531Changes not staged for commit:
532 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700533 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200534 modified: dir1/modified
535
536Untracked files:
537 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200538 dir1/untracked
539 dir2/modified
540 dir2/untracked
541 dir3/untracked1
542 dir3/untracked2
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200543 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200544
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200545EOF
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +0200546 git status -uall >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100547 test_cmp expect output
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200548'
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700549
550test_expect_success 'status (status.showUntrackedFiles all)' '
Jeff King99094a72015-03-20 06:07:15 -0400551 test_config status.showuntrackedfiles all &&
Marius Storm-Olsend6293d12008-06-05 14:47:50 +0200552 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100553 test_cmp expect output
Marius Storm-Olsen4bfee302008-06-05 10:31:19 +0200554'
555
Ævar Arnfjörð Bjarmason355ec7a2011-02-22 23:42:13 +0000556test_expect_success 'teardown dir3' '
557 rm -rf dir3
558'
559
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100560cat >expect <<EOF
561 M dir1/modified
562A dir2/added
563?? dir1/untracked
564?? dir2/modified
565?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100566?? untracked
567EOF
568test_expect_success 'status -s -uall' '
Jeff Kinga6a4a882015-03-20 06:10:21 -0400569 test_unconfig status.showuntrackedfiles &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100570 git status -s -uall >output &&
571 test_cmp expect output
572'
573test_expect_success 'status -s (status.showUntrackedFiles all)' '
Yann Droneaudc63659d2013-03-24 22:06:11 +0100574 test_config status.showuntrackedfiles all &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100575 git status -s >output &&
576 rm -rf dir3 &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100577 test_cmp expect output
578'
579
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700580test_expect_success 'status with relative paths' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200581 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000582On branch main
Jeff King75177c82017-04-27 05:01:05 -0400583Your branch and '\''upstream'\'' have diverged,
584and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600585 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400586
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200587Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700588 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200589 new file: ../dir2/added
590
591Changes not staged for commit:
592 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700593 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200594 modified: modified
595
596Untracked files:
597 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200598 untracked
599 ../dir2/modified
600 ../dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200601 ../untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200602
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200603EOF
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100604 (cd dir1 && git status) >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100605 test_cmp expect output
Johannes Schindelin367c9882007-11-11 17:35:41 +0000606'
607
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100608cat >expect <<\EOF
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100609 M modified
610A ../dir2/added
611?? untracked
612?? ../dir2/modified
613?? ../dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100614?? ../untracked
615EOF
616test_expect_success 'status -s with relative paths' '
617
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100618 (cd dir1 && git status -s) >output &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100619 test_cmp expect output
620
621'
622
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100623cat >expect <<\EOF
Michael J Gruberc521bb72009-12-08 11:12:01 +0100624 M dir1/modified
625A dir2/added
626?? dir1/untracked
627?? dir2/modified
628?? dir2/untracked
Michael J Gruberc521bb72009-12-08 11:12:01 +0100629?? untracked
630EOF
631
632test_expect_success 'status --porcelain ignores relative paths setting' '
633
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100634 (cd dir1 && git status --porcelain) >output &&
Michael J Gruberc521bb72009-12-08 11:12:01 +0100635 test_cmp expect output
636
637'
638
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100639test_expect_success 'setup unique colors' '
640
Aleksi Aalto1d282322010-11-18 01:40:05 +0200641 git config status.color.untracked blue &&
Stephen Kent93fdf302017-04-21 22:42:02 -0700642 git config status.color.branch green &&
643 git config status.color.localBranch yellow &&
644 git config status.color.remoteBranch cyan
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100645
646'
647
Jeff King01c94e92017-10-03 09:43:29 -0400648test_expect_success TTY 'status with color.ui' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200649 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000650On branch <GREEN>main<RESET>
Jeff King75177c82017-04-27 05:01:05 -0400651Your branch and '\''upstream'\'' have diverged,
652and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600653 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400654
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200655Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700656 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200657 <GREEN>new file: dir2/added<RESET>
658
659Changes not staged for commit:
660 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700661 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200662 <RED>modified: dir1/modified<RESET>
663
664Untracked files:
665 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200666 <BLUE>dir1/untracked<RESET>
667 <BLUE>dir2/modified<RESET>
668 <BLUE>dir2/untracked<RESET>
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200669 <BLUE>untracked<RESET>
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200670
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200671EOF
Jeff King01c94e92017-10-03 09:43:29 -0400672 test_config color.ui auto &&
673 test_terminal git status | test_decode_color >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100674 test_cmp expect output
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100675'
676
Jeff King01c94e92017-10-03 09:43:29 -0400677test_expect_success TTY 'status with color.status' '
678 test_config color.status auto &&
679 test_terminal git status | test_decode_color >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100680 test_cmp expect output
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100681'
682
683cat >expect <<\EOF
684 <RED>M<RESET> dir1/modified
685<GREEN>A<RESET> dir2/added
686<BLUE>??<RESET> dir1/untracked
687<BLUE>??<RESET> dir2/modified
688<BLUE>??<RESET> dir2/untracked
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100689<BLUE>??<RESET> untracked
690EOF
691
Jeff King01c94e92017-10-03 09:43:29 -0400692test_expect_success TTY 'status -s with color.ui' '
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100693
Jeff King01c94e92017-10-03 09:43:29 -0400694 git config color.ui auto &&
695 test_terminal git status -s | test_decode_color >output &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100696 test_cmp expect output
697
698'
699
Jeff King01c94e92017-10-03 09:43:29 -0400700test_expect_success TTY 'status -s with color.status' '
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100701
702 git config --unset color.ui &&
Jeff King01c94e92017-10-03 09:43:29 -0400703 git config color.status auto &&
704 test_terminal git status -s | test_decode_color >output &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100705 test_cmp expect output
706
707'
708
709cat >expect <<\EOF
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000710## <YELLOW>main<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
Michael J Gruber46077fa2010-05-25 16:52:03 +0200711 <RED>M<RESET> dir1/modified
712<GREEN>A<RESET> dir2/added
713<BLUE>??<RESET> dir1/untracked
714<BLUE>??<RESET> dir2/modified
715<BLUE>??<RESET> dir2/untracked
Michael J Gruber46077fa2010-05-25 16:52:03 +0200716<BLUE>??<RESET> untracked
717EOF
718
Jeff King01c94e92017-10-03 09:43:29 -0400719test_expect_success TTY 'status -s -b with color.status' '
Michael J Gruber46077fa2010-05-25 16:52:03 +0200720
Jeff King01c94e92017-10-03 09:43:29 -0400721 test_terminal git status -s -b | test_decode_color >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100722 test_cmp expect output
Michael J Gruber46077fa2010-05-25 16:52:03 +0200723
724'
725
726cat >expect <<\EOF
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100727 M dir1/modified
728A dir2/added
729?? dir1/untracked
730?? dir2/modified
731?? dir2/untracked
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100732?? untracked
733EOF
734
Jeff King01c94e92017-10-03 09:43:29 -0400735test_expect_success TTY 'status --porcelain ignores color.ui' '
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100736
737 git config --unset color.status &&
Jeff King01c94e92017-10-03 09:43:29 -0400738 git config color.ui auto &&
739 test_terminal git status --porcelain | test_decode_color >output &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100740 test_cmp expect output
741
742'
743
Jeff King01c94e92017-10-03 09:43:29 -0400744test_expect_success TTY 'status --porcelain ignores color.status' '
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100745
746 git config --unset color.ui &&
Jeff King01c94e92017-10-03 09:43:29 -0400747 git config color.status auto &&
748 test_terminal git status --porcelain | test_decode_color >output &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100749 test_cmp expect output
750
751'
752
753# recover unconditionally from color tests
754git config --unset color.status
755git config --unset color.ui
756
Jeff Kingd4a6bf12012-05-07 17:09:04 -0400757test_expect_success 'status --porcelain respects -b' '
Michael J Gruber46077fa2010-05-25 16:52:03 +0200758
759 git status --porcelain -b >output &&
Jeff Kingd4a6bf12012-05-07 17:09:04 -0400760 {
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000761 echo "## main...upstream [ahead 1, behind 2]" &&
Jeff Kingd4a6bf12012-05-07 17:09:04 -0400762 cat expect
763 } >tmp &&
764 mv tmp expect &&
Michael J Gruber46077fa2010-05-25 16:52:03 +0200765 test_cmp expect output
766
767'
768
Jeff King46f721c2007-12-07 16:26:07 -0500769
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100770
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700771test_expect_success 'status without relative paths' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200772 cat >expect <<\EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000773On branch main
Jeff King75177c82017-04-27 05:01:05 -0400774Your branch and '\''upstream'\'' have diverged,
775and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600776 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400777
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200778Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700779 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200780 new file: dir2/added
781
782Changes not staged for commit:
783 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700784 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200785 modified: dir1/modified
786
787Untracked files:
788 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200789 dir1/untracked
790 dir2/modified
791 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200792 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200793
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200794EOF
Yann Droneaudc63659d2013-03-24 22:06:11 +0100795 test_config status.relativePaths false &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100796 (cd dir1 && git status) >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100797 test_cmp expect output
Jeff King46f721c2007-12-07 16:26:07 -0500798
799'
800
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100801cat >expect <<\EOF
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100802 M dir1/modified
803A dir2/added
804?? dir1/untracked
805?? dir2/modified
806?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100807?? untracked
808EOF
809
810test_expect_success 'status -s without relative paths' '
811
Yann Droneaudc63659d2013-03-24 22:06:11 +0100812 test_config status.relativePaths false &&
Michael J Gruber68cfc6f2009-12-08 11:12:02 +0100813 (cd dir1 && git status -s) >output &&
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100814 test_cmp expect output
815
816'
817
Junio C Hamanoa361dd32020-09-10 10:01:57 -0700818cat >expect <<\EOF
819 M dir1/modified
820A dir2/added
821A "file with spaces"
822?? dir1/untracked
823?? dir2/modified
824?? dir2/untracked
825?? "file with spaces 2"
826?? untracked
827EOF
828
829test_expect_success 'status -s without relative paths' '
830 test_when_finished "git rm --cached \"file with spaces\"; rm -f file*" &&
831 >"file with spaces" &&
832 >"file with spaces 2" &&
833 >"expect with spaces" &&
834 git add "file with spaces" &&
835
836 git status -s >output &&
837 test_cmp expect output &&
838
839 git status -s --ignored >output &&
840 grep "^!! \"expect with spaces\"$" output &&
841 grep -v "^!! " output >output-wo-ignored &&
842 test_cmp expect output-wo-ignored
843'
844
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -0700845test_expect_success 'dry-run of partial commit excluding new file in index' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200846 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000847On branch main
Jeff King75177c82017-04-27 05:01:05 -0400848Your branch and '\''upstream'\'' have diverged,
849and have 1 and 2 different commits each, respectively.
Jeff King75177c82017-04-27 05:01:05 -0400850
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200851Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700852 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200853 modified: dir1/modified
854
855Untracked files:
856 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200857 dir1/untracked
858 dir2/
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200859 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200860
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200861EOF
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700862 git commit --dry-run dir1/modified >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100863 test_cmp expect output
Jeff King959ba672008-02-14 12:18:23 -0500864'
865
Markus Heidelberg4c926b32010-04-02 14:27:20 +0200866cat >expect <<EOF
brian m. carlsona5587b82020-07-29 23:14:06 +0000867:100644 100644 $EMPTY_BLOB $ZERO_OID M dir1/modified
Markus Heidelberg4c926b32010-04-02 14:27:20 +0200868EOF
Markus Heidelberg4bb66442010-04-02 23:44:21 +0200869test_expect_success 'status refreshes the index' '
Markus Heidelberg4c926b32010-04-02 14:27:20 +0200870 touch dir2/added &&
871 git status &&
872 git diff-files >output &&
873 test_cmp expect output
874'
875
Jonathan Tanf24c30e2020-09-01 15:28:09 -0700876test_expect_success 'status shows detached HEAD properly after checking out non-local upstream branch' '
877 test_when_finished rm -rf upstream downstream actual &&
878
879 test_create_repo upstream &&
880 test_commit -C upstream foo &&
881
882 git clone upstream downstream &&
883 git -C downstream checkout @{u} &&
884 git -C downstream status >actual &&
Carlo Marcelo Arenas Belón4da8b2f2021-08-01 14:53:00 -0700885 grep -E "HEAD detached at [0-9a-f]+" actual
Jonathan Tanf24c30e2020-09-01 15:28:09 -0700886'
887
Ping Yine5e4a7f2008-04-12 23:05:33 +0800888test_expect_success 'setup status submodule summary' '
889 test_create_repo sm && (
890 cd sm &&
891 >foo &&
892 git add foo &&
893 git commit -m "Add foo"
894 ) &&
895 git add sm
896'
897
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700898test_expect_success 'status submodule summary is disabled by default' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200899 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000900On branch main
Jeff King75177c82017-04-27 05:01:05 -0400901Your branch and '\''upstream'\'' have diverged,
902and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600903 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400904
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200905Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700906 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200907 new file: dir2/added
908 new file: sm
909
910Changes not staged for commit:
911 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700912 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200913 modified: dir1/modified
914
915Untracked files:
916 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200917 dir1/untracked
918 dir2/modified
919 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200920 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200921
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200922EOF
Ping Yine5e4a7f2008-04-12 23:05:33 +0800923 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100924 test_cmp expect output
Ping Yine5e4a7f2008-04-12 23:05:33 +0800925'
926
Jeff King98fa4732008-10-16 11:07:26 -0400927# we expect the same as the previous test
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700928test_expect_success 'status --untracked-files=all does not show submodule' '
Jeff King98fa4732008-10-16 11:07:26 -0400929 git status --untracked-files=all >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100930 test_cmp expect output
Jeff King98fa4732008-10-16 11:07:26 -0400931'
932
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100933cat >expect <<EOF
934 M dir1/modified
935A dir2/added
936A sm
937?? dir1/untracked
938?? dir2/modified
939?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +0100940?? untracked
941EOF
942test_expect_success 'status -s submodule summary is disabled by default' '
943 git status -s >output &&
944 test_cmp expect output
945'
946
947# we expect the same as the previous test
948test_expect_success 'status -s --untracked-files=all does not show submodule' '
949 git status -s --untracked-files=all >output &&
950 test_cmp expect output
951'
952
Ping Yine5e4a7f2008-04-12 23:05:33 +0800953head=$(cd sm && git rev-parse --short=7 --verify HEAD)
954
Junio C Hamanocc6658e2011-04-14 13:56:14 -0700955test_expect_success 'status submodule summary' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200956 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +0000957On branch main
Jeff King75177c82017-04-27 05:01:05 -0400958Your branch and '\''upstream'\'' have diverged,
959and have 1 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -0600960 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -0400961
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200962Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700963 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200964 new file: dir2/added
965 new file: sm
966
967Changes not staged for commit:
968 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +0700969 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200970 modified: dir1/modified
971
972Submodule changes to be committed:
973
974* sm 0000000...$head (1):
975 > Add foo
976
977Untracked files:
978 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200979 dir1/untracked
980 dir2/modified
981 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200982 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +0200983
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200984EOF
Ping Yine5e4a7f2008-04-12 23:05:33 +0800985 git config status.submodulesummary 10 &&
986 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100987 test_cmp expect output
Ping Yine5e4a7f2008-04-12 23:05:33 +0800988'
989
Matthieu Moy2556b992013-09-06 19:43:07 +0200990test_expect_success 'status submodule summary with status.displayCommentPrefix=false' '
991 strip_comments expect &&
992 git -c status.displayCommentPrefix=false status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100993 test_cmp expect output
Matthieu Moy2556b992013-09-06 19:43:07 +0200994'
995
996test_expect_success 'commit with submodule summary ignores status.displayCommentPrefix' '
997 commit_template_commented
998'
999
Michael J Gruber14ed05d2009-11-27 22:29:30 +01001000cat >expect <<EOF
1001 M dir1/modified
1002A dir2/added
1003A sm
1004?? dir1/untracked
1005?? dir2/modified
1006?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +01001007?? untracked
1008EOF
1009test_expect_success 'status -s submodule summary' '
1010 git status -s >output &&
1011 test_cmp expect output
1012'
Ping Yine5e4a7f2008-04-12 23:05:33 +08001013
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001014test_expect_success 'status submodule summary (clean submodule): commit' '
Alex Henrieb6f3da52023-07-12 22:41:13 -06001015 cat >expect-status <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001016On branch main
Jeff King75177c82017-04-27 05:01:05 -04001017Your branch and '\''upstream'\'' have diverged,
1018and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001019 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001020
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001021Changes not staged for commit:
1022 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001023 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001024 modified: dir1/modified
1025
1026Untracked files:
1027 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001028 dir1/untracked
1029 dir2/modified
1030 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001031 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001032
Ping Yine5e4a7f2008-04-12 23:05:33 +08001033no changes added to commit (use "git add" and/or "git commit -a")
1034EOF
Alex Henrieb6f3da52023-07-12 22:41:13 -06001035 sed "/git pull/d" expect-status > expect-commit &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001036 git commit -m "commit submodule" &&
Ping Yine5e4a7f2008-04-12 23:05:33 +08001037 git config status.submodulesummary 10 &&
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -07001038 test_must_fail git commit --dry-run >output &&
Alex Henrieb6f3da52023-07-12 22:41:13 -06001039 test_cmp expect-commit output &&
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -07001040 git status >output &&
Alex Henrieb6f3da52023-07-12 22:41:13 -06001041 test_cmp expect-status output
Ping Yine5e4a7f2008-04-12 23:05:33 +08001042'
1043
1044cat >expect <<EOF
Michael J Gruber14ed05d2009-11-27 22:29:30 +01001045 M dir1/modified
1046?? dir1/untracked
1047?? dir2/modified
1048?? dir2/untracked
Michael J Gruber14ed05d2009-11-27 22:29:30 +01001049?? untracked
1050EOF
1051test_expect_success 'status -s submodule summary (clean submodule)' '
1052 git status -s >output &&
1053 test_cmp expect output
1054'
1055
Brandon Casey000f97b2011-05-26 13:43:21 -07001056test_expect_success 'status -z implies porcelain' '
Brandon Casey95b9f9f2011-05-26 13:43:20 -07001057 git status --porcelain |
Jeff King94221d22013-10-28 21:23:03 -04001058 perl -pe "s/\012/\000/g" >expect &&
Brandon Casey95b9f9f2011-05-26 13:43:20 -07001059 git status -z >output &&
1060 test_cmp expect output
1061'
1062
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001063test_expect_success 'commit --dry-run submodule summary (--amend)' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001064 cat >expect <<EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001065On branch main
Jeff King75177c82017-04-27 05:01:05 -04001066Your branch and '\''upstream'\'' have diverged,
1067and have 2 and 2 different commits each, respectively.
Jeff King75177c82017-04-27 05:01:05 -04001068
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001069Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001070 (use "git restore --source=HEAD^1 --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001071 new file: dir2/added
1072 new file: sm
1073
1074Changes not staged for commit:
1075 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001076 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001077 modified: dir1/modified
1078
1079Submodule changes to be committed:
1080
1081* sm 0000000...$head (1):
1082 > Add foo
1083
1084Untracked files:
1085 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001086 dir1/untracked
1087 dir2/modified
1088 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001089 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001090
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001091EOF
Ping Yine5e4a7f2008-04-12 23:05:33 +08001092 git config status.submodulesummary 10 &&
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -07001093 git commit --dry-run --amend >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001094 test_cmp expect output
Ping Yine5e4a7f2008-04-12 23:05:33 +08001095'
1096
Ævar Arnfjörð Bjarmasonc91cfd12010-08-06 22:09:09 +00001097test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' '
Junio C Hamano03771422018-06-15 11:13:39 -07001098 test_when_finished "chmod 775 .git" &&
Markus Heidelbergb2f6fd92010-04-03 12:11:57 +02001099 (
1100 chmod a-w .git &&
1101 # make dir1/tracked stat-dirty
1102 >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked &&
1103 git status -s >output &&
1104 ! grep dir1/tracked output &&
1105 # make sure "status" succeeded without writing index out
1106 git diff-files | grep dir1/tracked
1107 )
Markus Heidelbergb2f6fd92010-04-03 12:11:57 +02001108'
1109
Jens Lehmannc2e09402010-09-06 20:41:06 +02001110(cd sm && echo > bar && git add bar && git commit -q -m 'Add bar') && git add sm
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001111new_head=$(cd sm && git rev-parse --short=7 --verify HEAD)
1112touch .gitmodules
1113
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001114test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001115 cat > expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001116On branch main
Jeff King75177c82017-04-27 05:01:05 -04001117Your branch and '\''upstream'\'' have diverged,
1118and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001119 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001120
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001121Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001122 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001123 modified: sm
1124
1125Changes not staged for commit:
1126 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001127 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001128 modified: dir1/modified
1129
1130Submodule changes to be committed:
1131
1132* sm $head...$new_head (1):
1133 > Add bar
1134
1135Untracked files:
1136 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001137 .gitmodules
1138 dir1/untracked
1139 dir2/modified
1140 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001141 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001142
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001143EOF
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001144 echo modified sm/untracked &&
1145 git status --ignore-submodules=untracked >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001146 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001147'
1148
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001149test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' '
Yann Droneaudc63659d2013-03-24 22:06:11 +01001150 test_config diff.ignoreSubmodules dirty &&
Jens Lehmann90e14522010-08-06 01:27:15 +02001151 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001152 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001153 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1154 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001155 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001156 test_cmp expect output &&
Yann Droneaudc63659d2013-03-24 22:06:11 +01001157 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001158'
1159
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001160test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001161 git config --add -f .gitmodules submodule.subname.ignore none &&
1162 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001163 git config --add submodule.subname.ignore untracked &&
1164 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001165 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001166 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001167 git config --remove-section submodule.subname &&
1168 git config --remove-section -f .gitmodules submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001169'
1170
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001171test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' '
1172 git status --ignore-submodules=dirty >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001173 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001174'
1175
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001176test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' '
Yann Droneaudc63659d2013-03-24 22:06:11 +01001177 test_config diff.ignoreSubmodules dirty &&
Jens Lehmann90e14522010-08-06 01:27:15 +02001178 git status >output &&
1179 ! test -s actual &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001180 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1181 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001182 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001183 test_cmp expect output &&
Yann Droneaudc63659d2013-03-24 22:06:11 +01001184 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001185'
1186
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001187test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001188 git config --add -f .gitmodules submodule.subname.ignore none &&
1189 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001190 git config --add submodule.subname.ignore dirty &&
1191 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001192 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001193 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001194 git config --remove-section submodule.subname &&
1195 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001196'
1197
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001198test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' '
1199 echo modified >sm/foo &&
1200 git status --ignore-submodules=dirty >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001201 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001202'
1203
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001204test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001205 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1206 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001207 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001208 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001209 git config -f .gitmodules --remove-section submodule.subname
1210'
1211
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001212test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001213 git config --add -f .gitmodules submodule.subname.ignore none &&
1214 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001215 git config --add submodule.subname.ignore dirty &&
1216 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001217 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001218 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001219 git config --remove-section submodule.subname &&
1220 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001221'
1222
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001223test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001224 cat > expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001225On branch main
Jeff King75177c82017-04-27 05:01:05 -04001226Your branch and '\''upstream'\'' have diverged,
1227and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001228 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001229
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001230Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001231 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001232 modified: sm
1233
1234Changes not staged for commit:
1235 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001236 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001237 (commit or discard the untracked or modified content in submodules)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001238 modified: dir1/modified
1239 modified: sm (modified content)
1240
1241Submodule changes to be committed:
1242
1243* sm $head...$new_head (1):
1244 > Add bar
1245
1246Untracked files:
1247 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001248 .gitmodules
1249 dir1/untracked
1250 dir2/modified
1251 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001252 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001253
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001254EOF
Jens Lehmann46a958b2010-06-25 16:56:47 +02001255 git status --ignore-submodules=untracked > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001256 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001257'
1258
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001259test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001260 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1261 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001262 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001263 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001264 git config -f .gitmodules --remove-section submodule.subname
1265'
1266
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001267test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001268 git config --add -f .gitmodules submodule.subname.ignore none &&
1269 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001270 git config --add submodule.subname.ignore untracked &&
1271 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001272 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001273 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001274 git config --remove-section submodule.subname &&
1275 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001276'
1277
Jens Lehmann46a958b2010-06-25 16:56:47 +02001278head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD)
1279
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001280test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001281 cat > expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001282On branch main
Jeff King75177c82017-04-27 05:01:05 -04001283Your branch and '\''upstream'\'' have diverged,
1284and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001285 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001286
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001287Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001288 (use "git restore --staged <file>..." to unstage)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001289 modified: sm
1290
1291Changes not staged for commit:
1292 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001293 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001294 modified: dir1/modified
1295 modified: sm (new commits)
1296
1297Submodule changes to be committed:
1298
1299* sm $head...$new_head (1):
1300 > Add bar
1301
1302Submodules changed but not updated:
1303
1304* sm $new_head...$head2 (1):
1305 > 2nd commit
1306
1307Untracked files:
1308 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001309 .gitmodules
1310 dir1/untracked
1311 dir2/modified
1312 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001313 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001314
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001315EOF
Jens Lehmann46a958b2010-06-25 16:56:47 +02001316 git status --ignore-submodules=untracked > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001317 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001318'
1319
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001320test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001321 git config --add -f .gitmodules submodule.subname.ignore untracked &&
1322 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001323 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001324 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001325 git config -f .gitmodules --remove-section submodule.subname
1326'
1327
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001328test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001329 git config --add -f .gitmodules submodule.subname.ignore none &&
1330 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001331 git config --add submodule.subname.ignore untracked &&
1332 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001333 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001334 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001335 git config --remove-section submodule.subname &&
1336 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001337'
1338
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001339test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" '
Jens Lehmann46a958b2010-06-25 16:56:47 +02001340 git status --ignore-submodules=dirty > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001341 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001342'
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001343test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001344 git config --add -f .gitmodules submodule.subname.ignore dirty &&
1345 git config --add -f .gitmodules submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001346 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001347 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001348 git config -f .gitmodules --remove-section submodule.subname
1349'
Jens Lehmann46a958b2010-06-25 16:56:47 +02001350
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001351test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001352 git config --add -f .gitmodules submodule.subname.ignore none &&
1353 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001354 git config --add submodule.subname.ignore dirty &&
1355 git config --add submodule.subname.path sm &&
Junio C Hamanocc6658e2011-04-14 13:56:14 -07001356 git status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001357 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001358 git config --remove-section submodule.subname &&
1359 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001360'
1361
Jens Lehmann46a958b2010-06-25 16:56:47 +02001362cat > expect << EOF
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001363; On branch main
Jeff King75177c82017-04-27 05:01:05 -04001364; Your branch and 'upstream' have diverged,
1365; and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001366; (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001367;
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001368; Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001369; (use "git restore --staged <file>..." to unstage)
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001370; modified: sm
1371;
1372; Changes not staged for commit:
1373; (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001374; (use "git restore <file>..." to discard changes in working directory)
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001375; modified: dir1/modified
1376; modified: sm (new commits)
1377;
1378; Submodule changes to be committed:
1379;
1380; * sm $head...$new_head (1):
1381; > Add bar
1382;
1383; Submodules changed but not updated:
1384;
1385; * sm $new_head...$head2 (1):
1386; > 2nd commit
1387;
1388; Untracked files:
1389; (use "git add <file>..." to include in what will be committed)
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001390; .gitmodules
1391; dir1/untracked
1392; dir2/modified
1393; dir2/untracked
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001394; untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001395;
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001396EOF
1397
1398test_expect_success "status (core.commentchar with submodule summary)" '
Yann Droneaudc63659d2013-03-24 22:06:11 +01001399 test_config core.commentchar ";" &&
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001400 git -c status.displayCommentPrefix=true status >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001401 test_cmp expect output
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001402'
1403
1404test_expect_success "status (core.commentchar with two chars with submodule summary)" '
Yann Droneaudc63659d2013-03-24 22:06:11 +01001405 test_config core.commentchar ";;" &&
Nguyễn Thái Ngọc Duy50b54fd2014-05-17 08:52:22 +07001406 test_must_fail git -c status.displayCommentPrefix=true status
Junio C Hamanoeff80a92013-01-16 20:18:48 +01001407'
1408
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001409test_expect_success "--ignore-submodules=all suppresses submodule summary" '
1410 cat > expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001411On branch main
Jeff King75177c82017-04-27 05:01:05 -04001412Your branch and '\''upstream'\'' have diverged,
1413and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001414 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001415
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001416Changes not staged for commit:
1417 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001418 (use "git restore <file>..." to discard changes in working directory)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001419 modified: dir1/modified
1420
1421Untracked files:
1422 (use "git add <file>..." to include in what will be committed)
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001423 .gitmodules
1424 dir1/untracked
1425 dir2/modified
1426 dir2/untracked
Matthieu Moy1c7969c2013-09-06 19:43:08 +02001427 untracked
Matthieu Moy2f0f7f12013-09-06 19:43:09 +02001428
Jens Lehmann46a958b2010-06-25 16:56:47 +02001429no changes added to commit (use "git add" and/or "git commit -a")
1430EOF
Jens Lehmann46a958b2010-06-25 16:56:47 +02001431 git status --ignore-submodules=all > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001432 test_cmp expect output
Jens Lehmann46a958b2010-06-25 16:56:47 +02001433'
1434
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001435test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
1436 cat > expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001437On branch main
Jeff King75177c82017-04-27 05:01:05 -04001438Your branch and '\''upstream'\'' have diverged,
1439and have 2 and 2 different commits each, respectively.
Alex Henried92304f2023-07-12 22:41:14 -06001440 (use "git pull" if you want to integrate the remote branch with yours)
Jeff King75177c82017-04-27 05:01:05 -04001441
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001442Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001443 (use "git restore --staged <file>..." to unstage)
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001444 modified: sm
1445
1446Changes not staged for commit:
1447 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001448 (use "git restore <file>..." to discard changes in working directory)
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001449 modified: dir1/modified
1450
1451Untracked files:
1452 (use "git add <file>..." to include in what will be committed)
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001453 .gitmodules
1454 dir1/untracked
1455 dir2/modified
1456 dir2/untracked
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001457 untracked
1458
1459EOF
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001460 git config --add -f .gitmodules submodule.subname.ignore all &&
1461 git config --add -f .gitmodules submodule.subname.path sm &&
1462 git status > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001463 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001464 git config -f .gitmodules --remove-section submodule.subname
1465'
1466
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001467test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' '
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001468 git config --add -f .gitmodules submodule.subname.ignore none &&
1469 git config --add -f .gitmodules submodule.subname.path sm &&
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001470 git config --add submodule.subname.ignore all &&
1471 git config --add submodule.subname.path sm &&
1472 git status > output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001473 test_cmp expect output &&
Jens Lehmann302ad7a2010-08-06 00:40:48 +02001474 git config --remove-section submodule.subname &&
1475 git config -f .gitmodules --remove-section submodule.subname
Jens Lehmannaee9c7d2010-08-06 00:39:25 +02001476'
1477
Jorge Juan Garcia Garcia4fb51662013-06-11 15:34:04 +02001478test_expect_success 'setup of test environment' '
1479 git config status.showUntrackedFiles no &&
1480 git status -s >expected_short &&
1481 git status --no-short >expected_noshort
1482'
1483
1484test_expect_success '"status.short=true" same as "-s"' '
1485 git -c status.short=true status >actual &&
1486 test_cmp expected_short actual
1487'
1488
1489test_expect_success '"status.short=true" weaker than "--no-short"' '
1490 git -c status.short=true status --no-short >actual &&
1491 test_cmp expected_noshort actual
1492'
1493
1494test_expect_success '"status.short=false" same as "--no-short"' '
1495 git -c status.short=false status >actual &&
1496 test_cmp expected_noshort actual
1497'
1498
1499test_expect_success '"status.short=false" weaker than "-s"' '
1500 git -c status.short=false status -s >actual &&
1501 test_cmp expected_short actual
1502'
1503
Jorge Juan Garcia Garciaec85d072013-06-11 15:34:05 +02001504test_expect_success '"status.branch=true" same as "-b"' '
1505 git status -sb >expected_branch &&
1506 git -c status.branch=true status -s >actual &&
1507 test_cmp expected_branch actual
1508'
1509
1510test_expect_success '"status.branch=true" different from "--no-branch"' '
1511 git status -s --no-branch >expected_nobranch &&
1512 git -c status.branch=true status -s >actual &&
Denton Liue8a5f072020-04-20 04:54:41 -04001513 ! test_cmp expected_nobranch actual
Jorge Juan Garcia Garciaec85d072013-06-11 15:34:05 +02001514'
1515
1516test_expect_success '"status.branch=true" weaker than "--no-branch"' '
1517 git -c status.branch=true status -s --no-branch >actual &&
1518 test_cmp expected_nobranch actual
1519'
1520
Junio C Hamano84b42022013-06-24 11:41:40 -07001521test_expect_success '"status.branch=true" weaker than "--porcelain"' '
John Caia6171e12023-05-20 16:13:52 +00001522 git -c status.branch=true status --porcelain >actual &&
1523 test_cmp expected_nobranch actual
Junio C Hamano84b42022013-06-24 11:41:40 -07001524'
1525
Jorge Juan Garcia Garciaec85d072013-06-11 15:34:05 +02001526test_expect_success '"status.branch=false" same as "--no-branch"' '
1527 git -c status.branch=false status -s >actual &&
1528 test_cmp expected_nobranch actual
1529'
1530
1531test_expect_success '"status.branch=false" weaker than "-b"' '
1532 git -c status.branch=false status -sb >actual &&
1533 test_cmp expected_branch actual
1534'
1535
Jorge Juan Garcia Garcia4fb51662013-06-11 15:34:04 +02001536test_expect_success 'Restore default test environment' '
1537 git config --unset status.showUntrackedFiles
1538'
1539
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001540test_expect_success 'git commit will commit a staged but ignored submodule' '
1541 git config --add -f .gitmodules submodule.subname.ignore all &&
1542 git config --add -f .gitmodules submodule.subname.path sm &&
1543 git config --add submodule.subname.ignore all &&
1544 git status -s --ignore-submodules=dirty >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001545 test_grep "^M. sm" output &&
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001546 GIT_EDITOR="echo hello >>\"\$1\"" &&
1547 export GIT_EDITOR &&
1548 git commit -uno &&
1549 git status -s --ignore-submodules=dirty >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001550 test_grep ! "^M. sm" output
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001551'
1552
1553test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
1554 git reset HEAD^ &&
1555 git add sm &&
1556 cat >expect << EOF &&
Johannes Schindelin1e2ae142020-11-18 23:44:40 +00001557On branch main
Jeff King75177c82017-04-27 05:01:05 -04001558Your branch and '\''upstream'\'' have diverged,
1559and have 2 and 2 different commits each, respectively.
Jeff King75177c82017-04-27 05:01:05 -04001560
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001561Changes to be committed:
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001562 (use "git restore --staged <file>..." to unstage)
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001563 modified: sm
1564
1565Changes not staged for commit:
1566 (use "git add <file>..." to update what will be committed)
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +07001567 (use "git restore <file>..." to discard changes in working directory)
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001568 modified: dir1/modified
1569
1570Untracked files not listed (use -u option to show untracked files)
1571EOF
1572 git commit -uno --dry-run >output &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +01001573 test_cmp expect output &&
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001574 git status -s --ignore-submodules=dirty >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001575 test_grep "^M. sm" output
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001576'
1577
Jens Lehmannc215d3d2014-04-05 18:59:36 +02001578test_expect_success 'git commit -m will commit a staged but ignored submodule' '
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001579 git commit -uno -m message &&
1580 git status -s --ignore-submodules=dirty >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001581 test_grep ! "^M. sm" output &&
Jens Lehmann1d2f3932014-04-05 18:59:03 +02001582 git config --remove-section submodule.subname &&
1583 git config -f .gitmodules --remove-section submodule.subname
1584'
1585
Liam Beguinc1b5d012017-06-17 18:30:51 -04001586test_expect_success 'show stash info with "--show-stash"' '
1587 git reset --hard &&
1588 git stash clear &&
1589 echo 1 >file &&
1590 git add file &&
1591 git stash &&
1592 git status >expected_default &&
1593 git status --show-stash >expected_with_stash &&
Junio C Hamano67892752023-10-31 14:23:30 +09001594 test_grep "^Your stash currently has 1 entry$" expected_with_stash
Liam Beguinc1b5d012017-06-17 18:30:51 -04001595'
1596
1597test_expect_success 'no stash info with "--show-stash --no-show-stash"' '
1598 git status --show-stash --no-show-stash >expected_without_stash &&
1599 test_cmp expected_default expected_without_stash
1600'
1601
1602test_expect_success '"status.showStash=false" weaker than "--show-stash"' '
1603 git -c status.showStash=false status --show-stash >actual &&
1604 test_cmp expected_with_stash actual
1605'
1606
1607test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' '
1608 git -c status.showStash=true status --no-show-stash >actual &&
1609 test_cmp expected_without_stash actual
1610'
1611
Elijah Newren4dc8b1c2019-11-05 17:07:25 +00001612test_expect_success 'no additional info if no stash entries' '
Liam Beguinc1b5d012017-06-17 18:30:51 -04001613 git stash clear &&
1614 git -c status.showStash=true status >actual &&
1615 test_cmp expected_without_stash actual
1616'
1617
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +05301618test_expect_success '"No commits yet" should be noted in status output' '
1619 git checkout --orphan empty-branch-1 &&
1620 git status >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001621 test_grep "No commits yet" output
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +05301622'
1623
1624test_expect_success '"No commits yet" should not be noted in status output' '
1625 git checkout --orphan empty-branch-2 &&
1626 test_commit test-commit-1 &&
1627 git status >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001628 test_grep ! "No commits yet" output
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +05301629'
1630
1631test_expect_success '"Initial commit" should be noted in commit template' '
1632 git checkout --orphan empty-branch-3 &&
1633 touch to_be_committed_1 &&
1634 git add to_be_committed_1 &&
1635 git commit --dry-run >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001636 test_grep "Initial commit" output
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +05301637'
1638
1639test_expect_success '"Initial commit" should not be noted in commit template' '
1640 git checkout --orphan empty-branch-4 &&
1641 test_commit test-commit-2 &&
1642 touch to_be_committed_2 &&
1643 git add to_be_committed_2 &&
1644 git commit --dry-run >output &&
Junio C Hamano67892752023-10-31 14:23:30 +09001645 test_grep ! "Initial commit" output
Kaartic Sivaraam4ddb1352017-06-21 23:46:14 +05301646'
1647
Jeff King27344d62017-09-27 02:54:30 -04001648test_expect_success '--no-optional-locks prevents index update' '
Marc Strapetz0275e4d2022-01-07 11:17:29 +00001649 test_set_magic_mtime .git/index &&
Jeff King27344d62017-09-27 02:54:30 -04001650 git --no-optional-locks status &&
Marc Strapetz0275e4d2022-01-07 11:17:29 +00001651 test_is_magic_mtime .git/index &&
Jeff King27344d62017-09-27 02:54:30 -04001652 git status &&
Marc Strapetz0275e4d2022-01-07 11:17:29 +00001653 ! test_is_magic_mtime .git/index
Jeff King27344d62017-09-27 02:54:30 -04001654'
1655
Marc Strapetz9b71efd2022-01-07 11:17:30 +00001656test_expect_success 'racy timestamps will be fixed for clean worktree' '
1657 echo content >racy-dirty &&
1658 echo content >racy-racy &&
1659 git add racy* &&
1660 git commit -m "racy test files" &&
1661 # let status rewrite the index, if necessary; after that we expect
1662 # no more index writes unless caused by racy timestamps; note that
1663 # timestamps may already be racy now (depending on previous tests)
1664 git status &&
1665 test_set_magic_mtime .git/index &&
1666 git status &&
1667 ! test_is_magic_mtime .git/index
1668'
1669
1670test_expect_success 'racy timestamps will be fixed for dirty worktree' '
1671 echo content2 >racy-dirty &&
1672 git status &&
1673 test_set_magic_mtime .git/index &&
1674 git status &&
1675 ! test_is_magic_mtime .git/index
1676'
1677
Rudy Rigotecbc23e2022-11-30 00:52:16 +00001678test_expect_success 'setup slow status advice' '
1679 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main git init slowstatus &&
1680 (
1681 cd slowstatus &&
1682 cat >.gitignore <<-\EOF &&
1683 /actual
1684 /expected
1685 /out
1686 EOF
1687 git add .gitignore &&
1688 git commit -m "Add .gitignore" &&
1689 git config advice.statusuoption true
1690 )
1691'
1692
1693test_expect_success 'slow status advice when core.untrackedCache and fsmonitor are unset' '
1694 (
1695 cd slowstatus &&
1696 git config core.untrackedCache false &&
1697 git config core.fsmonitor false &&
1698 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1699 cat >expected <<-\EOF &&
1700 On branch main
1701
1702 It took 3.25 seconds to enumerate untracked files.
1703 See '\''git help status'\'' for information on how to improve this.
1704
1705 nothing to commit, working tree clean
1706 EOF
1707 test_cmp expected actual
1708 )
1709'
1710
1711test_expect_success 'slow status advice when core.untrackedCache true, but not fsmonitor' '
1712 (
1713 cd slowstatus &&
1714 git config core.untrackedCache true &&
1715 git config core.fsmonitor false &&
1716 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1717 cat >expected <<-\EOF &&
1718 On branch main
1719
1720 It took 3.25 seconds to enumerate untracked files.
1721 See '\''git help status'\'' for information on how to improve this.
1722
1723 nothing to commit, working tree clean
1724 EOF
1725 test_cmp expected actual
1726 )
1727'
1728
1729test_expect_success 'slow status advice when core.untrackedCache true, and fsmonitor' '
1730 (
1731 cd slowstatus &&
1732 git config core.untrackedCache true &&
1733 git config core.fsmonitor true &&
1734 GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
1735 cat >expected <<-\EOF &&
1736 On branch main
1737
1738 It took 3.25 seconds to enumerate untracked files,
1739 but the results were cached, and subsequent runs may be faster.
1740 See '\''git help status'\'' for information on how to improve this.
1741
1742 nothing to commit, working tree clean
1743 EOF
1744 test_cmp expected actual
1745 )
1746'
1747
Jason Hatton5143ac02023-10-12 16:09:30 +00001748test_expect_success EXPENSIVE 'status does not re-read unchanged 4 or 8 GiB file' '
1749 (
1750 mkdir large-file &&
1751 cd large-file &&
1752 # Files are 2 GiB, 4 GiB, and 8 GiB sparse files.
1753 test-tool truncate file-a 0x080000000 &&
1754 test-tool truncate file-b 0x100000000 &&
1755 test-tool truncate file-c 0x200000000 &&
1756 # This will be slow.
1757 git add file-a file-b file-c &&
1758 git commit -m "add large files" &&
1759 git diff-index HEAD file-a file-b file-c >actual &&
1760 test_must_be_empty actual
1761 )
1762'
1763
Johannes Schindelin367c9882007-11-11 17:35:41 +00001764test_done