Merge branch 'pw/clean-sequencer-state-upon-final-commit'
"git chery-pick" (and "revert" that shares the same runtime engine) that deals with multiple commits got confused when the final step gets stopped with a conflict and the user concluded the sequence with "git commit". Attempt to fix it by cleaning up the state files used by these commands in such a situation. * pw/clean-sequencer-state-upon-final-commit: fix cherry-pick/revert status after commit commit/reset: try to clean up sequencer state
This commit is contained in:
commit
b51a0fdc38
4
branch.c
4
branch.c
@ -5,6 +5,7 @@
|
|||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "refspec.h"
|
#include "refspec.h"
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
|
#include "sequencer.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "worktree.h"
|
#include "worktree.h"
|
||||||
|
|
||||||
@ -339,8 +340,7 @@ void create_branch(struct repository *r,
|
|||||||
|
|
||||||
void remove_branch_state(struct repository *r)
|
void remove_branch_state(struct repository *r)
|
||||||
{
|
{
|
||||||
unlink(git_path_cherry_pick_head(r));
|
sequencer_post_commit_cleanup(r);
|
||||||
unlink(git_path_revert_head(r));
|
|
||||||
unlink(git_path_merge_head(r));
|
unlink(git_path_merge_head(r));
|
||||||
unlink(git_path_merge_rr(r));
|
unlink(git_path_merge_rr(r));
|
||||||
unlink(git_path_merge_msg(r));
|
unlink(git_path_merge_msg(r));
|
||||||
|
@ -1658,8 +1658,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
die("%s", err.buf);
|
die("%s", err.buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(git_path_cherry_pick_head(the_repository));
|
sequencer_post_commit_cleanup(the_repository);
|
||||||
unlink(git_path_revert_head(the_repository));
|
|
||||||
unlink(git_path_merge_head(the_repository));
|
unlink(git_path_merge_head(the_repository));
|
||||||
unlink(git_path_merge_msg(the_repository));
|
unlink(git_path_merge_msg(the_repository));
|
||||||
unlink(git_path_merge_mode(the_repository));
|
unlink(git_path_merge_mode(the_repository));
|
||||||
|
86
sequencer.c
86
sequencer.c
@ -2168,6 +2168,41 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
|
|||||||
return !item->commit;
|
return !item->commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sequencer_get_last_command(struct repository *r, enum replay_action *action)
|
||||||
|
{
|
||||||
|
struct todo_item item;
|
||||||
|
char *eol;
|
||||||
|
const char *todo_file;
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
todo_file = git_path_todo_file();
|
||||||
|
if (strbuf_read_file(&buf, todo_file, 0) < 0) {
|
||||||
|
if (errno == ENOENT)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return error_errno("unable to open '%s'", todo_file);
|
||||||
|
}
|
||||||
|
eol = strchrnul(buf.buf, '\n');
|
||||||
|
if (buf.buf != eol && eol[-1] == '\r')
|
||||||
|
eol--; /* strip Carriage Return */
|
||||||
|
if (parse_insn_line(r, &item, buf.buf, buf.buf, eol))
|
||||||
|
goto fail;
|
||||||
|
if (item.command == TODO_PICK)
|
||||||
|
*action = REPLAY_PICK;
|
||||||
|
else if (item.command == TODO_REVERT)
|
||||||
|
*action = REPLAY_REVERT;
|
||||||
|
else
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
strbuf_release(&buf);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
|
int todo_list_parse_insn_buffer(struct repository *r, char *buf,
|
||||||
struct todo_list *todo_list)
|
struct todo_list *todo_list)
|
||||||
{
|
{
|
||||||
@ -2251,6 +2286,57 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int have_finished_the_last_pick(void)
|
||||||
|
{
|
||||||
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
const char *eol;
|
||||||
|
const char *todo_path = git_path_todo_file();
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (strbuf_read_file(&buf, todo_path, 0) < 0) {
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
error_errno("unable to open '%s'", todo_path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* If there is only one line then we are done */
|
||||||
|
eol = strchr(buf.buf, '\n');
|
||||||
|
if (!eol || !eol[1])
|
||||||
|
ret = 1;
|
||||||
|
|
||||||
|
strbuf_release(&buf);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sequencer_post_commit_cleanup(struct repository *r)
|
||||||
|
{
|
||||||
|
struct replay_opts opts = REPLAY_OPTS_INIT;
|
||||||
|
int need_cleanup = 0;
|
||||||
|
|
||||||
|
if (file_exists(git_path_cherry_pick_head(r))) {
|
||||||
|
unlink(git_path_cherry_pick_head(r));
|
||||||
|
opts.action = REPLAY_PICK;
|
||||||
|
need_cleanup = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists(git_path_revert_head(r))) {
|
||||||
|
unlink(git_path_revert_head(r));
|
||||||
|
opts.action = REPLAY_REVERT;
|
||||||
|
need_cleanup = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!need_cleanup)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!have_finished_the_last_pick())
|
||||||
|
return;
|
||||||
|
|
||||||
|
sequencer_remove_state(&opts);
|
||||||
|
}
|
||||||
|
|
||||||
static int read_populate_todo(struct repository *r,
|
static int read_populate_todo(struct repository *r,
|
||||||
struct todo_list *todo_list,
|
struct todo_list *todo_list,
|
||||||
struct replay_opts *opts)
|
struct replay_opts *opts)
|
||||||
|
@ -200,3 +200,6 @@ int read_author_script(const char *path, char **name, char **email, char **date,
|
|||||||
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
|
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
|
||||||
int write_basic_state(struct replay_opts *opts, const char *head_name,
|
int write_basic_state(struct replay_opts *opts, const char *head_name,
|
||||||
struct commit *onto, const char *orig_head);
|
struct commit *onto, const char *orig_head);
|
||||||
|
void sequencer_post_commit_cleanup(struct repository *r);
|
||||||
|
int sequencer_get_last_command(struct repository* r,
|
||||||
|
enum replay_action *action);
|
||||||
|
@ -161,6 +161,25 @@ test_expect_success 'successful commit clears CHERRY_PICK_HEAD' '
|
|||||||
|
|
||||||
test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
|
test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
|
||||||
'
|
'
|
||||||
|
test_expect_success 'successful final commit clears cherry-pick state' '
|
||||||
|
pristine_detach initial &&
|
||||||
|
|
||||||
|
test_must_fail git cherry-pick base picked-signed &&
|
||||||
|
echo resolved >foo &&
|
||||||
|
test_path_is_file .git/sequencer/todo &&
|
||||||
|
git commit -a &&
|
||||||
|
test_must_fail test_path_exists .git/sequencer
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'reset after final pick clears cherry-pick state' '
|
||||||
|
pristine_detach initial &&
|
||||||
|
|
||||||
|
test_must_fail git cherry-pick base picked-signed &&
|
||||||
|
echo resolved >foo &&
|
||||||
|
test_path_is_file .git/sequencer/todo &&
|
||||||
|
git reset &&
|
||||||
|
test_must_fail test_path_exists .git/sequencer
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'failed cherry-pick produces dirty index' '
|
test_expect_success 'failed cherry-pick produces dirty index' '
|
||||||
pristine_detach initial &&
|
pristine_detach initial &&
|
||||||
@ -361,6 +380,26 @@ test_expect_success 'failed commit does not clear REVERT_HEAD' '
|
|||||||
test_cmp_rev picked REVERT_HEAD
|
test_cmp_rev picked REVERT_HEAD
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'successful final commit clears revert state' '
|
||||||
|
pristine_detach picked-signed &&
|
||||||
|
|
||||||
|
test_must_fail git revert picked-signed base &&
|
||||||
|
echo resolved >foo &&
|
||||||
|
test_path_is_file .git/sequencer/todo &&
|
||||||
|
git commit -a &&
|
||||||
|
test_must_fail test_path_exists .git/sequencer
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'reset after final pick clears revert state' '
|
||||||
|
pristine_detach picked-signed &&
|
||||||
|
|
||||||
|
test_must_fail git revert picked-signed base &&
|
||||||
|
echo resolved >foo &&
|
||||||
|
test_path_is_file .git/sequencer/todo &&
|
||||||
|
git reset &&
|
||||||
|
test_must_fail test_path_exists .git/sequencer
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'revert conflict, diff3 -m style' '
|
test_expect_success 'revert conflict, diff3 -m style' '
|
||||||
pristine_detach initial &&
|
pristine_detach initial &&
|
||||||
git config merge.conflictstyle diff3 &&
|
git config merge.conflictstyle diff3 &&
|
||||||
|
@ -780,6 +780,24 @@ EOF
|
|||||||
test_i18ncmp expected actual
|
test_i18ncmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status when cherry-picking after committing conflict resolution' '
|
||||||
|
git reset --hard cherry_branch &&
|
||||||
|
test_when_finished "git cherry-pick --abort" &&
|
||||||
|
test_must_fail git cherry-pick cherry_branch_second one_cherry &&
|
||||||
|
echo end >main.txt &&
|
||||||
|
git commit -a &&
|
||||||
|
cat >expected <<EOF &&
|
||||||
|
On branch cherry_branch
|
||||||
|
Cherry-pick currently in progress.
|
||||||
|
(run "git cherry-pick --continue" to continue)
|
||||||
|
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
|
||||||
|
|
||||||
|
nothing to commit (use -u to show untracked files)
|
||||||
|
EOF
|
||||||
|
git status --untracked-files=no >actual &&
|
||||||
|
test_i18ncmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'status showing detached at and from a tag' '
|
test_expect_success 'status showing detached at and from a tag' '
|
||||||
test_commit atag tagging &&
|
test_commit atag tagging &&
|
||||||
git checkout atag &&
|
git checkout atag &&
|
||||||
@ -857,6 +875,24 @@ EOF
|
|||||||
test_i18ncmp expected actual
|
test_i18ncmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status while reverting after committing conflict resolution' '
|
||||||
|
test_when_finished "git revert --abort" &&
|
||||||
|
git reset --hard new &&
|
||||||
|
test_must_fail git revert old new &&
|
||||||
|
echo reverted >to-revert.txt &&
|
||||||
|
git commit -a &&
|
||||||
|
cat >expected <<EOF &&
|
||||||
|
On branch master
|
||||||
|
Revert currently in progress.
|
||||||
|
(run "git revert --continue" to continue)
|
||||||
|
(use "git revert --abort" to cancel the revert operation)
|
||||||
|
|
||||||
|
nothing to commit (use -u to show untracked files)
|
||||||
|
EOF
|
||||||
|
git status --untracked-files=no >actual &&
|
||||||
|
test_i18ncmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'prepare for different number of commits rebased' '
|
test_expect_success 'prepare for different number of commits rebased' '
|
||||||
git reset --hard master &&
|
git reset --hard master &&
|
||||||
git checkout -b several_commits &&
|
git checkout -b several_commits &&
|
||||||
|
39
wt-status.c
39
wt-status.c
@ -17,6 +17,7 @@
|
|||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "worktree.h"
|
#include "worktree.h"
|
||||||
#include "lockfile.h"
|
#include "lockfile.h"
|
||||||
|
#include "sequencer.h"
|
||||||
|
|
||||||
static const char cut_line[] =
|
static const char cut_line[] =
|
||||||
"------------------------ >8 ------------------------\n";
|
"------------------------ >8 ------------------------\n";
|
||||||
@ -1386,12 +1387,22 @@ static void show_rebase_in_progress(struct wt_status *s,
|
|||||||
static void show_cherry_pick_in_progress(struct wt_status *s,
|
static void show_cherry_pick_in_progress(struct wt_status *s,
|
||||||
const char *color)
|
const char *color)
|
||||||
{
|
{
|
||||||
status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
|
if (is_null_oid(&s->state.cherry_pick_head_oid))
|
||||||
find_unique_abbrev(&s->state.cherry_pick_head_oid, DEFAULT_ABBREV));
|
status_printf_ln(s, color,
|
||||||
|
_("Cherry-pick currently in progress."));
|
||||||
|
else
|
||||||
|
status_printf_ln(s, color,
|
||||||
|
_("You are currently cherry-picking commit %s."),
|
||||||
|
find_unique_abbrev(&s->state.cherry_pick_head_oid,
|
||||||
|
DEFAULT_ABBREV));
|
||||||
|
|
||||||
if (s->hints) {
|
if (s->hints) {
|
||||||
if (has_unmerged(s))
|
if (has_unmerged(s))
|
||||||
status_printf_ln(s, color,
|
status_printf_ln(s, color,
|
||||||
_(" (fix conflicts and run \"git cherry-pick --continue\")"));
|
_(" (fix conflicts and run \"git cherry-pick --continue\")"));
|
||||||
|
else if (is_null_oid(&s->state.cherry_pick_head_oid))
|
||||||
|
status_printf_ln(s, color,
|
||||||
|
_(" (run \"git cherry-pick --continue\" to continue)"));
|
||||||
else
|
else
|
||||||
status_printf_ln(s, color,
|
status_printf_ln(s, color,
|
||||||
_(" (all conflicts fixed: run \"git cherry-pick --continue\")"));
|
_(" (all conflicts fixed: run \"git cherry-pick --continue\")"));
|
||||||
@ -1404,12 +1415,21 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
|
|||||||
static void show_revert_in_progress(struct wt_status *s,
|
static void show_revert_in_progress(struct wt_status *s,
|
||||||
const char *color)
|
const char *color)
|
||||||
{
|
{
|
||||||
status_printf_ln(s, color, _("You are currently reverting commit %s."),
|
if (is_null_oid(&s->state.revert_head_oid))
|
||||||
find_unique_abbrev(&s->state.revert_head_oid, DEFAULT_ABBREV));
|
status_printf_ln(s, color,
|
||||||
|
_("Revert currently in progress."));
|
||||||
|
else
|
||||||
|
status_printf_ln(s, color,
|
||||||
|
_("You are currently reverting commit %s."),
|
||||||
|
find_unique_abbrev(&s->state.revert_head_oid,
|
||||||
|
DEFAULT_ABBREV));
|
||||||
if (s->hints) {
|
if (s->hints) {
|
||||||
if (has_unmerged(s))
|
if (has_unmerged(s))
|
||||||
status_printf_ln(s, color,
|
status_printf_ln(s, color,
|
||||||
_(" (fix conflicts and run \"git revert --continue\")"));
|
_(" (fix conflicts and run \"git revert --continue\")"));
|
||||||
|
else if (is_null_oid(&s->state.revert_head_oid))
|
||||||
|
status_printf_ln(s, color,
|
||||||
|
_(" (run \"git revert --continue\" to continue)"));
|
||||||
else
|
else
|
||||||
status_printf_ln(s, color,
|
status_printf_ln(s, color,
|
||||||
_(" (all conflicts fixed: run \"git revert --continue\")"));
|
_(" (all conflicts fixed: run \"git revert --continue\")"));
|
||||||
@ -1580,6 +1600,7 @@ void wt_status_get_state(struct repository *r,
|
|||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
|
enum replay_action action;
|
||||||
|
|
||||||
if (!stat(git_path_merge_head(r), &st)) {
|
if (!stat(git_path_merge_head(r), &st)) {
|
||||||
wt_status_check_rebase(NULL, state);
|
wt_status_check_rebase(NULL, state);
|
||||||
@ -1597,7 +1618,15 @@ void wt_status_get_state(struct repository *r,
|
|||||||
state->revert_in_progress = 1;
|
state->revert_in_progress = 1;
|
||||||
oidcpy(&state->revert_head_oid, &oid);
|
oidcpy(&state->revert_head_oid, &oid);
|
||||||
}
|
}
|
||||||
|
if (!sequencer_get_last_command(r, &action)) {
|
||||||
|
if (action == REPLAY_PICK) {
|
||||||
|
state->cherry_pick_in_progress = 1;
|
||||||
|
oidcpy(&state->cherry_pick_head_oid, &null_oid);
|
||||||
|
} else {
|
||||||
|
state->revert_in_progress = 1;
|
||||||
|
oidcpy(&state->revert_head_oid, &null_oid);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (get_detached_from)
|
if (get_detached_from)
|
||||||
wt_status_get_detached_from(r, state);
|
wt_status_get_detached_from(r, state);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user