Skip to content

Commit e64734b

Browse files
committed
Merge branch 'mm/status-during-revert'
"git status" learned to report that you are in the middle of a revert session, just like it does for a cherry-pick and a bisect session. * mm/status-during-revert: status: show commit sha1 in "You are currently reverting" message status: show 'revert' state and status hint
2 parents 88dccb6 + 87e139c commit e64734b

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

t/t7512-status-help.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,62 @@ 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+
TO_REVERT=$(git rev-parse --short HEAD^) &&
690+
test_must_fail git revert $TO_REVERT &&
691+
cat >expected <<-EOF
692+
# On branch master
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)
696+
#
697+
# Unmerged paths:
698+
# (use "git reset HEAD <file>..." to unstage)
699+
# (use "git add <file>..." to mark resolution)
700+
#
701+
# both modified: to-revert.txt
702+
#
703+
no changes added to commit (use "git add" and/or "git commit -a")
704+
EOF
705+
git status --untracked-files=no >actual &&
706+
test_i18ncmp expected actual
707+
'
708+
709+
test_expect_success 'status while reverting commit (conflicts resolved)' '
710+
echo reverted >to-revert.txt &&
711+
git add to-revert.txt &&
712+
cat >expected <<-EOF
713+
# On branch master
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)
717+
#
718+
# Changes to be committed:
719+
# (use "git reset HEAD <file>..." to unstage)
720+
#
721+
# modified: to-revert.txt
722+
#
723+
# Untracked files not listed (use -u option to show untracked files)
724+
EOF
725+
git status --untracked-files=no >actual &&
726+
test_i18ncmp expected actual
727+
'
728+
729+
test_expect_success 'status after reverting commit' '
730+
git revert --continue &&
731+
cat >expected <<-\EOF
732+
# On branch master
733+
nothing to commit (use -u to show untracked files)
734+
EOF
735+
git status --untracked-files=no >actual &&
736+
test_i18ncmp expected actual
737+
'
738+
681739
test_done

wt-status.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,25 @@ 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 commit %s."),
973+
find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
974+
if (advice_status_hints) {
975+
if (has_unmerged(s))
976+
status_printf_ln(s, color,
977+
_(" (fix conflicts and run \"git revert --continue\")"));
978+
else
979+
status_printf_ln(s, color,
980+
_(" (all conflicts fixed: run \"git revert --continue\")"));
981+
status_printf_ln(s, color,
982+
_(" (use \"git revert --abort\" to cancel the revert operation)"));
983+
}
984+
wt_status_print_trailer(s);
985+
}
986+
968987
static void show_bisect_in_progress(struct wt_status *s,
969988
struct wt_status_state *state,
970989
const char *color)
@@ -1086,6 +1105,7 @@ void wt_status_get_state(struct wt_status_state *state,
10861105
int get_detached_from)
10871106
{
10881107
struct stat st;
1108+
unsigned char sha1[20];
10891109

10901110
if (!stat(git_path("MERGE_HEAD"), &st)) {
10911111
state->merge_in_progress = 1;
@@ -1113,6 +1133,11 @@ void wt_status_get_state(struct wt_status_state *state,
11131133
state->bisect_in_progress = 1;
11141134
state->branch = read_and_strip_branch("BISECT_START");
11151135
}
1136+
if (!stat(git_path("REVERT_HEAD"), &st) &&
1137+
!get_sha1("REVERT_HEAD", sha1)) {
1138+
state->revert_in_progress = 1;
1139+
hashcpy(state->revert_head_sha1, sha1);
1140+
}
11161141

11171142
if (get_detached_from)
11181143
wt_status_get_detached_from(state);
@@ -1130,6 +1155,8 @@ static void wt_status_print_state(struct wt_status *s,
11301155
show_rebase_in_progress(s, state, state_color);
11311156
else if (state->cherry_pick_in_progress)
11321157
show_cherry_pick_in_progress(s, state, state_color);
1158+
else if (state->revert_in_progress)
1159+
show_revert_in_progress(s, state, state_color);
11331160
if (state->bisect_in_progress)
11341161
show_bisect_in_progress(s, state, state_color);
11351162
}

wt-status.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ 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;
8687
unsigned char detached_sha1[20];
88+
unsigned char revert_head_sha1[20];
8789
};
8890

8991
void wt_status_prepare(struct wt_status *s);

0 commit comments

Comments
 (0)