1#!/bin/sh
2#
3# Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4# Thomas Nguy, Khoi Nguyen
5# Grenoble INP Ensimag
6#
7
8test_description='git status advice'
9
10. ./test-lib.sh
11
12. "$TEST_DIRECTORY"/lib-rebase.sh
13
14set_fake_editor
15
16test_expect_success 'prepare for conflicts' '
17 git config --global advice.statusuoption false &&
18 test_commit init main.txt init &&
19 git branch conflicts &&
20 test_commit on_master main.txt on_master &&
21 git checkout conflicts &&
22 test_commit on_conflicts main.txt on_conflicts
23'
24
25
26test_expect_success 'status when conflicts unresolved' '
27 test_must_fail git merge master &&
28 cat >expected <<\EOF &&
29On branch conflicts
30You have unmerged paths.
31 (fix conflicts and run "git commit")
32 (use "git merge --abort" to abort the merge)
33
34Unmerged paths:
35 (use "git add <file>..." to mark resolution)
36 both modified: main.txt
37
38no changes added to commit (use "git add" and/or "git commit -a")
39EOF
40 git status --untracked-files=no >actual &&
41 test_i18ncmp expected actual
42'
43
44
45test_expect_success 'status when conflicts resolved before commit' '
46 git reset --hard conflicts &&
47 test_must_fail git merge master &&
48 echo one >main.txt &&
49 git add main.txt &&
50 cat >expected <<\EOF &&
51On branch conflicts
52All conflicts fixed but you are still merging.
53 (use "git commit" to conclude merge)
54
55Changes to be committed:
56 modified: main.txt
57
58Untracked files not listed (use -u option to show untracked files)
59EOF
60 git status --untracked-files=no >actual &&
61 test_i18ncmp expected actual
62'
63
64
65test_expect_success 'prepare for rebase conflicts' '
66 git reset --hard master &&
67 git checkout -b rebase_conflicts &&
68 test_commit one_rebase main.txt one &&
69 test_commit two_rebase main.txt two &&
70 test_commit three_rebase main.txt three
71'
72
73
74test_expect_success 'status when rebase in progress before resolving conflicts' '
75 test_when_finished "git rebase --abort" &&
76 ONTO=$(git rev-parse --short HEAD^^) &&
77 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
78 cat >expected <<EOF &&
79rebase in progress; onto $ONTO
80You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
81 (fix conflicts and then run "git rebase --continue")
82 (use "git rebase --skip" to skip this patch)
83 (use "git rebase --abort" to check out the original branch)
84
85Unmerged paths:
86 (use "git restore --staged <file>..." to unstage)
87 (use "git add <file>..." to mark resolution)
88 both modified: main.txt
89
90no changes added to commit (use "git add" and/or "git commit -a")
91EOF
92 git status --untracked-files=no >actual &&
93 test_i18ncmp expected actual
94'
95
96
97test_expect_success 'status when rebase in progress before rebase --continue' '
98 git reset --hard rebase_conflicts &&
99 test_when_finished "git rebase --abort" &&
100 ONTO=$(git rev-parse --short HEAD^^) &&
101 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
102 echo three >main.txt &&
103 git add main.txt &&
104 cat >expected <<EOF &&
105rebase in progress; onto $ONTO
106You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
107 (all conflicts fixed: run "git rebase --continue")
108
109Changes to be committed:
110 (use "git restore --staged <file>..." to unstage)
111 modified: main.txt
112
113Untracked files not listed (use -u option to show untracked files)
114EOF
115 git status --untracked-files=no >actual &&
116 test_i18ncmp expected actual
117'
118
119
120test_expect_success 'prepare for rebase_i_conflicts' '
121 git reset --hard master &&
122 git checkout -b rebase_i_conflicts &&
123 test_commit one_unmerge main.txt one_unmerge &&
124 git branch rebase_i_conflicts_second &&
125 test_commit one_master main.txt one_master &&
126 git checkout rebase_i_conflicts_second &&
127 test_commit one_second main.txt one_second
128'
129
130
131test_expect_success 'status during rebase -i when conflicts unresolved' '
132 test_when_finished "git rebase --abort" &&
133 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
134 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
135 test_must_fail git rebase -i rebase_i_conflicts &&
136 cat >expected <<EOF &&
137interactive rebase in progress; onto $ONTO
138Last command done (1 command done):
139 pick $LAST_COMMIT one_second
140No commands remaining.
141You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
142 (fix conflicts and then run "git rebase --continue")
143 (use "git rebase --skip" to skip this patch)
144 (use "git rebase --abort" to check out the original branch)
145
146Unmerged paths:
147 (use "git restore --staged <file>..." to unstage)
148 (use "git add <file>..." to mark resolution)
149 both modified: main.txt
150
151no changes added to commit (use "git add" and/or "git commit -a")
152EOF
153 git status --untracked-files=no >actual &&
154 test_i18ncmp expected actual
155'
156
157
158test_expect_success 'status during rebase -i after resolving conflicts' '
159 git reset --hard rebase_i_conflicts_second &&
160 test_when_finished "git rebase --abort" &&
161 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
162 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
163 test_must_fail git rebase -i rebase_i_conflicts &&
164 git add main.txt &&
165 cat >expected <<EOF &&
166interactive rebase in progress; onto $ONTO
167Last command done (1 command done):
168 pick $LAST_COMMIT one_second
169No commands remaining.
170You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
171 (all conflicts fixed: run "git rebase --continue")
172
173Changes to be committed:
174 (use "git restore --staged <file>..." to unstage)
175 modified: main.txt
176
177Untracked files not listed (use -u option to show untracked files)
178EOF
179 git status --untracked-files=no >actual &&
180 test_i18ncmp expected actual
181'
182
183
184test_expect_success 'status when rebasing -i in edit mode' '
185 git reset --hard master &&
186 git checkout -b rebase_i_edit &&
187 test_commit one_rebase_i main.txt one &&
188 test_commit two_rebase_i main.txt two &&
189 COMMIT2=$(git rev-parse --short rebase_i_edit) &&
190 test_commit three_rebase_i main.txt three &&
191 COMMIT3=$(git rev-parse --short rebase_i_edit) &&
192 FAKE_LINES="1 edit 2" &&
193 export FAKE_LINES &&
194 test_when_finished "git rebase --abort" &&
195 ONTO=$(git rev-parse --short HEAD~2) &&
196 git rebase -i HEAD~2 &&
197 cat >expected <<EOF &&
198interactive rebase in progress; onto $ONTO
199Last commands done (2 commands done):
200 pick $COMMIT2 two_rebase_i
201 edit $COMMIT3 three_rebase_i
202No commands remaining.
203You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
204 (use "git commit --amend" to amend the current commit)
205 (use "git rebase --continue" once you are satisfied with your changes)
206
207nothing to commit (use -u to show untracked files)
208EOF
209 git status --untracked-files=no >actual &&
210 test_i18ncmp expected actual
211'
212
213
214test_expect_success 'status when splitting a commit' '
215 git reset --hard master &&
216 git checkout -b split_commit &&
217 test_commit one_split main.txt one &&
218 test_commit two_split main.txt two &&
219 COMMIT2=$(git rev-parse --short split_commit) &&
220 test_commit three_split main.txt three &&
221 COMMIT3=$(git rev-parse --short split_commit) &&
222 test_commit four_split main.txt four &&
223 COMMIT4=$(git rev-parse --short split_commit) &&
224 FAKE_LINES="1 edit 2 3" &&
225 export FAKE_LINES &&
226 test_when_finished "git rebase --abort" &&
227 ONTO=$(git rev-parse --short HEAD~3) &&
228 git rebase -i HEAD~3 &&
229 git reset HEAD^ &&
230 cat >expected <<EOF &&
231interactive rebase in progress; onto $ONTO
232Last commands done (2 commands done):
233 pick $COMMIT2 two_split
234 edit $COMMIT3 three_split
235Next command to do (1 remaining command):
236 pick $COMMIT4 four_split
237 (use "git rebase --edit-todo" to view and edit)
238You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
239 (Once your working directory is clean, run "git rebase --continue")
240
241Changes not staged for commit:
242 (use "git add <file>..." to update what will be committed)
243 (use "git restore <file>..." to discard changes in working directory)
244 modified: main.txt
245
246no changes added to commit (use "git add" and/or "git commit -a")
247EOF
248 git status --untracked-files=no >actual &&
249 test_i18ncmp expected actual
250'
251
252
253test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
254 git reset --hard master &&
255 git checkout -b amend_last &&
256 test_commit one_amend main.txt one &&
257 test_commit two_amend main.txt two &&
258 test_commit three_amend main.txt three &&
259 COMMIT3=$(git rev-parse --short amend_last) &&
260 test_commit four_amend main.txt four &&
261 COMMIT4=$(git rev-parse --short amend_last) &&
262 FAKE_LINES="1 2 edit 3" &&
263 export FAKE_LINES &&
264 test_when_finished "git rebase --abort" &&
265 ONTO=$(git rev-parse --short HEAD~3) &&
266 git rebase -i HEAD~3 &&
267 git commit --amend -m "foo" &&
268 cat >expected <<EOF &&
269interactive rebase in progress; onto $ONTO
270Last commands done (3 commands done):
271 pick $COMMIT3 three_amend
272 edit $COMMIT4 four_amend
273 (see more in file .git/rebase-merge/done)
274No commands remaining.
275You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
276 (use "git commit --amend" to amend the current commit)
277 (use "git rebase --continue" once you are satisfied with your changes)
278
279nothing to commit (use -u to show untracked files)
280EOF
281 git status --untracked-files=no >actual &&
282 test_i18ncmp expected actual
283'
284
285
286test_expect_success 'prepare for several edits' '
287 git reset --hard master &&
288 git checkout -b several_edits &&
289 test_commit one_edits main.txt one &&
290 test_commit two_edits main.txt two &&
291 test_commit three_edits main.txt three &&
292 test_commit four_edits main.txt four
293'
294
295
296test_expect_success 'status: (continue first edit) second edit' '
297 FAKE_LINES="edit 1 edit 2 3" &&
298 export FAKE_LINES &&
299 test_when_finished "git rebase --abort" &&
300 COMMIT2=$(git rev-parse --short several_edits^^) &&
301 COMMIT3=$(git rev-parse --short several_edits^) &&
302 COMMIT4=$(git rev-parse --short several_edits) &&
303 ONTO=$(git rev-parse --short HEAD~3) &&
304 git rebase -i HEAD~3 &&
305 git rebase --continue &&
306 cat >expected <<EOF &&
307interactive rebase in progress; onto $ONTO
308Last commands done (2 commands done):
309 edit $COMMIT2 two_edits
310 edit $COMMIT3 three_edits
311Next command to do (1 remaining command):
312 pick $COMMIT4 four_edits
313 (use "git rebase --edit-todo" to view and edit)
314You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
315 (use "git commit --amend" to amend the current commit)
316 (use "git rebase --continue" once you are satisfied with your changes)
317
318nothing to commit (use -u to show untracked files)
319EOF
320 git status --untracked-files=no >actual &&
321 test_i18ncmp expected actual
322'
323
324
325test_expect_success 'status: (continue first edit) second edit and split' '
326 git reset --hard several_edits &&
327 FAKE_LINES="edit 1 edit 2 3" &&
328 export FAKE_LINES &&
329 test_when_finished "git rebase --abort" &&
330 COMMIT2=$(git rev-parse --short several_edits^^) &&
331 COMMIT3=$(git rev-parse --short several_edits^) &&
332 COMMIT4=$(git rev-parse --short several_edits) &&
333 ONTO=$(git rev-parse --short HEAD~3) &&
334 git rebase -i HEAD~3 &&
335 git rebase --continue &&
336 git reset HEAD^ &&
337 cat >expected <<EOF &&
338interactive rebase in progress; onto $ONTO
339Last commands done (2 commands done):
340 edit $COMMIT2 two_edits
341 edit $COMMIT3 three_edits
342Next command to do (1 remaining command):
343 pick $COMMIT4 four_edits
344 (use "git rebase --edit-todo" to view and edit)
345You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
346 (Once your working directory is clean, run "git rebase --continue")
347
348Changes not staged for commit:
349 (use "git add <file>..." to update what will be committed)
350 (use "git restore <file>..." to discard changes in working directory)
351 modified: main.txt
352
353no changes added to commit (use "git add" and/or "git commit -a")
354EOF
355 git status --untracked-files=no >actual &&
356 test_i18ncmp expected actual
357'
358
359
360test_expect_success 'status: (continue first edit) second edit and amend' '
361 git reset --hard several_edits &&
362 FAKE_LINES="edit 1 edit 2 3" &&
363 export FAKE_LINES &&
364 test_when_finished "git rebase --abort" &&
365 COMMIT2=$(git rev-parse --short several_edits^^) &&
366 COMMIT3=$(git rev-parse --short several_edits^) &&
367 COMMIT4=$(git rev-parse --short several_edits) &&
368 ONTO=$(git rev-parse --short HEAD~3) &&
369 git rebase -i HEAD~3 &&
370 git rebase --continue &&
371 git commit --amend -m "foo" &&
372 cat >expected <<EOF &&
373interactive rebase in progress; onto $ONTO
374Last commands done (2 commands done):
375 edit $COMMIT2 two_edits
376 edit $COMMIT3 three_edits
377Next command to do (1 remaining command):
378 pick $COMMIT4 four_edits
379 (use "git rebase --edit-todo" to view and edit)
380You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
381 (use "git commit --amend" to amend the current commit)
382 (use "git rebase --continue" once you are satisfied with your changes)
383
384nothing to commit (use -u to show untracked files)
385EOF
386 git status --untracked-files=no >actual &&
387 test_i18ncmp expected actual
388'
389
390
391test_expect_success 'status: (amend first edit) second edit' '
392 git reset --hard several_edits &&
393 FAKE_LINES="edit 1 edit 2 3" &&
394 export FAKE_LINES &&
395 test_when_finished "git rebase --abort" &&
396 COMMIT2=$(git rev-parse --short several_edits^^) &&
397 COMMIT3=$(git rev-parse --short several_edits^) &&
398 COMMIT4=$(git rev-parse --short several_edits) &&
399 ONTO=$(git rev-parse --short HEAD~3) &&
400 git rebase -i HEAD~3 &&
401 git commit --amend -m "a" &&
402 git rebase --continue &&
403 cat >expected <<EOF &&
404interactive rebase in progress; onto $ONTO
405Last commands done (2 commands done):
406 edit $COMMIT2 two_edits
407 edit $COMMIT3 three_edits
408Next command to do (1 remaining command):
409 pick $COMMIT4 four_edits
410 (use "git rebase --edit-todo" to view and edit)
411You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
412 (use "git commit --amend" to amend the current commit)
413 (use "git rebase --continue" once you are satisfied with your changes)
414
415nothing to commit (use -u to show untracked files)
416EOF
417 git status --untracked-files=no >actual &&
418 test_i18ncmp expected actual
419'
420
421
422test_expect_success 'status: (amend first edit) second edit and split' '
423 git reset --hard several_edits &&
424 FAKE_LINES="edit 1 edit 2 3" &&
425 export FAKE_LINES &&
426 test_when_finished "git rebase --abort" &&
427 ONTO=$(git rev-parse --short HEAD~3) &&
428 COMMIT2=$(git rev-parse --short several_edits^^) &&
429 COMMIT3=$(git rev-parse --short several_edits^) &&
430 COMMIT4=$(git rev-parse --short several_edits) &&
431 git rebase -i HEAD~3 &&
432 git commit --amend -m "b" &&
433 git rebase --continue &&
434 git reset HEAD^ &&
435 cat >expected <<EOF &&
436interactive rebase in progress; onto $ONTO
437Last commands done (2 commands done):
438 edit $COMMIT2 two_edits
439 edit $COMMIT3 three_edits
440Next command to do (1 remaining command):
441 pick $COMMIT4 four_edits
442 (use "git rebase --edit-todo" to view and edit)
443You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
444 (Once your working directory is clean, run "git rebase --continue")
445
446Changes not staged for commit:
447 (use "git add <file>..." to update what will be committed)
448 (use "git restore <file>..." to discard changes in working directory)
449 modified: main.txt
450
451no changes added to commit (use "git add" and/or "git commit -a")
452EOF
453 git status --untracked-files=no >actual &&
454 test_i18ncmp expected actual
455'
456
457
458test_expect_success 'status: (amend first edit) second edit and amend' '
459 git reset --hard several_edits &&
460 FAKE_LINES="edit 1 edit 2 3" &&
461 export FAKE_LINES &&
462 test_when_finished "git rebase --abort" &&
463 COMMIT2=$(git rev-parse --short several_edits^^) &&
464 COMMIT3=$(git rev-parse --short several_edits^) &&
465 COMMIT4=$(git rev-parse --short several_edits) &&
466 ONTO=$(git rev-parse --short HEAD~3) &&
467 git rebase -i HEAD~3 &&
468 git commit --amend -m "c" &&
469 git rebase --continue &&
470 git commit --amend -m "d" &&
471 cat >expected <<EOF &&
472interactive rebase in progress; onto $ONTO
473Last commands done (2 commands done):
474 edit $COMMIT2 two_edits
475 edit $COMMIT3 three_edits
476Next command to do (1 remaining command):
477 pick $COMMIT4 four_edits
478 (use "git rebase --edit-todo" to view and edit)
479You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
480 (use "git commit --amend" to amend the current commit)
481 (use "git rebase --continue" once you are satisfied with your changes)
482
483nothing to commit (use -u to show untracked files)
484EOF
485 git status --untracked-files=no >actual &&
486 test_i18ncmp expected actual
487'
488
489
490test_expect_success 'status: (split first edit) second edit' '
491 git reset --hard several_edits &&
492 FAKE_LINES="edit 1 edit 2 3" &&
493 export FAKE_LINES &&
494 test_when_finished "git rebase --abort" &&
495 COMMIT2=$(git rev-parse --short several_edits^^) &&
496 COMMIT3=$(git rev-parse --short several_edits^) &&
497 COMMIT4=$(git rev-parse --short several_edits) &&
498 ONTO=$(git rev-parse --short HEAD~3) &&
499 git rebase -i HEAD~3 &&
500 git reset HEAD^ &&
501 git add main.txt &&
502 git commit -m "e" &&
503 git rebase --continue &&
504 cat >expected <<EOF &&
505interactive rebase in progress; onto $ONTO
506Last commands done (2 commands done):
507 edit $COMMIT2 two_edits
508 edit $COMMIT3 three_edits
509Next command to do (1 remaining command):
510 pick $COMMIT4 four_edits
511 (use "git rebase --edit-todo" to view and edit)
512You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
513 (use "git commit --amend" to amend the current commit)
514 (use "git rebase --continue" once you are satisfied with your changes)
515
516nothing to commit (use -u to show untracked files)
517EOF
518 git status --untracked-files=no >actual &&
519 test_i18ncmp expected actual
520'
521
522
523test_expect_success 'status: (split first edit) second edit and split' '
524 git reset --hard several_edits &&
525 FAKE_LINES="edit 1 edit 2 3" &&
526 export FAKE_LINES &&
527 test_when_finished "git rebase --abort" &&
528 COMMIT2=$(git rev-parse --short several_edits^^) &&
529 COMMIT3=$(git rev-parse --short several_edits^) &&
530 COMMIT4=$(git rev-parse --short several_edits) &&
531 ONTO=$(git rev-parse --short HEAD~3) &&
532 git rebase -i HEAD~3 &&
533 git reset HEAD^ &&
534 git add main.txt &&
535 git commit --amend -m "f" &&
536 git rebase --continue &&
537 git reset HEAD^ &&
538 cat >expected <<EOF &&
539interactive rebase in progress; onto $ONTO
540Last commands done (2 commands done):
541 edit $COMMIT2 two_edits
542 edit $COMMIT3 three_edits
543Next command to do (1 remaining command):
544 pick $COMMIT4 four_edits
545 (use "git rebase --edit-todo" to view and edit)
546You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
547 (Once your working directory is clean, run "git rebase --continue")
548
549Changes not staged for commit:
550 (use "git add <file>..." to update what will be committed)
551 (use "git restore <file>..." to discard changes in working directory)
552 modified: main.txt
553
554no changes added to commit (use "git add" and/or "git commit -a")
555EOF
556 git status --untracked-files=no >actual &&
557 test_i18ncmp expected actual
558'
559
560
561test_expect_success 'status: (split first edit) second edit and amend' '
562 git reset --hard several_edits &&
563 FAKE_LINES="edit 1 edit 2 3" &&
564 export FAKE_LINES &&
565 test_when_finished "git rebase --abort" &&
566 COMMIT2=$(git rev-parse --short several_edits^^) &&
567 COMMIT3=$(git rev-parse --short several_edits^) &&
568 COMMIT4=$(git rev-parse --short several_edits) &&
569 ONTO=$(git rev-parse --short HEAD~3) &&
570 git rebase -i HEAD~3 &&
571 git reset HEAD^ &&
572 git add main.txt &&
573 git commit --amend -m "g" &&
574 git rebase --continue &&
575 git commit --amend -m "h" &&
576 cat >expected <<EOF &&
577interactive rebase in progress; onto $ONTO
578Last commands done (2 commands done):
579 edit $COMMIT2 two_edits
580 edit $COMMIT3 three_edits
581Next command to do (1 remaining command):
582 pick $COMMIT4 four_edits
583 (use "git rebase --edit-todo" to view and edit)
584You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
585 (use "git commit --amend" to amend the current commit)
586 (use "git rebase --continue" once you are satisfied with your changes)
587
588nothing to commit (use -u to show untracked files)
589EOF
590 git status --untracked-files=no >actual &&
591 test_i18ncmp expected actual
592'
593
594
595test_expect_success 'prepare am_session' '
596 git reset --hard master &&
597 git checkout -b am_session &&
598 test_commit one_am one.txt "one" &&
599 test_commit two_am two.txt "two" &&
600 test_commit three_am three.txt "three"
601'
602
603
604test_expect_success 'status in an am session: file already exists' '
605 git checkout -b am_already_exists &&
606 test_when_finished "rm Maildir/* && git am --abort" &&
607 git format-patch -1 -oMaildir &&
608 test_must_fail git am Maildir/*.patch &&
609 cat >expected <<\EOF &&
610On branch am_already_exists
611You are in the middle of an am session.
612 (fix conflicts and then run "git am --continue")
613 (use "git am --skip" to skip this patch)
614 (use "git am --abort" to restore the original branch)
615
616nothing to commit (use -u to show untracked files)
617EOF
618 git status --untracked-files=no >actual &&
619 test_i18ncmp expected actual
620'
621
622
623test_expect_success 'status in an am session: file does not exist' '
624 git reset --hard am_session &&
625 git checkout -b am_not_exists &&
626 git rm three.txt &&
627 git commit -m "delete three.txt" &&
628 test_when_finished "rm Maildir/* && git am --abort" &&
629 git format-patch -1 -oMaildir &&
630 test_must_fail git am Maildir/*.patch &&
631 cat >expected <<\EOF &&
632On branch am_not_exists
633You are in the middle of an am session.
634 (fix conflicts and then run "git am --continue")
635 (use "git am --skip" to skip this patch)
636 (use "git am --abort" to restore the original branch)
637
638nothing to commit (use -u to show untracked files)
639EOF
640 git status --untracked-files=no >actual &&
641 test_i18ncmp expected actual
642'
643
644
645test_expect_success 'status in an am session: empty patch' '
646 git reset --hard am_session &&
647 git checkout -b am_empty &&
648 test_when_finished "rm Maildir/* && git am --abort" &&
649 git format-patch -3 -oMaildir &&
650 git rm one.txt two.txt three.txt &&
651 git commit -m "delete all am_empty" &&
652 echo error >Maildir/0002-two_am.patch &&
653 test_must_fail git am Maildir/*.patch &&
654 cat >expected <<\EOF &&
655On branch am_empty
656You are in the middle of an am session.
657The current patch is empty.
658 (use "git am --skip" to skip this patch)
659 (use "git am --abort" to restore the original branch)
660
661nothing to commit (use -u to show untracked files)
662EOF
663 git status --untracked-files=no >actual &&
664 test_i18ncmp expected actual
665'
666
667
668test_expect_success 'status when bisecting' '
669 git reset --hard master &&
670 git checkout -b bisect &&
671 test_commit one_bisect main.txt one &&
672 test_commit two_bisect main.txt two &&
673 test_commit three_bisect main.txt three &&
674 test_when_finished "git bisect reset" &&
675 git bisect start &&
676 git bisect bad &&
677 git bisect good one_bisect &&
678 TGT=$(git rev-parse --short two_bisect) &&
679 cat >expected <<EOF &&
680HEAD detached at $TGT
681You are currently bisecting, started from branch '\''bisect'\''.
682 (use "git bisect reset" to get back to the original branch)
683
684nothing to commit (use -u to show untracked files)
685EOF
686 git status --untracked-files=no >actual &&
687 test_i18ncmp expected actual
688'
689
690
691test_expect_success 'status when rebase conflicts with statushints disabled' '
692 git reset --hard master &&
693 git checkout -b statushints_disabled &&
694 test_when_finished "git config --local advice.statushints true" &&
695 git config --local advice.statushints false &&
696 test_commit one_statushints main.txt one &&
697 test_commit two_statushints main.txt two &&
698 test_commit three_statushints main.txt three &&
699 test_when_finished "git rebase --abort" &&
700 ONTO=$(git rev-parse --short HEAD^^) &&
701 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
702 cat >expected <<EOF &&
703rebase in progress; onto $ONTO
704You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
705
706Unmerged paths:
707 both modified: main.txt
708
709no changes added to commit
710EOF
711 git status --untracked-files=no >actual &&
712 test_i18ncmp expected actual
713'
714
715
716test_expect_success 'prepare for cherry-pick conflicts' '
717 git reset --hard master &&
718 git checkout -b cherry_branch &&
719 test_commit one_cherry main.txt one &&
720 test_commit two_cherries main.txt two &&
721 git checkout -b cherry_branch_second &&
722 test_commit second_cherry main.txt second &&
723 git checkout cherry_branch &&
724 test_commit three_cherries main.txt three
725'
726
727
728test_expect_success 'status when cherry-picking before resolving conflicts' '
729 test_when_finished "git cherry-pick --abort" &&
730 test_must_fail git cherry-pick cherry_branch_second &&
731 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
732 cat >expected <<EOF &&
733On branch cherry_branch
734You are currently cherry-picking commit $TO_CHERRY_PICK.
735 (fix conflicts and run "git cherry-pick --continue")
736 (use "git cherry-pick --skip" to skip this patch)
737 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
738
739Unmerged paths:
740 (use "git add <file>..." to mark resolution)
741 both modified: main.txt
742
743no changes added to commit (use "git add" and/or "git commit -a")
744EOF
745 git status --untracked-files=no >actual &&
746 test_i18ncmp expected actual
747'
748
749
750test_expect_success 'status when cherry-picking after resolving conflicts' '
751 git reset --hard cherry_branch &&
752 test_when_finished "git cherry-pick --abort" &&
753 test_must_fail git cherry-pick cherry_branch_second &&
754 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
755 echo end >main.txt &&
756 git add main.txt &&
757 cat >expected <<EOF &&
758On branch cherry_branch
759You are currently cherry-picking commit $TO_CHERRY_PICK.
760 (all conflicts fixed: run "git cherry-pick --continue")
761 (use "git cherry-pick --skip" to skip this patch)
762 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
763
764Changes to be committed:
765 modified: main.txt
766
767Untracked files not listed (use -u option to show untracked files)
768EOF
769 git status --untracked-files=no >actual &&
770 test_i18ncmp expected actual
771'
772
773test_expect_success 'status when cherry-picking after committing conflict resolution' '
774 git reset --hard cherry_branch &&
775 test_when_finished "git cherry-pick --abort" &&
776 test_must_fail git cherry-pick cherry_branch_second one_cherry &&
777 echo end >main.txt &&
778 git commit -a &&
779 cat >expected <<EOF &&
780On branch cherry_branch
781Cherry-pick currently in progress.
782 (run "git cherry-pick --continue" to continue)
783 (use "git cherry-pick --skip" to skip this patch)
784 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
785
786nothing to commit (use -u to show untracked files)
787EOF
788 git status --untracked-files=no >actual &&
789 test_i18ncmp expected actual
790'
791
792test_expect_success 'status shows cherry-pick with invalid oid' '
793 mkdir .git/sequencer &&
794 test_write_lines "pick invalid-oid" >.git/sequencer/todo &&
795 git status --untracked-files=no >actual 2>err &&
796 git cherry-pick --quit &&
797 test_must_be_empty err &&
798 test_i18ncmp expected actual
799'
800
801test_expect_success 'status does not show error if .git/sequencer is a file' '
802 test_when_finished "rm .git/sequencer" &&
803 test_write_lines hello >.git/sequencer &&
804 git status --untracked-files=no 2>err &&
805 test_must_be_empty err
806'
807
808test_expect_success 'status showing detached at and from a tag' '
809 test_commit atag tagging &&
810 git checkout atag &&
811 cat >expected <<\EOF &&
812HEAD detached at atag
813nothing to commit (use -u to show untracked files)
814EOF
815 git status --untracked-files=no >actual &&
816 test_i18ncmp expected actual &&
817
818 git reset --hard HEAD^ &&
819 cat >expected <<\EOF &&
820HEAD detached from atag
821nothing to commit (use -u to show untracked files)
822EOF
823 git status --untracked-files=no >actual &&
824 test_i18ncmp expected actual
825'
826
827test_expect_success 'status while reverting commit (conflicts)' '
828 git checkout master &&
829 echo before >to-revert.txt &&
830 test_commit before to-revert.txt &&
831 echo old >to-revert.txt &&
832 test_commit old to-revert.txt &&
833 echo new >to-revert.txt &&
834 test_commit new to-revert.txt &&
835 TO_REVERT=$(git rev-parse --short HEAD^) &&
836 test_must_fail git revert $TO_REVERT &&
837 cat >expected <<EOF &&
838On branch master
839You are currently reverting commit $TO_REVERT.
840 (fix conflicts and run "git revert --continue")
841 (use "git revert --skip" to skip this patch)
842 (use "git revert --abort" to cancel the revert operation)
843
844Unmerged paths:
845 (use "git restore --staged <file>..." to unstage)
846 (use "git add <file>..." to mark resolution)
847 both modified: to-revert.txt
848
849no changes added to commit (use "git add" and/or "git commit -a")
850EOF
851 git status --untracked-files=no >actual &&
852 test_i18ncmp expected actual
853'
854
855test_expect_success 'status while reverting commit (conflicts resolved)' '
856 echo reverted >to-revert.txt &&
857 git add to-revert.txt &&
858 cat >expected <<EOF &&
859On branch master
860You are currently reverting commit $TO_REVERT.
861 (all conflicts fixed: run "git revert --continue")
862 (use "git revert --skip" to skip this patch)
863 (use "git revert --abort" to cancel the revert operation)
864
865Changes to be committed:
866 (use "git restore --staged <file>..." to unstage)
867 modified: to-revert.txt
868
869Untracked files not listed (use -u option to show untracked files)
870EOF
871 git status --untracked-files=no >actual &&
872 test_i18ncmp expected actual
873'
874
875test_expect_success 'status after reverting commit' '
876 git revert --continue &&
877 cat >expected <<\EOF &&
878On branch master
879nothing to commit (use -u to show untracked files)
880EOF
881 git status --untracked-files=no >actual &&
882 test_i18ncmp expected actual
883'
884
885test_expect_success 'status while reverting after committing conflict resolution' '
886 test_when_finished "git revert --abort" &&
887 git reset --hard new &&
888 test_must_fail git revert old new &&
889 echo reverted >to-revert.txt &&
890 git commit -a &&
891 cat >expected <<EOF &&
892On branch master
893Revert currently in progress.
894 (run "git revert --continue" to continue)
895 (use "git revert --skip" to skip this patch)
896 (use "git revert --abort" to cancel the revert operation)
897
898nothing to commit (use -u to show untracked files)
899EOF
900 git status --untracked-files=no >actual &&
901 test_i18ncmp expected actual
902'
903
904test_expect_success 'prepare for different number of commits rebased' '
905 git reset --hard master &&
906 git checkout -b several_commits &&
907 test_commit one_commit main.txt one &&
908 test_commit two_commit main.txt two &&
909 test_commit three_commit main.txt three &&
910 test_commit four_commit main.txt four
911'
912
913test_expect_success 'status: one command done nothing remaining' '
914 FAKE_LINES="exec_exit_15" &&
915 export FAKE_LINES &&
916 test_when_finished "git rebase --abort" &&
917 ONTO=$(git rev-parse --short HEAD~3) &&
918 test_must_fail git rebase -i HEAD~3 &&
919 cat >expected <<EOF &&
920interactive rebase in progress; onto $ONTO
921Last command done (1 command done):
922 exec exit 15
923No commands remaining.
924You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
925 (use "git commit --amend" to amend the current commit)
926 (use "git rebase --continue" once you are satisfied with your changes)
927
928nothing to commit (use -u to show untracked files)
929EOF
930 git status --untracked-files=no >actual &&
931 test_i18ncmp expected actual
932'
933
934test_expect_success 'status: two commands done with some white lines in done file' '
935 FAKE_LINES="1 > exec_exit_15 2 3" &&
936 export FAKE_LINES &&
937 test_when_finished "git rebase --abort" &&
938 ONTO=$(git rev-parse --short HEAD~3) &&
939 COMMIT4=$(git rev-parse --short HEAD) &&
940 COMMIT3=$(git rev-parse --short HEAD^) &&
941 COMMIT2=$(git rev-parse --short HEAD^^) &&
942 test_must_fail git rebase -i HEAD~3 &&
943 cat >expected <<EOF &&
944interactive rebase in progress; onto $ONTO
945Last commands done (2 commands done):
946 pick $COMMIT2 two_commit
947 exec exit 15
948Next commands to do (2 remaining commands):
949 pick $COMMIT3 three_commit
950 pick $COMMIT4 four_commit
951 (use "git rebase --edit-todo" to view and edit)
952You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
953 (use "git commit --amend" to amend the current commit)
954 (use "git rebase --continue" once you are satisfied with your changes)
955
956nothing to commit (use -u to show untracked files)
957EOF
958 git status --untracked-files=no >actual &&
959 test_i18ncmp expected actual
960'
961
962test_expect_success 'status: two remaining commands with some white lines in todo file' '
963 FAKE_LINES="1 2 exec_exit_15 3 > 4" &&
964 export FAKE_LINES &&
965 test_when_finished "git rebase --abort" &&
966 ONTO=$(git rev-parse --short HEAD~4) &&
967 COMMIT4=$(git rev-parse --short HEAD) &&
968 COMMIT3=$(git rev-parse --short HEAD^) &&
969 COMMIT2=$(git rev-parse --short HEAD^^) &&
970 test_must_fail git rebase -i HEAD~4 &&
971 cat >expected <<EOF &&
972interactive rebase in progress; onto $ONTO
973Last commands done (3 commands done):
974 pick $COMMIT2 two_commit
975 exec exit 15
976 (see more in file .git/rebase-merge/done)
977Next commands to do (2 remaining commands):
978 pick $COMMIT3 three_commit
979 pick $COMMIT4 four_commit
980 (use "git rebase --edit-todo" to view and edit)
981You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
982 (use "git commit --amend" to amend the current commit)
983 (use "git rebase --continue" once you are satisfied with your changes)
984
985nothing to commit (use -u to show untracked files)
986EOF
987 git status --untracked-files=no >actual &&
988 test_i18ncmp expected actual
989'
990
991test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
992 ONTO=$(git rev-parse --short HEAD^) &&
993 COMMIT=$(git rev-parse --short HEAD) &&
994 EDITOR="git status --untracked-files=no >actual" git rebase -i HEAD^ &&
995 cat >expected <<EOF &&
996On branch several_commits
997No commands done.
998Next command to do (1 remaining command):
999 pick $COMMIT four_commit
1000 (use "git rebase --edit-todo" to view and edit)
1001You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
1002 (use "git commit --amend" to amend the current commit)
1003 (use "git rebase --continue" once you are satisfied with your changes)
1004
1005nothing to commit (use -u to show untracked files)
1006EOF
1007 test_i18ncmp expected actual
1008'
1009
1010test_done