]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7508-status.sh
status: reduce duplicated setup code
[thirdparty/git.git] / t / t7508-status.sh
CommitLineData
367c9886
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
47a528ad 6test_description='git status'
367c9886
JS
7
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 : > tracked &&
12 : > modified &&
13 mkdir dir1 &&
14 : > dir1/tracked &&
15 : > dir1/modified &&
16 mkdir dir2 &&
17 : > dir1/tracked &&
18 : > dir1/modified &&
19 git add . &&
ff58b9aa
JK
20
21 git status >output &&
22
367c9886
JS
23 test_tick &&
24 git commit -m initial &&
25 : > untracked &&
26 : > dir1/untracked &&
27 : > dir2/untracked &&
28 echo 1 > dir1/modified &&
29 echo 2 > dir2/modified &&
30 echo 3 > dir2/added &&
31 git add dir2/added
32'
33
ff58b9aa
JK
34test_expect_success 'status (1)' '
35
aadbe44f 36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
ff58b9aa
JK
37
38'
39
367c9886
JS
40cat > expect << \EOF
41# On branch master
42# Changes to be committed:
43# (use "git reset HEAD <file>..." to unstage)
44#
45# new file: dir2/added
46#
47# Changed but not updated:
48# (use "git add <file>..." to update what will be committed)
4d6e4c4d 49# (use "git checkout -- <file>..." to discard changes in working directory)
367c9886
JS
50#
51# modified: dir1/modified
52#
53# Untracked files:
54# (use "git add <file>..." to include in what will be committed)
55#
56# dir1/untracked
57# dir2/modified
58# dir2/untracked
59# expect
60# output
61# untracked
62EOF
63
ff58b9aa 64test_expect_success 'status (2)' '
367c9886
JS
65
66 git status > output &&
3af82863 67 test_cmp expect output
367c9886
JS
68
69'
70
14ed05dd
MG
71cat > expect << \EOF
72 M dir1/modified
73A dir2/added
74?? dir1/untracked
75?? dir2/modified
76?? dir2/untracked
77?? expect
78?? output
79?? untracked
80EOF
81
82test_expect_success 'status -s (2)' '
83
84 git status -s > output &&
85 test_cmp expect output
86
87'
88
6c2ce048
MSO
89cat >expect <<EOF
90# On branch master
91# Changes to be committed:
92# (use "git reset HEAD <file>..." to unstage)
93#
94# new file: dir2/added
95#
96# Changed but not updated:
97# (use "git add <file>..." to update what will be committed)
4d6e4c4d 98# (use "git checkout -- <file>..." to discard changes in working directory)
6c2ce048
MSO
99#
100# modified: dir1/modified
101#
102# Untracked files not listed (use -u option to show untracked files)
103EOF
104test_expect_success 'status -uno' '
105 mkdir dir3 &&
106 : > dir3/untracked1 &&
107 : > dir3/untracked2 &&
108 git status -uno >output &&
109 test_cmp expect output
110'
111
d6293d1f
MSO
112test_expect_success 'status (status.showUntrackedFiles no)' '
113 git config status.showuntrackedfiles no
114 git status >output &&
115 test_cmp expect output
116'
117
14ed05dd
MG
118cat >expect << EOF
119 M dir1/modified
120A dir2/added
121EOF
122test_expect_success 'status -s -uno' '
123 git config --unset status.showuntrackedfiles
124 git status -s -uno >output &&
125 test_cmp expect output
126'
127
128test_expect_success 'status -s (status.showUntrackedFiles no)' '
129 git config status.showuntrackedfiles no
130 git status -s >output &&
131 test_cmp expect output
132'
133
4bfee30a
MSO
134cat >expect <<EOF
135# On branch master
136# Changes to be committed:
137# (use "git reset HEAD <file>..." to unstage)
138#
139# new file: dir2/added
140#
141# Changed but not updated:
142# (use "git add <file>..." to update what will be committed)
4d6e4c4d 143# (use "git checkout -- <file>..." to discard changes in working directory)
4bfee30a
MSO
144#
145# modified: dir1/modified
146#
147# Untracked files:
148# (use "git add <file>..." to include in what will be committed)
149#
150# dir1/untracked
151# dir2/modified
152# dir2/untracked
153# dir3/
154# expect
155# output
156# untracked
157EOF
158test_expect_success 'status -unormal' '
4bfee30a
MSO
159 git status -unormal >output &&
160 test_cmp expect output
161'
162
d6293d1f
MSO
163test_expect_success 'status (status.showUntrackedFiles normal)' '
164 git config status.showuntrackedfiles normal
165 git status >output &&
166 test_cmp expect output
167'
168
14ed05dd
MG
169cat >expect <<EOF
170 M dir1/modified
171A dir2/added
172?? dir1/untracked
173?? dir2/modified
174?? dir2/untracked
175?? dir3/
176?? expect
177?? output
178?? untracked
179EOF
180test_expect_success 'status -s -unormal' '
181 git config --unset status.showuntrackedfiles
182 git status -s -unormal >output &&
183 test_cmp expect output
184'
185
186test_expect_success 'status -s (status.showUntrackedFiles normal)' '
187 git config status.showuntrackedfiles normal
188 git status -s >output &&
189 test_cmp expect output
190'
191
4bfee30a
MSO
192cat >expect <<EOF
193# On branch master
194# Changes to be committed:
195# (use "git reset HEAD <file>..." to unstage)
196#
197# new file: dir2/added
198#
199# Changed but not updated:
200# (use "git add <file>..." to update what will be committed)
4d6e4c4d 201# (use "git checkout -- <file>..." to discard changes in working directory)
4bfee30a
MSO
202#
203# modified: dir1/modified
204#
205# Untracked files:
206# (use "git add <file>..." to include in what will be committed)
207#
208# dir1/untracked
209# dir2/modified
210# dir2/untracked
211# dir3/untracked1
212# dir3/untracked2
213# expect
214# output
215# untracked
216EOF
217test_expect_success 'status -uall' '
218 git status -uall >output &&
d6293d1f
MSO
219 test_cmp expect output
220'
221test_expect_success 'status (status.showUntrackedFiles all)' '
222 git config status.showuntrackedfiles all
223 git status >output &&
4bfee30a 224 rm -rf dir3 &&
d6293d1f 225 git config --unset status.showuntrackedfiles &&
4bfee30a
MSO
226 test_cmp expect output
227'
228
14ed05dd
MG
229cat >expect <<EOF
230 M dir1/modified
231A dir2/added
232?? dir1/untracked
233?? dir2/modified
234?? dir2/untracked
235?? expect
236?? output
237?? untracked
238EOF
239test_expect_success 'status -s -uall' '
240 git config --unset status.showuntrackedfiles
241 git status -s -uall >output &&
242 test_cmp expect output
243'
244test_expect_success 'status -s (status.showUntrackedFiles all)' '
245 git config status.showuntrackedfiles all
246 git status -s >output &&
247 rm -rf dir3 &&
248 git config --unset status.showuntrackedfiles &&
249 test_cmp expect output
250'
251
367c9886
JS
252cat > expect << \EOF
253# On branch master
254# Changes to be committed:
255# (use "git reset HEAD <file>..." to unstage)
256#
257# new file: ../dir2/added
258#
259# Changed but not updated:
260# (use "git add <file>..." to update what will be committed)
4d6e4c4d 261# (use "git checkout -- <file>..." to discard changes in working directory)
367c9886 262#
69e74918 263# modified: modified
367c9886
JS
264#
265# Untracked files:
266# (use "git add <file>..." to include in what will be committed)
267#
268# untracked
269# ../dir2/modified
270# ../dir2/untracked
271# ../expect
272# ../output
273# ../untracked
274EOF
275
276test_expect_success 'status with relative paths' '
277
278 (cd dir1 && git status) > output &&
3af82863 279 test_cmp expect output
367c9886
JS
280
281'
282
14ed05dd
MG
283cat > expect << \EOF
284 M modified
285A ../dir2/added
286?? untracked
287?? ../dir2/modified
288?? ../dir2/untracked
289?? ../expect
290?? ../output
291?? ../untracked
292EOF
293test_expect_success 'status -s with relative paths' '
294
295 (cd dir1 && git status -s) > output &&
296 test_cmp expect output
297
298'
299
46f721c8
JK
300cat > expect << \EOF
301# On branch master
302# Changes to be committed:
303# (use "git reset HEAD <file>..." to unstage)
304#
305# new file: dir2/added
306#
307# Changed but not updated:
308# (use "git add <file>..." to update what will be committed)
4d6e4c4d 309# (use "git checkout -- <file>..." to discard changes in working directory)
46f721c8
JK
310#
311# modified: dir1/modified
312#
313# Untracked files:
314# (use "git add <file>..." to include in what will be committed)
315#
316# dir1/untracked
317# dir2/modified
318# dir2/untracked
319# expect
320# output
321# untracked
322EOF
323
324test_expect_success 'status without relative paths' '
325
326 git config status.relativePaths false
327 (cd dir1 && git status) > output &&
3af82863 328 test_cmp expect output
46f721c8
JK
329
330'
331
14ed05dd
MG
332cat > expect << \EOF
333 M dir1/modified
334A dir2/added
335?? dir1/untracked
336?? dir2/modified
337?? dir2/untracked
338?? expect
339?? output
340?? untracked
341EOF
342
343test_expect_success 'status -s without relative paths' '
344
345 (cd dir1 && git status -s) > output &&
346 test_cmp expect output
347
348'
349
959ba670
JK
350cat <<EOF >expect
351# On branch master
352# Changes to be committed:
353# (use "git reset HEAD <file>..." to unstage)
354#
355# modified: dir1/modified
356#
357# Untracked files:
358# (use "git add <file>..." to include in what will be committed)
359#
360# dir1/untracked
361# dir2/
362# expect
363# output
364# untracked
365EOF
9e4b7ab6
JH
366test_expect_success 'dry-run of partial commit excluding new file in index' '
367 git commit --dry-run dir1/modified >output &&
82ebb0b6 368 test_cmp expect output
959ba670
JK
369'
370
e5e4a7f2
PY
371test_expect_success 'setup status submodule summary' '
372 test_create_repo sm && (
373 cd sm &&
374 >foo &&
375 git add foo &&
376 git commit -m "Add foo"
377 ) &&
378 git add sm
379'
380
381cat >expect <<EOF
382# On branch master
383# Changes to be committed:
384# (use "git reset HEAD <file>..." to unstage)
385#
386# new file: dir2/added
387# new file: sm
388#
389# Changed but not updated:
390# (use "git add <file>..." to update what will be committed)
4d6e4c4d 391# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
392#
393# modified: dir1/modified
394#
395# Untracked files:
396# (use "git add <file>..." to include in what will be committed)
397#
398# dir1/untracked
399# dir2/modified
400# dir2/untracked
401# expect
402# output
403# untracked
404EOF
405test_expect_success 'status submodule summary is disabled by default' '
406 git status >output &&
407 test_cmp expect output
408'
409
98fa4738
JK
410# we expect the same as the previous test
411test_expect_success 'status --untracked-files=all does not show submodule' '
412 git status --untracked-files=all >output &&
e5e4a7f2
PY
413 test_cmp expect output
414'
415
14ed05dd
MG
416cat >expect <<EOF
417 M dir1/modified
418A dir2/added
419A sm
420?? dir1/untracked
421?? dir2/modified
422?? dir2/untracked
423?? expect
424?? output
425?? untracked
426EOF
427test_expect_success 'status -s submodule summary is disabled by default' '
428 git status -s >output &&
429 test_cmp expect output
430'
431
432# we expect the same as the previous test
433test_expect_success 'status -s --untracked-files=all does not show submodule' '
434 git status -s --untracked-files=all >output &&
435 test_cmp expect output
436'
437
e5e4a7f2
PY
438head=$(cd sm && git rev-parse --short=7 --verify HEAD)
439
440cat >expect <<EOF
441# On branch master
442# Changes to be committed:
443# (use "git reset HEAD <file>..." to unstage)
444#
445# new file: dir2/added
446# new file: sm
447#
448# Changed but not updated:
449# (use "git add <file>..." to update what will be committed)
4d6e4c4d 450# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
451#
452# modified: dir1/modified
453#
454# Modified submodules:
455#
456# * sm 0000000...$head (1):
457# > Add foo
458#
459# Untracked files:
460# (use "git add <file>..." to include in what will be committed)
461#
462# dir1/untracked
463# dir2/modified
464# dir2/untracked
465# expect
466# output
467# untracked
468EOF
469test_expect_success 'status submodule summary' '
470 git config status.submodulesummary 10 &&
471 git status >output &&
472 test_cmp expect output
473'
474
14ed05dd
MG
475cat >expect <<EOF
476 M dir1/modified
477A dir2/added
478A sm
479?? dir1/untracked
480?? dir2/modified
481?? dir2/untracked
482?? expect
483?? output
484?? untracked
485EOF
486test_expect_success 'status -s submodule summary' '
487 git status -s >output &&
488 test_cmp expect output
489'
e5e4a7f2
PY
490
491cat >expect <<EOF
492# On branch master
493# Changed but not updated:
494# (use "git add <file>..." to update what will be committed)
4d6e4c4d 495# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
496#
497# modified: dir1/modified
498#
499# Untracked files:
500# (use "git add <file>..." to include in what will be committed)
501#
502# dir1/untracked
503# dir2/modified
504# dir2/untracked
505# expect
506# output
507# untracked
508no changes added to commit (use "git add" and/or "git commit -a")
509EOF
510test_expect_success 'status submodule summary (clean submodule)' '
511 git commit -m "commit submodule" &&
512 git config status.submodulesummary 10 &&
9e4b7ab6
JH
513 test_must_fail git commit --dry-run >output &&
514 test_cmp expect output &&
515 git status >output &&
e5e4a7f2
PY
516 test_cmp expect output
517'
518
14ed05dd
MG
519cat >expect <<EOF
520 M dir1/modified
521?? dir1/untracked
522?? dir2/modified
523?? dir2/untracked
524?? expect
525?? output
526?? untracked
527EOF
528test_expect_success 'status -s submodule summary (clean submodule)' '
529 git status -s >output &&
530 test_cmp expect output
531'
532
e5e4a7f2
PY
533cat >expect <<EOF
534# On branch master
535# Changes to be committed:
536# (use "git reset HEAD^1 <file>..." to unstage)
537#
538# new file: dir2/added
539# new file: sm
540#
541# Changed but not updated:
542# (use "git add <file>..." to update what will be committed)
4d6e4c4d 543# (use "git checkout -- <file>..." to discard changes in working directory)
e5e4a7f2
PY
544#
545# modified: dir1/modified
546#
547# Modified submodules:
548#
549# * sm 0000000...$head (1):
550# > Add foo
551#
552# Untracked files:
553# (use "git add <file>..." to include in what will be committed)
554#
555# dir1/untracked
556# dir2/modified
557# dir2/untracked
558# expect
559# output
560# untracked
561EOF
9e4b7ab6 562test_expect_success 'commit --dry-run submodule summary (--amend)' '
e5e4a7f2 563 git config status.submodulesummary 10 &&
9e4b7ab6 564 git commit --dry-run --amend >output &&
e5e4a7f2
PY
565 test_cmp expect output
566'
567
367c9886 568test_done