1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
6 test_description='git status'
8 . ./test-lib.sh
10 test_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 . &&
21 git status >output &&
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 '
34 test_expect_success 'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
38 '
40 cat > 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)
49 # (use "git checkout -- <file>..." to discard changes in working directory)
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
62 EOF
64 test_expect_success 'status (2)' '
66 git status > output &&
67 test_cmp expect output
69 '
71 cat > expect << \EOF
72 M dir1/modified
73 A dir2/added
74 ?? dir1/untracked
75 ?? dir2/modified
76 ?? dir2/untracked
77 ?? expect
78 ?? output
79 ?? untracked
80 EOF
82 test_expect_success 'status -s (2)' '
84 git status -s > output &&
85 test_cmp expect output
87 '
89 cat >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)
98 # (use "git checkout -- <file>..." to discard changes in working directory)
99 #
100 # modified: dir1/modified
101 #
102 # Untracked files not listed (use -u option to show untracked files)
103 EOF
104 test_expect_success 'status -uno' '
105 mkdir dir3 &&
106 : > dir3/untracked1 &&
107 : > dir3/untracked2 &&
108 git status -uno >output &&
109 test_cmp expect output
110 '
112 test_expect_success 'status (status.showUntrackedFiles no)' '
113 git config status.showuntrackedfiles no
114 git status >output &&
115 test_cmp expect output
116 '
118 cat >expect << EOF
119 M dir1/modified
120 A dir2/added
121 EOF
122 test_expect_success 'status -s -uno' '
123 git config --unset status.showuntrackedfiles
124 git status -s -uno >output &&
125 test_cmp expect output
126 '
128 test_expect_success 'status -s (status.showUntrackedFiles no)' '
129 git config status.showuntrackedfiles no
130 git status -s >output &&
131 test_cmp expect output
132 '
134 cat >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)
143 # (use "git checkout -- <file>..." to discard changes in working directory)
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
157 EOF
158 test_expect_success 'status -unormal' '
159 git status -unormal >output &&
160 test_cmp expect output
161 '
163 test_expect_success 'status (status.showUntrackedFiles normal)' '
164 git config status.showuntrackedfiles normal
165 git status >output &&
166 test_cmp expect output
167 '
169 cat >expect <<EOF
170 M dir1/modified
171 A dir2/added
172 ?? dir1/untracked
173 ?? dir2/modified
174 ?? dir2/untracked
175 ?? dir3/
176 ?? expect
177 ?? output
178 ?? untracked
179 EOF
180 test_expect_success 'status -s -unormal' '
181 git config --unset status.showuntrackedfiles
182 git status -s -unormal >output &&
183 test_cmp expect output
184 '
186 test_expect_success 'status -s (status.showUntrackedFiles normal)' '
187 git config status.showuntrackedfiles normal
188 git status -s >output &&
189 test_cmp expect output
190 '
192 cat >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)
201 # (use "git checkout -- <file>..." to discard changes in working directory)
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
216 EOF
217 test_expect_success 'status -uall' '
218 git status -uall >output &&
219 test_cmp expect output
220 '
221 test_expect_success 'status (status.showUntrackedFiles all)' '
222 git config status.showuntrackedfiles all
223 git status >output &&
224 rm -rf dir3 &&
225 git config --unset status.showuntrackedfiles &&
226 test_cmp expect output
227 '
229 cat >expect <<EOF
230 M dir1/modified
231 A dir2/added
232 ?? dir1/untracked
233 ?? dir2/modified
234 ?? dir2/untracked
235 ?? expect
236 ?? output
237 ?? untracked
238 EOF
239 test_expect_success 'status -s -uall' '
240 git config --unset status.showuntrackedfiles
241 git status -s -uall >output &&
242 test_cmp expect output
243 '
244 test_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 '
252 cat > 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)
261 # (use "git checkout -- <file>..." to discard changes in working directory)
262 #
263 # modified: modified
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
274 EOF
276 test_expect_success 'status with relative paths' '
278 (cd dir1 && git status) > output &&
279 test_cmp expect output
281 '
283 cat > expect << \EOF
284 M modified
285 A ../dir2/added
286 ?? untracked
287 ?? ../dir2/modified
288 ?? ../dir2/untracked
289 ?? ../expect
290 ?? ../output
291 ?? ../untracked
292 EOF
293 test_expect_success 'status -s with relative paths' '
295 (cd dir1 && git status -s) > output &&
296 test_cmp expect output
298 '
300 cat > expect << \EOF
301 M dir1/modified
302 A dir2/added
303 ?? dir1/untracked
304 ?? dir2/modified
305 ?? dir2/untracked
306 ?? expect
307 ?? output
308 ?? untracked
309 EOF
311 test_expect_success 'status --porcelain ignores relative paths setting' '
313 (cd dir1 && git status --porcelain) > output &&
314 test_cmp expect output
316 '
318 cat > expect << \EOF
319 # On branch master
320 # Changes to be committed:
321 # (use "git reset HEAD <file>..." to unstage)
322 #
323 # new file: dir2/added
324 #
325 # Changed but not updated:
326 # (use "git add <file>..." to update what will be committed)
327 # (use "git checkout -- <file>..." to discard changes in working directory)
328 #
329 # modified: dir1/modified
330 #
331 # Untracked files:
332 # (use "git add <file>..." to include in what will be committed)
333 #
334 # dir1/untracked
335 # dir2/modified
336 # dir2/untracked
337 # expect
338 # output
339 # untracked
340 EOF
342 test_expect_success 'status without relative paths' '
344 git config status.relativePaths false
345 (cd dir1 && git status) > output &&
346 test_cmp expect output
348 '
350 cat > expect << \EOF
351 M dir1/modified
352 A dir2/added
353 ?? dir1/untracked
354 ?? dir2/modified
355 ?? dir2/untracked
356 ?? expect
357 ?? output
358 ?? untracked
359 EOF
361 test_expect_success 'status -s without relative paths' '
363 (cd dir1 && git status -s) > output &&
364 test_cmp expect output
366 '
368 cat <<EOF >expect
369 # On branch master
370 # Changes to be committed:
371 # (use "git reset HEAD <file>..." to unstage)
372 #
373 # modified: dir1/modified
374 #
375 # Untracked files:
376 # (use "git add <file>..." to include in what will be committed)
377 #
378 # dir1/untracked
379 # dir2/
380 # expect
381 # output
382 # untracked
383 EOF
384 test_expect_success 'dry-run of partial commit excluding new file in index' '
385 git commit --dry-run dir1/modified >output &&
386 test_cmp expect output
387 '
389 test_expect_success 'setup status submodule summary' '
390 test_create_repo sm && (
391 cd sm &&
392 >foo &&
393 git add foo &&
394 git commit -m "Add foo"
395 ) &&
396 git add sm
397 '
399 cat >expect <<EOF
400 # On branch master
401 # Changes to be committed:
402 # (use "git reset HEAD <file>..." to unstage)
403 #
404 # new file: dir2/added
405 # new file: sm
406 #
407 # Changed but not updated:
408 # (use "git add <file>..." to update what will be committed)
409 # (use "git checkout -- <file>..." to discard changes in working directory)
410 #
411 # modified: dir1/modified
412 #
413 # Untracked files:
414 # (use "git add <file>..." to include in what will be committed)
415 #
416 # dir1/untracked
417 # dir2/modified
418 # dir2/untracked
419 # expect
420 # output
421 # untracked
422 EOF
423 test_expect_success 'status submodule summary is disabled by default' '
424 git status >output &&
425 test_cmp expect output
426 '
428 # we expect the same as the previous test
429 test_expect_success 'status --untracked-files=all does not show submodule' '
430 git status --untracked-files=all >output &&
431 test_cmp expect output
432 '
434 cat >expect <<EOF
435 M dir1/modified
436 A dir2/added
437 A sm
438 ?? dir1/untracked
439 ?? dir2/modified
440 ?? dir2/untracked
441 ?? expect
442 ?? output
443 ?? untracked
444 EOF
445 test_expect_success 'status -s submodule summary is disabled by default' '
446 git status -s >output &&
447 test_cmp expect output
448 '
450 # we expect the same as the previous test
451 test_expect_success 'status -s --untracked-files=all does not show submodule' '
452 git status -s --untracked-files=all >output &&
453 test_cmp expect output
454 '
456 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
458 cat >expect <<EOF
459 # On branch master
460 # Changes to be committed:
461 # (use "git reset HEAD <file>..." to unstage)
462 #
463 # new file: dir2/added
464 # new file: sm
465 #
466 # Changed but not updated:
467 # (use "git add <file>..." to update what will be committed)
468 # (use "git checkout -- <file>..." to discard changes in working directory)
469 #
470 # modified: dir1/modified
471 #
472 # Modified submodules:
473 #
474 # * sm 0000000...$head (1):
475 # > Add foo
476 #
477 # Untracked files:
478 # (use "git add <file>..." to include in what will be committed)
479 #
480 # dir1/untracked
481 # dir2/modified
482 # dir2/untracked
483 # expect
484 # output
485 # untracked
486 EOF
487 test_expect_success 'status submodule summary' '
488 git config status.submodulesummary 10 &&
489 git status >output &&
490 test_cmp expect output
491 '
493 cat >expect <<EOF
494 M dir1/modified
495 A dir2/added
496 A sm
497 ?? dir1/untracked
498 ?? dir2/modified
499 ?? dir2/untracked
500 ?? expect
501 ?? output
502 ?? untracked
503 EOF
504 test_expect_success 'status -s submodule summary' '
505 git status -s >output &&
506 test_cmp expect output
507 '
509 cat >expect <<EOF
510 # On branch master
511 # Changed but not updated:
512 # (use "git add <file>..." to update what will be committed)
513 # (use "git checkout -- <file>..." to discard changes in working directory)
514 #
515 # modified: dir1/modified
516 #
517 # Untracked files:
518 # (use "git add <file>..." to include in what will be committed)
519 #
520 # dir1/untracked
521 # dir2/modified
522 # dir2/untracked
523 # expect
524 # output
525 # untracked
526 no changes added to commit (use "git add" and/or "git commit -a")
527 EOF
528 test_expect_success 'status submodule summary (clean submodule)' '
529 git commit -m "commit submodule" &&
530 git config status.submodulesummary 10 &&
531 test_must_fail git commit --dry-run >output &&
532 test_cmp expect output &&
533 git status >output &&
534 test_cmp expect output
535 '
537 cat >expect <<EOF
538 M dir1/modified
539 ?? dir1/untracked
540 ?? dir2/modified
541 ?? dir2/untracked
542 ?? expect
543 ?? output
544 ?? untracked
545 EOF
546 test_expect_success 'status -s submodule summary (clean submodule)' '
547 git status -s >output &&
548 test_cmp expect output
549 '
551 cat >expect <<EOF
552 # On branch master
553 # Changes to be committed:
554 # (use "git reset HEAD^1 <file>..." to unstage)
555 #
556 # new file: dir2/added
557 # new file: sm
558 #
559 # Changed but not updated:
560 # (use "git add <file>..." to update what will be committed)
561 # (use "git checkout -- <file>..." to discard changes in working directory)
562 #
563 # modified: dir1/modified
564 #
565 # Modified submodules:
566 #
567 # * sm 0000000...$head (1):
568 # > Add foo
569 #
570 # Untracked files:
571 # (use "git add <file>..." to include in what will be committed)
572 #
573 # dir1/untracked
574 # dir2/modified
575 # dir2/untracked
576 # expect
577 # output
578 # untracked
579 EOF
580 test_expect_success 'commit --dry-run submodule summary (--amend)' '
581 git config status.submodulesummary 10 &&
582 git commit --dry-run --amend >output &&
583 test_cmp expect output
584 '
586 test_done