3 # Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4 # Thomas Nguy, Khoi Nguyen
8 test_description
='git status advice'
12 .
"$TEST_DIRECTORY"/lib-rebase.sh
16 test_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
26 test_expect_success
'status when conflicts unresolved' '
27 test_must_fail git merge master &&
28 cat >expected <<\EOF &&
30 You have unmerged paths.
31 (fix conflicts and run "git commit")
34 (use "git add <file>..." to mark resolution)
36 both modified: main.txt
38 no changes added to commit (use "git add" and/or "git commit -a")
40 git status --untracked-files=no >actual &&
41 test_i18ncmp expected actual
45 test_expect_success
'status when conflicts resolved before commit' '
46 git reset --hard conflicts &&
47 test_must_fail git merge master &&
50 cat >expected <<\EOF &&
52 All conflicts fixed but you are still merging.
53 (use "git commit" to conclude merge)
55 Changes to be committed:
59 Untracked files not listed (use -u option to show untracked files)
61 git status --untracked-files=no >actual &&
62 test_i18ncmp expected actual
66 test_expect_success
'prepare for rebase conflicts' '
67 git reset --hard master &&
68 git checkout -b rebase_conflicts &&
69 test_commit one_rebase main.txt one &&
70 test_commit two_rebase main.txt two &&
71 test_commit three_rebase main.txt three
75 test_expect_success
'status when rebase in progress before resolving conflicts' '
76 test_when_finished "git rebase --abort" &&
77 ONTO=$(git rev-parse --short HEAD^^) &&
78 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
79 cat >expected <<EOF &&
80 rebase in progress; onto $ONTO
81 You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
82 (fix conflicts and then run "git rebase --continue")
83 (use "git rebase --skip" to skip this patch)
84 (use "git rebase --abort" to check out the original branch)
87 (use "git reset HEAD <file>..." to unstage)
88 (use "git add <file>..." to mark resolution)
90 both modified: main.txt
92 no changes added to commit (use "git add" and/or "git commit -a")
94 git status --untracked-files=no >actual &&
95 test_i18ncmp expected actual
99 test_expect_success
'status when rebase in progress before rebase --continue' '
100 git reset --hard rebase_conflicts &&
101 test_when_finished "git rebase --abort" &&
102 ONTO=$(git rev-parse --short HEAD^^) &&
103 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
104 echo three >main.txt &&
106 cat >expected <<EOF &&
107 rebase in progress; onto $ONTO
108 You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
109 (all conflicts fixed: run "git rebase --continue")
111 Changes to be committed:
112 (use "git reset HEAD <file>..." to unstage)
116 Untracked files not listed (use -u option to show untracked files)
118 git status --untracked-files=no >actual &&
119 test_i18ncmp expected actual
123 test_expect_success
'prepare for rebase_i_conflicts' '
124 git reset --hard master &&
125 git checkout -b rebase_i_conflicts &&
126 test_commit one_unmerge main.txt one_unmerge &&
127 git branch rebase_i_conflicts_second &&
128 test_commit one_master main.txt one_master &&
129 git checkout rebase_i_conflicts_second &&
130 test_commit one_second main.txt one_second
134 test_expect_success
'status during rebase -i when conflicts unresolved' '
135 test_when_finished "git rebase --abort" &&
136 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
137 test_must_fail git rebase -i rebase_i_conflicts &&
138 cat >expected <<EOF &&
139 rebase in progress; onto $ONTO
140 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
141 (fix conflicts and then run "git rebase --continue")
142 (use "git rebase --skip" to skip this patch)
143 (use "git rebase --abort" to check out the original branch)
146 (use "git reset HEAD <file>..." to unstage)
147 (use "git add <file>..." to mark resolution)
149 both modified: main.txt
151 no changes added to commit (use "git add" and/or "git commit -a")
153 git status --untracked-files=no >actual &&
154 test_i18ncmp expected actual
158 test_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 test_must_fail git rebase -i rebase_i_conflicts &&
164 cat >expected <<EOF &&
165 rebase in progress; onto $ONTO
166 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
167 (all conflicts fixed: run "git rebase --continue")
169 Changes to be committed:
170 (use "git reset HEAD <file>..." to unstage)
174 Untracked files not listed (use -u option to show untracked files)
176 git status --untracked-files=no >actual &&
177 test_i18ncmp expected actual
181 test_expect_success
'status when rebasing -i in edit mode' '
182 git reset --hard master &&
183 git checkout -b rebase_i_edit &&
184 test_commit one_rebase_i main.txt one &&
185 test_commit two_rebase_i main.txt two &&
186 test_commit three_rebase_i main.txt three &&
187 FAKE_LINES="1 edit 2" &&
189 test_when_finished "git rebase --abort" &&
190 ONTO=$(git rev-parse --short HEAD~2) &&
191 git rebase -i HEAD~2 &&
192 cat >expected <<EOF &&
193 rebase in progress; onto $ONTO
194 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
195 (use "git commit --amend" to amend the current commit)
196 (use "git rebase --continue" once you are satisfied with your changes)
198 nothing to commit (use -u to show untracked files)
200 git status --untracked-files=no >actual &&
201 test_i18ncmp expected actual
205 test_expect_success
'status when splitting a commit' '
206 git reset --hard master &&
207 git checkout -b split_commit &&
208 test_commit one_split main.txt one &&
209 test_commit two_split main.txt two &&
210 test_commit three_split main.txt three &&
211 test_commit four_split main.txt four &&
212 FAKE_LINES="1 edit 2 3" &&
214 test_when_finished "git rebase --abort" &&
215 ONTO=$(git rev-parse --short HEAD~3) &&
216 git rebase -i HEAD~3 &&
218 cat >expected <<EOF &&
219 rebase in progress; onto $ONTO
220 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
221 (Once your working directory is clean, run "git rebase --continue")
223 Changes not staged for commit:
224 (use "git add <file>..." to update what will be committed)
225 (use "git checkout -- <file>..." to discard changes in working directory)
229 no changes added to commit (use "git add" and/or "git commit -a")
231 git status --untracked-files=no >actual &&
232 test_i18ncmp expected actual
236 test_expect_success
'status after editing the last commit with --amend during a rebase -i' '
237 git reset --hard master &&
238 git checkout -b amend_last &&
239 test_commit one_amend main.txt one &&
240 test_commit two_amend main.txt two &&
241 test_commit three_amend main.txt three &&
242 test_commit four_amend main.txt four &&
243 FAKE_LINES="1 2 edit 3" &&
245 test_when_finished "git rebase --abort" &&
246 ONTO=$(git rev-parse --short HEAD~3) &&
247 git rebase -i HEAD~3 &&
248 git commit --amend -m "foo" &&
249 cat >expected <<EOF &&
250 rebase in progress; onto $ONTO
251 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
252 (use "git commit --amend" to amend the current commit)
253 (use "git rebase --continue" once you are satisfied with your changes)
255 nothing to commit (use -u to show untracked files)
257 git status --untracked-files=no >actual &&
258 test_i18ncmp expected actual
262 test_expect_success
'prepare for several edits' '
263 git reset --hard master &&
264 git checkout -b several_edits &&
265 test_commit one_edits main.txt one &&
266 test_commit two_edits main.txt two &&
267 test_commit three_edits main.txt three &&
268 test_commit four_edits main.txt four
272 test_expect_success
'status: (continue first edit) second edit' '
273 FAKE_LINES="edit 1 edit 2 3" &&
275 test_when_finished "git rebase --abort" &&
276 ONTO=$(git rev-parse --short HEAD~3) &&
277 git rebase -i HEAD~3 &&
278 git rebase --continue &&
279 cat >expected <<EOF &&
280 rebase in progress; onto $ONTO
281 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
282 (use "git commit --amend" to amend the current commit)
283 (use "git rebase --continue" once you are satisfied with your changes)
285 nothing to commit (use -u to show untracked files)
287 git status --untracked-files=no >actual &&
288 test_i18ncmp expected actual
292 test_expect_success
'status: (continue first edit) second edit and split' '
293 git reset --hard several_edits &&
294 FAKE_LINES="edit 1 edit 2 3" &&
296 test_when_finished "git rebase --abort" &&
297 ONTO=$(git rev-parse --short HEAD~3) &&
298 git rebase -i HEAD~3 &&
299 git rebase --continue &&
301 cat >expected <<EOF &&
302 rebase in progress; onto $ONTO
303 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
304 (Once your working directory is clean, run "git rebase --continue")
306 Changes not staged for commit:
307 (use "git add <file>..." to update what will be committed)
308 (use "git checkout -- <file>..." to discard changes in working directory)
312 no changes added to commit (use "git add" and/or "git commit -a")
314 git status --untracked-files=no >actual &&
315 test_i18ncmp expected actual
319 test_expect_success
'status: (continue first edit) second edit and amend' '
320 git reset --hard several_edits &&
321 FAKE_LINES="edit 1 edit 2 3" &&
323 test_when_finished "git rebase --abort" &&
324 ONTO=$(git rev-parse --short HEAD~3) &&
325 git rebase -i HEAD~3 &&
326 git rebase --continue &&
327 git commit --amend -m "foo" &&
328 cat >expected <<EOF &&
329 rebase in progress; onto $ONTO
330 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
331 (use "git commit --amend" to amend the current commit)
332 (use "git rebase --continue" once you are satisfied with your changes)
334 nothing to commit (use -u to show untracked files)
336 git status --untracked-files=no >actual &&
337 test_i18ncmp expected actual
341 test_expect_success
'status: (amend first edit) second edit' '
342 git reset --hard several_edits &&
343 FAKE_LINES="edit 1 edit 2 3" &&
345 test_when_finished "git rebase --abort" &&
346 ONTO=$(git rev-parse --short HEAD~3) &&
347 git rebase -i HEAD~3 &&
348 git commit --amend -m "a" &&
349 git rebase --continue &&
350 cat >expected <<EOF &&
351 rebase in progress; onto $ONTO
352 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
353 (use "git commit --amend" to amend the current commit)
354 (use "git rebase --continue" once you are satisfied with your changes)
356 nothing to commit (use -u to show untracked files)
358 git status --untracked-files=no >actual &&
359 test_i18ncmp expected actual
363 test_expect_success
'status: (amend first edit) second edit and split' '
364 git reset --hard several_edits &&
365 FAKE_LINES="edit 1 edit 2 3" &&
367 test_when_finished "git rebase --abort" &&
368 ONTO=$(git rev-parse --short HEAD~3) &&
369 git rebase -i HEAD~3 &&
370 git commit --amend -m "b" &&
371 git rebase --continue &&
373 cat >expected <<EOF &&
374 rebase in progress; onto $ONTO
375 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
376 (Once your working directory is clean, run "git rebase --continue")
378 Changes not staged for commit:
379 (use "git add <file>..." to update what will be committed)
380 (use "git checkout -- <file>..." to discard changes in working directory)
384 no changes added to commit (use "git add" and/or "git commit -a")
386 git status --untracked-files=no >actual &&
387 test_i18ncmp expected actual
391 test_expect_success
'status: (amend first edit) second edit and amend' '
392 git reset --hard several_edits &&
393 FAKE_LINES="edit 1 edit 2 3" &&
395 test_when_finished "git rebase --abort" &&
396 ONTO=$(git rev-parse --short HEAD~3) &&
397 git rebase -i HEAD~3 &&
398 git commit --amend -m "c" &&
399 git rebase --continue &&
400 git commit --amend -m "d" &&
401 cat >expected <<EOF &&
402 rebase in progress; onto $ONTO
403 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
404 (use "git commit --amend" to amend the current commit)
405 (use "git rebase --continue" once you are satisfied with your changes)
407 nothing to commit (use -u to show untracked files)
409 git status --untracked-files=no >actual &&
410 test_i18ncmp expected actual
414 test_expect_success
'status: (split first edit) second edit' '
415 git reset --hard several_edits &&
416 FAKE_LINES="edit 1 edit 2 3" &&
418 test_when_finished "git rebase --abort" &&
419 ONTO=$(git rev-parse --short HEAD~3) &&
420 git rebase -i HEAD~3 &&
424 git rebase --continue &&
425 cat >expected <<EOF &&
426 rebase in progress; onto $ONTO
427 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
428 (use "git commit --amend" to amend the current commit)
429 (use "git rebase --continue" once you are satisfied with your changes)
431 nothing to commit (use -u to show untracked files)
433 git status --untracked-files=no >actual &&
434 test_i18ncmp expected actual
438 test_expect_success
'status: (split first edit) second edit and split' '
439 git reset --hard several_edits &&
440 FAKE_LINES="edit 1 edit 2 3" &&
442 test_when_finished "git rebase --abort" &&
443 ONTO=$(git rev-parse --short HEAD~3) &&
444 git rebase -i HEAD~3 &&
447 git commit --amend -m "f" &&
448 git rebase --continue &&
450 cat >expected <<EOF &&
451 rebase in progress; onto $ONTO
452 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
453 (Once your working directory is clean, run "git rebase --continue")
455 Changes not staged for commit:
456 (use "git add <file>..." to update what will be committed)
457 (use "git checkout -- <file>..." to discard changes in working directory)
461 no changes added to commit (use "git add" and/or "git commit -a")
463 git status --untracked-files=no >actual &&
464 test_i18ncmp expected actual
468 test_expect_success
'status: (split first edit) second edit and amend' '
469 git reset --hard several_edits &&
470 FAKE_LINES="edit 1 edit 2 3" &&
472 test_when_finished "git rebase --abort" &&
473 ONTO=$(git rev-parse --short HEAD~3) &&
474 git rebase -i HEAD~3 &&
477 git commit --amend -m "g" &&
478 git rebase --continue &&
479 git commit --amend -m "h" &&
480 cat >expected <<EOF &&
481 rebase in progress; onto $ONTO
482 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
483 (use "git commit --amend" to amend the current commit)
484 (use "git rebase --continue" once you are satisfied with your changes)
486 nothing to commit (use -u to show untracked files)
488 git status --untracked-files=no >actual &&
489 test_i18ncmp expected actual
493 test_expect_success
'prepare am_session' '
494 git reset --hard master &&
495 git checkout -b am_session &&
496 test_commit one_am one.txt "one" &&
497 test_commit two_am two.txt "two" &&
498 test_commit three_am three.txt "three"
502 test_expect_success
'status in an am session: file already exists' '
503 git checkout -b am_already_exists &&
504 test_when_finished "rm Maildir/* && git am --abort" &&
505 git format-patch -1 -oMaildir &&
506 test_must_fail git am Maildir/*.patch &&
507 cat >expected <<\EOF &&
508 On branch am_already_exists
509 You are in the middle of an am session.
510 (fix conflicts and then run "git am --continue")
511 (use "git am --skip" to skip this patch)
512 (use "git am --abort" to restore the original branch)
514 nothing to commit (use -u to show untracked files)
516 git status --untracked-files=no >actual &&
517 test_i18ncmp expected actual
521 test_expect_success
'status in an am session: file does not exist' '
522 git reset --hard am_session &&
523 git checkout -b am_not_exists &&
525 git commit -m "delete three.txt" &&
526 test_when_finished "rm Maildir/* && git am --abort" &&
527 git format-patch -1 -oMaildir &&
528 test_must_fail git am Maildir/*.patch &&
529 cat >expected <<\EOF &&
530 On branch am_not_exists
531 You are in the middle of an am session.
532 (fix conflicts and then run "git am --continue")
533 (use "git am --skip" to skip this patch)
534 (use "git am --abort" to restore the original branch)
536 nothing to commit (use -u to show untracked files)
538 git status --untracked-files=no >actual &&
539 test_i18ncmp expected actual
543 test_expect_success
'status in an am session: empty patch' '
544 git reset --hard am_session &&
545 git checkout -b am_empty &&
546 test_when_finished "rm Maildir/* && git am --abort" &&
547 git format-patch -3 -oMaildir &&
548 git rm one.txt two.txt three.txt &&
549 git commit -m "delete all am_empty" &&
550 echo error >Maildir/0002-two_am.patch &&
551 test_must_fail git am Maildir/*.patch &&
552 cat >expected <<\EOF &&
554 You are in the middle of an am session.
555 The current patch is empty.
556 (use "git am --skip" to skip this patch)
557 (use "git am --abort" to restore the original branch)
559 nothing to commit (use -u to show untracked files)
561 git status --untracked-files=no >actual &&
562 test_i18ncmp expected actual
566 test_expect_success
'status when bisecting' '
567 git reset --hard master &&
568 git checkout -b bisect &&
569 test_commit one_bisect main.txt one &&
570 test_commit two_bisect main.txt two &&
571 test_commit three_bisect main.txt three &&
572 test_when_finished "git bisect reset" &&
575 git bisect good one_bisect &&
576 TGT=$(git rev-parse --short two_bisect) &&
577 cat >expected <<EOF &&
578 HEAD detached at $TGT
579 You are currently bisecting, started from branch '\''bisect'\''.
580 (use "git bisect reset" to get back to the original branch)
582 nothing to commit (use -u to show untracked files)
584 git status --untracked-files=no >actual &&
585 test_i18ncmp expected actual
589 test_expect_success
'status when rebase conflicts with statushints disabled' '
590 git reset --hard master &&
591 git checkout -b statushints_disabled &&
592 test_when_finished "git config --local advice.statushints true" &&
593 git config --local advice.statushints false &&
594 test_commit one_statushints main.txt one &&
595 test_commit two_statushints main.txt two &&
596 test_commit three_statushints main.txt three &&
597 test_when_finished "git rebase --abort" &&
598 ONTO=$(git rev-parse --short HEAD^^) &&
599 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
600 cat >expected <<EOF &&
601 rebase in progress; onto $ONTO
602 You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
605 both modified: main.txt
607 no changes added to commit
609 git status --untracked-files=no >actual &&
610 test_i18ncmp expected actual
614 test_expect_success
'prepare for cherry-pick conflicts' '
615 git reset --hard master &&
616 git checkout -b cherry_branch &&
617 test_commit one_cherry main.txt one &&
618 test_commit two_cherries main.txt two &&
619 git checkout -b cherry_branch_second &&
620 test_commit second_cherry main.txt second &&
621 git checkout cherry_branch &&
622 test_commit three_cherries main.txt three
626 test_expect_success
'status when cherry-picking before resolving conflicts' '
627 test_when_finished "git cherry-pick --abort" &&
628 test_must_fail git cherry-pick cherry_branch_second &&
629 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
630 cat >expected <<EOF &&
631 On branch cherry_branch
632 You are currently cherry-picking commit $TO_CHERRY_PICK.
633 (fix conflicts and run "git cherry-pick --continue")
634 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
637 (use "git add <file>..." to mark resolution)
639 both modified: main.txt
641 no changes added to commit (use "git add" and/or "git commit -a")
643 git status --untracked-files=no >actual &&
644 test_i18ncmp expected actual
648 test_expect_success
'status when cherry-picking after resolving conflicts' '
649 git reset --hard cherry_branch &&
650 test_when_finished "git cherry-pick --abort" &&
651 test_must_fail git cherry-pick cherry_branch_second &&
652 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
653 echo end >main.txt &&
655 cat >expected <<EOF &&
656 On branch cherry_branch
657 You are currently cherry-picking commit $TO_CHERRY_PICK.
658 (all conflicts fixed: run "git cherry-pick --continue")
659 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
661 Changes to be committed:
665 Untracked files not listed (use -u option to show untracked files)
667 git status --untracked-files=no >actual &&
668 test_i18ncmp expected actual
671 test_expect_success
'status showing detached at and from a tag' '
672 test_commit atag tagging &&
674 cat >expected <<\EOF &&
675 HEAD detached at atag
676 nothing to commit (use -u to show untracked files)
678 git status --untracked-files=no >actual &&
679 test_i18ncmp expected actual &&
681 git reset --hard HEAD^ &&
682 cat >expected <<\EOF &&
683 HEAD detached from atag
684 nothing to commit (use -u to show untracked files)
686 git status --untracked-files=no >actual &&
687 test_i18ncmp expected actual
690 test_expect_success
'status while reverting commit (conflicts)' '
691 git checkout master &&
692 echo before >to-revert.txt &&
693 test_commit before to-revert.txt &&
694 echo old >to-revert.txt &&
695 test_commit old to-revert.txt &&
696 echo new >to-revert.txt &&
697 test_commit new to-revert.txt &&
698 TO_REVERT=$(git rev-parse --short HEAD^) &&
699 test_must_fail git revert $TO_REVERT &&
700 cat >expected <<EOF &&
702 You are currently reverting commit $TO_REVERT.
703 (fix conflicts and run "git revert --continue")
704 (use "git revert --abort" to cancel the revert operation)
707 (use "git reset HEAD <file>..." to unstage)
708 (use "git add <file>..." to mark resolution)
710 both modified: to-revert.txt
712 no changes added to commit (use "git add" and/or "git commit -a")
714 git status --untracked-files=no >actual &&
715 test_i18ncmp expected actual
718 test_expect_success
'status while reverting commit (conflicts resolved)' '
719 echo reverted >to-revert.txt &&
720 git add to-revert.txt &&
721 cat >expected <<EOF &&
723 You are currently reverting commit $TO_REVERT.
724 (all conflicts fixed: run "git revert --continue")
725 (use "git revert --abort" to cancel the revert operation)
727 Changes to be committed:
728 (use "git reset HEAD <file>..." to unstage)
730 modified: to-revert.txt
732 Untracked files not listed (use -u option to show untracked files)
734 git status --untracked-files=no >actual &&
735 test_i18ncmp expected actual
738 test_expect_success
'status after reverting commit' '
739 git revert --continue &&
740 cat >expected <<\EOF &&
742 nothing to commit (use -u to show untracked files)
744 git status --untracked-files=no >actual &&
745 test_i18ncmp expected actual