status: show 'revert' state and status hint

This is the logical equivalent for "git status" of 3ee4452 (bash: teach __git_ps1 about REVERT_HEAD). Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Apr 2, 2013 at 16:20 UTC db4ef4496e7a99809f7caa52e8821320e5cca7bc
3 files changed +81
t/t7512-status-help.sh
+57
@@ -678,4 +678,61 @@ test_expect_success 'status showing detached from a tag' '
678 test_i18ncmp expected actual
679 '
680
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 + test_must_fail git revert HEAD^ &&
690 + cat >expected <<-EOF
691 + # On branch master
692 + # You are currently reverting a commit.
693 + # (fix conflicts and run "git revert --continue")
694 + # (use "git revert --abort" to cancel the revert operation)
695 + #
696 + # Unmerged paths:
697 + # (use "git reset HEAD <file>..." to unstage)
698 + # (use "git add <file>..." to mark resolution)
699 + #
700 + # both modified: to-revert.txt
701 + #
702 + no changes added to commit (use "git add" and/or "git commit -a")
703 + EOF
704 + git status --untracked-files=no >actual &&
705 + test_i18ncmp expected actual
706 +'
707 +
708 +test_expect_success 'status while reverting commit (conflicts resolved)' '
709 + echo reverted >to-revert.txt &&
710 + git add to-revert.txt &&
711 + cat >expected <<-EOF
712 + # On branch master
713 + # You are currently reverting a commit.
714 + # (all conflicts fixed: run "git revert --continue")
715 + # (use "git revert --abort" to cancel the revert operation)
716 + #
717 + # Changes to be committed:
718 + # (use "git reset HEAD <file>..." to unstage)
719 + #
720 + # modified: to-revert.txt
721 + #
722 + # Untracked files not listed (use -u option to show untracked files)
723 + EOF
724 + git status --untracked-files=no >actual &&
725 + test_i18ncmp expected actual
726 +'
727 +
728 +test_expect_success 'status after reverting commit' '
729 + git revert --continue &&
730 + cat >expected <<-\EOF
731 + # On branch master
732 + nothing to commit (use -u to show untracked files)
733 + EOF
734 + git status --untracked-files=no >actual &&
735 + test_i18ncmp expected actual
736 +'
737 +
738 test_done
wt-status.c
+23
@@ -965,6 +965,24 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
965 wt_status_print_trailer(s);
966 }
967
968 +static void show_revert_in_progress(struct wt_status *s,
969 + struct wt_status_state *state,
970 + const char *color)
971 +{
972 + status_printf_ln(s, color, _("You are currently reverting a commit."));
973 + if (advice_status_hints) {
974 + if (has_unmerged(s))
975 + status_printf_ln(s, color,
976 + _(" (fix conflicts and run \"git revert --continue\")"));
977 + else
978 + status_printf_ln(s, color,
979 + _(" (all conflicts fixed: run \"git revert --continue\")"));
980 + status_printf_ln(s, color,
981 + _(" (use \"git revert --abort\" to cancel the revert operation)"));
982 + }
983 + wt_status_print_trailer(s);
984 +}
985 +
986 static void show_bisect_in_progress(struct wt_status *s,
987 struct wt_status_state *state,
988 const char *color)
@@ -1113,6 +1131,9 @@ void wt_status_get_state(struct wt_status_state *state,
1131 state->bisect_in_progress = 1;
1132 state->branch = read_and_strip_branch("BISECT_START");
1133 }
1134 + if (!stat(git_path("REVERT_HEAD"), &st)) {
1135 + state->revert_in_progress = 1;
1136 + }
1137
1138 if (get_detached_from)
1139 wt_status_get_detached_from(state);
@@ -1130,6 +1151,8 @@ static void wt_status_print_state(struct wt_status *s,
1151 show_rebase_in_progress(s, state, state_color);
1152 else if (state->cherry_pick_in_progress)
1153 show_cherry_pick_in_progress(s, state, state_color);
1154 + else if (state->revert_in_progress)
1155 + show_revert_in_progress(s, state, state_color);
1156 if (state->bisect_in_progress)
1157 show_bisect_in_progress(s, state, state_color);
1158 }
wt-status.h
+1
@@ -80,6 +80,7 @@ struct wt_status_state {
80 int rebase_interactive_in_progress;
81 int cherry_pick_in_progress;
82 int bisect_in_progress;
83 + int revert_in_progress;
84 char *branch;
85 char *onto;
86 char *detached_from;