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 # HEAD detached at $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 # HEAD detached at $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 # HEAD detached at $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 # HEAD detached at $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 TGT=$(git rev-parse --short two_rebase_i) &&
192 git rebase -i HEAD~2 &&
193 cat >expected <<-EOF &&
194 # HEAD detached from $TGT
195 # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
196 # (use "git commit --amend" to amend the current commit)
197 # (use "git rebase --continue" once you are satisfied with your changes)
199 nothing to commit (use -u to show untracked files)
201 git status --untracked-files=no >actual &&
202 test_i18ncmp expected actual
206 test_expect_success 'status when splitting a commit' '
207 git reset --hard master &&
208 git checkout -b split_commit &&
209 test_commit one_split main.txt one &&
210 test_commit two_split main.txt two &&
211 test_commit three_split main.txt three &&
212 test_commit four_split main.txt four &&
213 FAKE_LINES="1 edit 2 3" &&
215 test_when_finished "git rebase --abort" &&
216 ONTO=$(git rev-parse --short HEAD~3) &&
217 git rebase -i HEAD~3 &&
219 TGT=$(git rev-parse --short HEAD) &&
220 cat >expected <<-EOF &&
221 # HEAD detached at $TGT
222 # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
223 # (Once your working directory is clean, run "git rebase --continue")
225 # Changes not staged for commit:
226 # (use "git add <file>..." to update what will be committed)
227 # (use "git checkout -- <file>..." to discard changes in working directory)
231 no changes added to commit (use "git add" and/or "git commit -a")
233 git status --untracked-files=no >actual &&
234 test_i18ncmp expected actual
238 test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
239 git reset --hard master &&
240 git checkout -b amend_last &&
241 test_commit one_amend main.txt one &&
242 test_commit two_amend main.txt two &&
243 test_commit three_amend main.txt three &&
244 test_commit four_amend main.txt four &&
245 FAKE_LINES="1 2 edit 3" &&
247 test_when_finished "git rebase --abort" &&
248 ONTO=$(git rev-parse --short HEAD~3) &&
249 TGT=$(git rev-parse --short three_amend) &&
250 git rebase -i HEAD~3 &&
251 git commit --amend -m "foo" &&
252 cat >expected <<-EOF &&
253 # HEAD detached from $TGT
254 # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
255 # (use "git commit --amend" to amend the current commit)
256 # (use "git rebase --continue" once you are satisfied with your changes)
258 nothing to commit (use -u to show untracked files)
260 git status --untracked-files=no >actual &&
261 test_i18ncmp expected actual
265 test_expect_success 'prepare for several edits' '
266 git reset --hard master &&
267 git checkout -b several_edits &&
268 test_commit one_edits main.txt one &&
269 test_commit two_edits main.txt two &&
270 test_commit three_edits main.txt three &&
271 test_commit four_edits main.txt four
275 test_expect_success 'status: (continue first edit) second edit' '
276 FAKE_LINES="edit 1 edit 2 3" &&
278 test_when_finished "git rebase --abort" &&
279 ONTO=$(git rev-parse --short HEAD~3) &&
280 git rebase -i HEAD~3 &&
281 git rebase --continue &&
282 cat >expected <<-EOF &&
283 # HEAD detached from $ONTO
284 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
285 # (use "git commit --amend" to amend the current commit)
286 # (use "git rebase --continue" once you are satisfied with your changes)
288 nothing to commit (use -u to show untracked files)
290 git status --untracked-files=no >actual &&
291 test_i18ncmp expected actual
295 test_expect_success 'status: (continue first edit) second edit and split' '
296 git reset --hard several_edits &&
297 FAKE_LINES="edit 1 edit 2 3" &&
299 test_when_finished "git rebase --abort" &&
300 ONTO=$(git rev-parse --short HEAD~3) &&
301 git rebase -i HEAD~3 &&
302 git rebase --continue &&
304 cat >expected <<-EOF &&
305 # HEAD detached from $ONTO
306 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
307 # (Once your working directory is clean, run "git rebase --continue")
309 # Changes not staged for commit:
310 # (use "git add <file>..." to update what will be committed)
311 # (use "git checkout -- <file>..." to discard changes in working directory)
315 no changes added to commit (use "git add" and/or "git commit -a")
317 git status --untracked-files=no >actual &&
318 test_i18ncmp expected actual
322 test_expect_success 'status: (continue first edit) second edit and amend' '
323 git reset --hard several_edits &&
324 FAKE_LINES="edit 1 edit 2 3" &&
326 test_when_finished "git rebase --abort" &&
327 ONTO=$(git rev-parse --short HEAD~3) &&
328 git rebase -i HEAD~3 &&
329 git rebase --continue &&
330 git commit --amend -m "foo" &&
331 cat >expected <<-EOF &&
332 # HEAD detached from $ONTO
333 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
334 # (use "git commit --amend" to amend the current commit)
335 # (use "git rebase --continue" once you are satisfied with your changes)
337 nothing to commit (use -u to show untracked files)
339 git status --untracked-files=no >actual &&
340 test_i18ncmp expected actual
344 test_expect_success 'status: (amend first edit) second edit' '
345 git reset --hard several_edits &&
346 FAKE_LINES="edit 1 edit 2 3" &&
348 test_when_finished "git rebase --abort" &&
349 ONTO=$(git rev-parse --short HEAD~3) &&
350 git rebase -i HEAD~3 &&
351 git commit --amend -m "a" &&
352 git rebase --continue &&
353 cat >expected <<-EOF &&
354 # HEAD detached from $ONTO
355 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
356 # (use "git commit --amend" to amend the current commit)
357 # (use "git rebase --continue" once you are satisfied with your changes)
359 nothing to commit (use -u to show untracked files)
361 git status --untracked-files=no >actual &&
362 test_i18ncmp expected actual
366 test_expect_success 'status: (amend first edit) second edit and split' '
367 git reset --hard several_edits &&
368 FAKE_LINES="edit 1 edit 2 3" &&
370 test_when_finished "git rebase --abort" &&
371 ONTO=$(git rev-parse --short HEAD~3) &&
372 git rebase -i HEAD~3 &&
373 git commit --amend -m "b" &&
374 git rebase --continue &&
376 cat >expected <<-EOF &&
377 # HEAD detached from $ONTO
378 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
379 # (Once your working directory is clean, run "git rebase --continue")
381 # Changes not staged for commit:
382 # (use "git add <file>..." to update what will be committed)
383 # (use "git checkout -- <file>..." to discard changes in working directory)
387 no changes added to commit (use "git add" and/or "git commit -a")
389 git status --untracked-files=no >actual &&
390 test_i18ncmp expected actual
394 test_expect_success 'status: (amend first edit) second edit and amend' '
395 git reset --hard several_edits &&
396 FAKE_LINES="edit 1 edit 2 3" &&
398 test_when_finished "git rebase --abort" &&
399 ONTO=$(git rev-parse --short HEAD~3) &&
400 git rebase -i HEAD~3 &&
401 git commit --amend -m "c" &&
402 git rebase --continue &&
403 git commit --amend -m "d" &&
404 cat >expected <<-EOF &&
405 # HEAD detached from $ONTO
406 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
407 # (use "git commit --amend" to amend the current commit)
408 # (use "git rebase --continue" once you are satisfied with your changes)
410 nothing to commit (use -u to show untracked files)
412 git status --untracked-files=no >actual &&
413 test_i18ncmp expected actual
417 test_expect_success 'status: (split first edit) second edit' '
418 git reset --hard several_edits &&
419 FAKE_LINES="edit 1 edit 2 3" &&
421 test_when_finished "git rebase --abort" &&
422 ONTO=$(git rev-parse --short HEAD~3) &&
423 git rebase -i HEAD~3 &&
427 git rebase --continue &&
428 cat >expected <<-EOF &&
429 # HEAD detached from $ONTO
430 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
431 # (use "git commit --amend" to amend the current commit)
432 # (use "git rebase --continue" once you are satisfied with your changes)
434 nothing to commit (use -u to show untracked files)
436 git status --untracked-files=no >actual &&
437 test_i18ncmp expected actual
441 test_expect_success 'status: (split first edit) second edit and split' '
442 git reset --hard several_edits &&
443 FAKE_LINES="edit 1 edit 2 3" &&
445 test_when_finished "git rebase --abort" &&
446 ONTO=$(git rev-parse --short HEAD~3) &&
447 git rebase -i HEAD~3 &&
450 git commit --amend -m "f" &&
451 git rebase --continue &&
453 cat >expected <<-EOF &&
454 # HEAD detached from $ONTO
455 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
456 # (Once your working directory is clean, run "git rebase --continue")
458 # Changes not staged for commit:
459 # (use "git add <file>..." to update what will be committed)
460 # (use "git checkout -- <file>..." to discard changes in working directory)
464 no changes added to commit (use "git add" and/or "git commit -a")
466 git status --untracked-files=no >actual &&
467 test_i18ncmp expected actual
471 test_expect_success 'status: (split first edit) second edit and amend' '
472 git reset --hard several_edits &&
473 FAKE_LINES="edit 1 edit 2 3" &&
475 test_when_finished "git rebase --abort" &&
476 ONTO=$(git rev-parse --short HEAD~3) &&
477 git rebase -i HEAD~3 &&
480 git commit --amend -m "g" &&
481 git rebase --continue &&
482 git commit --amend -m "h" &&
483 cat >expected <<-EOF &&
484 # HEAD detached from $ONTO
485 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
486 # (use "git commit --amend" to amend the current commit)
487 # (use "git rebase --continue" once you are satisfied with your changes)
489 nothing to commit (use -u to show untracked files)
491 git status --untracked-files=no >actual &&
492 test_i18ncmp expected actual
496 test_expect_success 'prepare am_session' '
497 git reset --hard master &&
498 git checkout -b am_session &&
499 test_commit one_am one.txt "one" &&
500 test_commit two_am two.txt "two" &&
501 test_commit three_am three.txt "three"
505 test_expect_success 'status in an am session: file already exists' '
506 git checkout -b am_already_exists &&
507 test_when_finished "rm Maildir/* && git am --abort" &&
508 git format-patch -1 -oMaildir &&
509 test_must_fail git am Maildir/*.patch &&
510 cat >expected <<-\EOF &&
511 # On branch am_already_exists
512 # You are in the middle of an am session.
513 # (fix conflicts and then run "git am --resolved")
514 # (use "git am --skip" to skip this patch)
515 # (use "git am --abort" to restore the original branch)
517 nothing to commit (use -u to show untracked files)
519 git status --untracked-files=no >actual &&
520 test_i18ncmp expected actual
524 test_expect_success 'status in an am session: file does not exist' '
525 git reset --hard am_session &&
526 git checkout -b am_not_exists &&
528 git commit -m "delete three.txt" &&
529 test_when_finished "rm Maildir/* && git am --abort" &&
530 git format-patch -1 -oMaildir &&
531 test_must_fail git am Maildir/*.patch &&
532 cat >expected <<-\EOF &&
533 # On branch am_not_exists
534 # You are in the middle of an am session.
535 # (fix conflicts and then run "git am --resolved")
536 # (use "git am --skip" to skip this patch)
537 # (use "git am --abort" to restore the original branch)
539 nothing to commit (use -u to show untracked files)
541 git status --untracked-files=no >actual &&
542 test_i18ncmp expected actual
546 test_expect_success 'status in an am session: empty patch' '
547 git reset --hard am_session &&
548 git checkout -b am_empty &&
549 test_when_finished "rm Maildir/* && git am --abort" &&
550 git format-patch -3 -oMaildir &&
551 git rm one.txt two.txt three.txt &&
552 git commit -m "delete all am_empty" &&
553 echo error >Maildir/0002-two_am.patch &&
554 test_must_fail git am Maildir/*.patch &&
555 cat >expected <<-\EOF &&
557 # You are in the middle of an am session.
558 # The current patch is empty.
559 # (use "git am --skip" to skip this patch)
560 # (use "git am --abort" to restore the original branch)
562 nothing to commit (use -u to show untracked files)
564 git status --untracked-files=no >actual &&
565 test_i18ncmp expected actual
569 test_expect_success 'status when bisecting' '
570 git reset --hard master &&
571 git checkout -b bisect &&
572 test_commit one_bisect main.txt one &&
573 test_commit two_bisect main.txt two &&
574 test_commit three_bisect main.txt three &&
575 test_when_finished "git bisect reset" &&
578 git bisect good one_bisect &&
579 TGT=$(git rev-parse --short two_bisect) &&
580 cat >expected <<-EOF &&
581 # HEAD detached at $TGT
582 # You are currently bisecting, started from branch '\''bisect'\''.
583 # (use "git bisect reset" to get back to the original branch)
585 nothing to commit (use -u to show untracked files)
587 git status --untracked-files=no >actual &&
588 test_i18ncmp expected actual
592 test_expect_success 'status when rebase conflicts with statushints disabled' '
593 git reset --hard master &&
594 git checkout -b statushints_disabled &&
595 test_when_finished "git config --local advice.statushints true" &&
596 git config --local advice.statushints false &&
597 test_commit one_statushints main.txt one &&
598 test_commit two_statushints main.txt two &&
599 test_commit three_statushints main.txt three &&
600 test_when_finished "git rebase --abort" &&
601 ONTO=$(git rev-parse --short HEAD^^) &&
602 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
603 cat >expected <<-EOF &&
604 # HEAD detached at $ONTO
605 # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
608 # both modified: main.txt
610 no changes added to commit
612 git status --untracked-files=no >actual &&
613 test_i18ncmp expected actual
617 test_expect_success 'prepare for cherry-pick conflicts' '
618 git reset --hard master &&
619 git checkout -b cherry_branch &&
620 test_commit one_cherry main.txt one &&
621 test_commit two_cherries main.txt two &&
622 git checkout -b cherry_branch_second &&
623 test_commit second_cherry main.txt second &&
624 git checkout cherry_branch &&
625 test_commit three_cherries main.txt three
629 test_expect_success 'status when cherry-picking before resolving conflicts' '
630 test_when_finished "git cherry-pick --abort" &&
631 test_must_fail git cherry-pick cherry_branch_second &&
632 cat >expected <<-\EOF &&
633 # On branch cherry_branch
634 # You are currently cherry-picking.
635 # (fix conflicts and run "git commit")
638 # (use "git add <file>..." to mark resolution)
640 # both modified: main.txt
642 no changes added to commit (use "git add" and/or "git commit -a")
644 git status --untracked-files=no >actual &&
645 test_i18ncmp expected actual
649 test_expect_success 'status when cherry-picking after resolving conflicts' '
650 git reset --hard cherry_branch &&
651 test_when_finished "git cherry-pick --abort" &&
652 test_must_fail git cherry-pick cherry_branch_second &&
653 echo end >main.txt &&
655 cat >expected <<-\EOF &&
656 # On branch cherry_branch
657 # You are currently cherry-picking.
658 # (all conflicts fixed: run "git commit")
660 # Changes to be committed:
664 # Untracked files not listed (use -u option to show untracked files)
666 git status --untracked-files=no >actual &&
667 test_i18ncmp expected actual
670 test_expect_success 'status showing detached from a tag' '
671 test_commit atag tagging &&
673 cat >expected <<-\EOF
674 # HEAD detached at atag
675 nothing to commit (use -u to show untracked files)
677 git status --untracked-files=no >actual &&
678 test_i18ncmp expected actual
681 test_expect_success 'status while reverting commit (conflicts)' '
682 git checkout master &&
683 echo before >to-revert.txt &&
684 test_commit before to-revert.txt &&
685 echo old >to-revert.txt &&
686 test_commit old to-revert.txt &&
687 echo new >to-revert.txt &&
688 test_commit new to-revert.txt &&
689 TO_REVERT=$(git rev-parse --short HEAD^) &&
690 test_must_fail git revert $TO_REVERT &&
693 # You are currently reverting commit $TO_REVERT.
694 # (fix conflicts and run "git revert --continue")
695 # (use "git revert --abort" to cancel the revert operation)
698 # (use "git reset HEAD <file>..." to unstage)
699 # (use "git add <file>..." to mark resolution)
701 # both modified: to-revert.txt
703 no changes added to commit (use "git add" and/or "git commit -a")
705 git status --untracked-files=no >actual &&
706 test_i18ncmp expected actual
709 test_expect_success 'status while reverting commit (conflicts resolved)' '
710 echo reverted >to-revert.txt &&
711 git add to-revert.txt &&
714 # You are currently reverting commit $TO_REVERT.
715 # (all conflicts fixed: run "git revert --continue")
716 # (use "git revert --abort" to cancel the revert operation)
718 # Changes to be committed:
719 # (use "git reset HEAD <file>..." to unstage)
721 # modified: to-revert.txt
723 # Untracked files not listed (use -u option to show untracked files)
725 git status --untracked-files=no >actual &&
726 test_i18ncmp expected actual
729 test_expect_success 'status after reverting commit' '
730 git revert --continue &&
731 cat >expected <<-\EOF
733 nothing to commit (use -u to show untracked files)
735 git status --untracked-files=no >actual &&
736 test_i18ncmp expected actual