The final step in unifying the sequencer interface involves making sure that a single-commit pick can be concluded with a '--continue'. $ git cherry-pick foo ... conflict ... $ echo "resolved" >problematicfile $ git add problematicfile $ git sequencer --continue To do this, we have to update our parser that normally reads '.git/sequencer/todo' to read '.git/CHERRY_PICK_HEAD' as a special case before proceeding as usual. Add a new test in 't3510-sequencer.sh' to make sure that this works. Although we have added a similar test for revert in the same patch for symmetry, the test doesn't depend on this patch to work. A single-commit revert operation does not create a '.git/CHERRY_PICK_HEAD' at all: it uses the information in '.git/sequencer' as usual. Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx> --- sequencer.c | 32 ++++++++++++++++++++++++++++---- t/t3510-sequencer.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index 7b10b7b..84df926 100644 --- a/sequencer.c +++ b/sequencer.c @@ -569,12 +569,32 @@ static int parse_insn_buffer(char *buf, struct replay_insn_list **todo_list) return 0; } -static void read_populate_todo(struct replay_insn_list **todo_list) +static void read_populate_todo(struct replay_insn_list **todo_list, int cph_flag) { const char *todo_file = git_path(SEQ_TODO_FILE); struct strbuf buf = STRBUF_INIT; int fd, res; + if (cph_flag) { + struct replay_insn_list item = {0, NULL, NULL}; + const char *name = "CHERRY_PICK_HEAD"; + const char *CHERRY_PICK_HEAD = git_path(name); + + fd = open(CHERRY_PICK_HEAD, O_RDONLY); + if (fd < 0) + die_errno(_("Could not open %s."), CHERRY_PICK_HEAD); + + item.action = REPLAY_PICK; + item.operand = lookup_commit_reference_by_name(name); + + if (!item.operand) + die(_("could not lookup commit %s"), name); + replay_insn_list_append(item.action, item.operand, todo_list); + close(fd); + strbuf_release(&buf); + return; + } + fd = open(todo_file, O_RDONLY); if (fd < 0) die_errno(_("Could not open %s."), todo_file); @@ -792,10 +812,14 @@ int sequencer_pick_revisions(struct replay_opts *opts) remove_sequencer_state(1); return 0; } else if (opts->subcommand == REPLAY_CONTINUE) { - if (!file_exists(git_path(SEQ_TODO_FILE))) - goto error; + if (!file_exists(git_path(SEQ_TODO_FILE))) { + if (!file_exists(git_path("CHERRY_PICK_HEAD"))) + goto error; + read_populate_todo(&todo_list, 1); + } + else + read_populate_todo(&todo_list, 0); read_populate_opts(&opts); - read_populate_todo(&todo_list); if (!index_differs_from("HEAD", 0)) todo_list = todo_list->next; diff --git a/t/t3510-sequencer.sh b/t/t3510-sequencer.sh index 65f2724..f7c3a37 100755 --- a/t/t3510-sequencer.sh +++ b/t/t3510-sequencer.sh @@ -45,6 +45,50 @@ test_expect_success '--continue complains when there are unresolved conflicts' ' test_must_fail git sequencer --continue ' +test_expect_success '--continue continues single-commit cherry-pick' ' + pristine_detach initial && + test_must_fail git cherry-pick anotherpick && + echo "c" >foo && + git add foo && + git sequencer --continue && + test_path_is_missing .git/sequencer && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_cmp expect actual +' + +test_expect_success '--continue continues single-commit revert' ' + pristine_detach initial && + test_must_fail git revert anotherpick && + echo "c" >foo && + git add foo && + git sequencer --continue && + test_path_is_missing .git/sequencer && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_cmp expect actual +' + test_expect_success '--continue continues after conflicts are resolved' ' pristine_detach initial && test_must_fail git cherry-pick base..anotherpick && -- 1.7.6.351.gb35ac.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html