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
This commit is contained in:
Junio C Hamano 2013-04-07 14:32:03 -07:00
commit e64734b6a0
3 changed files with 87 additions and 0 deletions

View File

@ -678,4 +678,62 @@ 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 &&
TO_REVERT=$(git rev-parse --short HEAD^) &&
test_must_fail git revert $TO_REVERT &&
cat >expected <<-EOF
# On branch master
# You are currently reverting commit $TO_REVERT.
# (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 commit $TO_REVERT.
# (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

View File

@ -965,6 +965,25 @@ 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 commit %s."),
find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
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)
@ -1086,6 +1105,7 @@ void wt_status_get_state(struct wt_status_state *state,
int get_detached_from)
{
struct stat st;
unsigned char sha1[20];
if (!stat(git_path("MERGE_HEAD"), &st)) {
state->merge_in_progress = 1;
@ -1113,6 +1133,11 @@ 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) &&
!get_sha1("REVERT_HEAD", sha1)) {
state->revert_in_progress = 1;
hashcpy(state->revert_head_sha1, sha1);
}
if (get_detached_from)
wt_status_get_detached_from(state);
@ -1130,6 +1155,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);
}

View File

@ -80,10 +80,12 @@ 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;
unsigned char detached_sha1[20];
unsigned char revert_head_sha1[20];
};
void wt_status_prepare(struct wt_status *s);