revert: Remove sequencer state when no commits are pending

When cherry-pick or revert is called on a list of commits, and a conflict encountered somewhere in the middle, the data in ".git/sequencer" is required to continue the operation. However, when a conflict is encountered in the very last commit, the user will have to "continue" after resolving the conflict and committing just so that the sequencer state is removed. This is how the current "rebase -i" script works as well. $ git cherry-pick foo..bar ... conflict encountered while picking "bar" ... $ echo "resolved" >problematicfile $ git add problematicfile $ git commit $ git cherry-pick --continue # This would be a no-op Change this so that the sequencer state is cleared when a conflict is encountered in the last commit. Incidentally, this patch makes sure that some existing tests don't break when features like "--reset" and "--continue" are implemented later in the series. A better way to implement this feature is to get the last "git commit" to remove the sequencer state. However, that requires tighter coupling between "git commit" and the sequencer, a goal that can be pursued once the sequencer is made more general. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Aug 4, 2011 at 16:09 UTC 2d27daa91da1d6376916533de2ec4b50e6acc925
2 files changed +35 -1
builtin/revert.c
+11 -1
@@ -763,8 +763,18 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
763 for (cur = todo_list; cur; cur = cur->next) {
764 save_todo(cur, opts);
765 res = do_pick_commit(cur->item, opts);
766 - if (res)
766 + if (res) {
767 + if (!cur->next)
768 + /*
769 + * An error was encountered while
770 + * picking the last commit; the
771 + * sequencer state is useless now --
772 + * the user simply needs to resolve
773 + * the conflict and commit
774 + */
775 + remove_sequencer_state(0);
776 return res;
777 + }
778 }
779
780 /*
t/t3510-cherry-pick-sequence.sh
+24
@@ -82,4 +82,28 @@ test_expect_success '--reset cleans up sequencer state' '
82 test_path_is_missing .git/sequencer
83 '
84
85 +test_expect_success 'cherry-pick cleans up sequencer state when one commit is left' '
86 + pristine_detach initial &&
87 + test_must_fail git cherry-pick base..picked &&
88 + test_path_is_missing .git/sequencer &&
89 + echo "resolved" >foo &&
90 + git add foo &&
91 + git commit &&
92 + {
93 + git rev-list HEAD |
94 + git diff-tree --root --stdin |
95 + sed "s/$_x40/OBJID/g"
96 + } >actual &&
97 + cat >expect <<-\EOF &&
98 + OBJID
99 + :100644 100644 OBJID OBJID M foo
100 + OBJID
101 + :100644 100644 OBJID OBJID M unrelated
102 + OBJID
103 + :000000 100644 OBJID OBJID A foo
104 + :000000 100644 OBJID OBJID A unrelated
105 + EOF
106 + test_cmp expect actual
107 +'
108 +
109 test_done