]> Pileus Git - ~andy/git/commitdiff
status: show 'revert' state and status hint
authorMatthieu Moy <Matthieu.Moy@imag.fr>
Tue, 2 Apr 2013 14:20:21 +0000 (16:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Apr 2013 21:22:55 +0000 (14:22 -0700)
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>
t/t7512-status-help.sh
wt-status.c
wt-status.h

index 06749a6aa07e40a5e5081c8912264d9c15b385ef..d745cf4e5f8a6f24b60fd9c26bd1453310f881e3 100755 (executable)
@@ -678,4 +678,61 @@ test_expect_success 'status showing detached from a tag' '
        test_i18ncmp expected actual
 '
 
+test_expect_success 'status while reverting commit (conflicts)' '
+       git checkout master &&
+       echo before >to-revert.txt &&
+       test_commit before to-revert.txt &&
+       echo old >to-revert.txt &&
+       test_commit old to-revert.txt &&
+       echo new >to-revert.txt &&
+       test_commit new to-revert.txt &&
+       test_must_fail git revert HEAD^ &&
+       cat >expected <<-EOF
+       # On branch master
+       # You are currently reverting a commit.
+       #   (fix conflicts and run "git revert --continue")
+       #   (use "git revert --abort" to cancel the revert operation)
+       #
+       # Unmerged paths:
+       #   (use "git reset HEAD <file>..." to unstage)
+       #   (use "git add <file>..." to mark resolution)
+       #
+       #       both modified:      to-revert.txt
+       #
+       no changes added to commit (use "git add" and/or "git commit -a")
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+test_expect_success 'status while reverting commit (conflicts resolved)' '
+       echo reverted >to-revert.txt &&
+       git add to-revert.txt &&
+       cat >expected <<-EOF
+       # On branch master
+       # You are currently reverting a commit.
+       #   (all conflicts fixed: run "git revert --continue")
+       #   (use "git revert --abort" to cancel the revert operation)
+       #
+       # Changes to be committed:
+       #   (use "git reset HEAD <file>..." to unstage)
+       #
+       #       modified:   to-revert.txt
+       #
+       # Untracked files not listed (use -u option to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
+test_expect_success 'status after reverting commit' '
+       git revert --continue &&
+       cat >expected <<-\EOF
+       # On branch master
+       nothing to commit (use -u to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual
+'
+
 test_done
index cea8e55d8bc1d9117a6104c4181be9ff875c3ffa..39f888bcc8b6cb4a32442972a7649b2825dd4d3f 100644 (file)
@@ -965,6 +965,24 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
        wt_status_print_trailer(s);
 }
 
+static void show_revert_in_progress(struct wt_status *s,
+                                       struct wt_status_state *state,
+                                       const char *color)
+{
+       status_printf_ln(s, color, _("You are currently reverting a commit."));
+       if (advice_status_hints) {
+               if (has_unmerged(s))
+                       status_printf_ln(s, color,
+                               _("  (fix conflicts and run \"git revert --continue\")"));
+               else
+                       status_printf_ln(s, color,
+                               _("  (all conflicts fixed: run \"git revert --continue\")"));
+               status_printf_ln(s, color,
+                       _("  (use \"git revert --abort\" to cancel the revert operation)"));
+       }
+       wt_status_print_trailer(s);
+}
+
 static void show_bisect_in_progress(struct wt_status *s,
                                struct wt_status_state *state,
                                const char *color)
@@ -1113,6 +1131,9 @@ void wt_status_get_state(struct wt_status_state *state,
                state->bisect_in_progress = 1;
                state->branch = read_and_strip_branch("BISECT_START");
        }
+       if (!stat(git_path("REVERT_HEAD"), &st)) {
+               state->revert_in_progress = 1;
+       }
 
        if (get_detached_from)
                wt_status_get_detached_from(state);
@@ -1130,6 +1151,8 @@ static void wt_status_print_state(struct wt_status *s,
                show_rebase_in_progress(s, state, state_color);
        else if (state->cherry_pick_in_progress)
                show_cherry_pick_in_progress(s, state, state_color);
+       else if (state->revert_in_progress)
+               show_revert_in_progress(s, state, state_color);
        if (state->bisect_in_progress)
                show_bisect_in_progress(s, state, state_color);
 }
index be7a016173487780fdd4d37e24b4a47fcb766454..35cd6cb669d48a7029c74c325167b92721b3a0ac 100644 (file)
@@ -80,6 +80,7 @@ struct wt_status_state {
        int rebase_interactive_in_progress;
        int cherry_pick_in_progress;
        int bisect_in_progress;
+       int revert_in_progress;
        char *branch;
        char *onto;
        char *detached_from;