Skip to content

Commit db4ef44

Browse files
moygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc3e4eb commit db4ef44

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

t/t7512-status-help.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,61 @@ test_expect_success 'status showing detached from a tag' '
678678
test_i18ncmp expected actual
679679
'
680680

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+
681738
test_done

wt-status.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,24 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
965965
wt_status_print_trailer(s);
966966
}
967967

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+
968986
static void show_bisect_in_progress(struct wt_status *s,
969987
struct wt_status_state *state,
970988
const char *color)
@@ -1113,6 +1131,9 @@ void wt_status_get_state(struct wt_status_state *state,
11131131
state->bisect_in_progress = 1;
11141132
state->branch = read_and_strip_branch("BISECT_START");
11151133
}
1134+
if (!stat(git_path("REVERT_HEAD"), &st)) {
1135+
state->revert_in_progress = 1;
1136+
}
11161137

11171138
if (get_detached_from)
11181139
wt_status_get_detached_from(state);
@@ -1130,6 +1151,8 @@ static void wt_status_print_state(struct wt_status *s,
11301151
show_rebase_in_progress(s, state, state_color);
11311152
else if (state->cherry_pick_in_progress)
11321153
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);
11331156
if (state->bisect_in_progress)
11341157
show_bisect_in_progress(s, state, state_color);
11351158
}

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct wt_status_state {
8080
int rebase_interactive_in_progress;
8181
int cherry_pick_in_progress;
8282
int bisect_in_progress;
83+
int revert_in_progress;
8384
char *branch;
8485
char *onto;
8586
char *detached_from;

0 commit comments

Comments
 (0)