diff options
-rw-r--r-- | builtin/revert.c | 26 | ||||
-rwxr-xr-x | t/t3510-cherry-pick-sequence.sh | 12 |
2 files changed, 38 insertions, 0 deletions
diff --git a/builtin/revert.c b/builtin/revert.c index f7f4bb3577..5785ff9941 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -1072,6 +1072,12 @@ static int sequencer_continue(struct replay_opts *opts) return pick_commits(todo_list, opts); } +static int single_pick(struct commit *cmit, struct replay_opts *opts) +{ + setenv(GIT_REFLOG_ACTION, action_name(opts), 0); + return do_pick_commit(cmit, opts); +} + static int pick_revisions(struct replay_opts *opts) { struct commit_list *todo_list = NULL; @@ -1097,6 +1103,26 @@ static int pick_revisions(struct replay_opts *opts) return sequencer_continue(opts); /* + * If we were called as "git cherry-pick <commit>", just + * cherry-pick/revert it, set CHERRY_PICK_HEAD / + * REVERT_HEAD, and don't touch the sequencer state. + * This means it is possible to cherry-pick in the middle + * of a cherry-pick sequence. + */ + if (opts->revs->cmdline.nr == 1 && + opts->revs->cmdline.rev->whence == REV_CMD_REV && + opts->revs->no_walk && + !opts->revs->cmdline.rev->flags) { + struct commit *cmit; + if (prepare_revision_walk(opts->revs)) + die(_("revision walk setup failed")); + cmit = get_revision(opts->revs); + if (!cmit || get_revision(opts->revs)) + die("BUG: expected exactly one commit from walk"); + return single_pick(cmit, opts); + } + + /* * Start a new cherry-pick/ revert sequence; but * first, make sure that an existing one isn't in * progress diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh index 56c95ec18c..98a27a23ea 100755 --- a/t/t3510-cherry-pick-sequence.sh +++ b/t/t3510-cherry-pick-sequence.sh @@ -50,6 +50,18 @@ test_expect_success 'cherry-pick persists data on failure' ' test_path_is_file .git/sequencer/opts ' +test_expect_success 'cherry-pick mid-cherry-pick-sequence' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test_cmp_rev picked CHERRY_PICK_HEAD && + # "oops, I forgot that these patches rely on the change from base" + git checkout HEAD foo && + git cherry-pick base && + git cherry-pick picked && + git cherry-pick --continue && + git diff --exit-code anotherpick +' + test_expect_success 'cherry-pick persists opts correctly' ' pristine_detach initial && test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick && |