Skip to content

Commit 2d27daa

Browse files
artagnongitster
authored andcommitted
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 <[email protected]> Acked-by: Jonathan Nieder <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 95eb88d commit 2d27daa

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

builtin/revert.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,18 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
763763
for (cur = todo_list; cur; cur = cur->next) {
764764
save_todo(cur, opts);
765765
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);
767776
return res;
777+
}
768778
}
769779

770780
/*

t/t3510-cherry-pick-sequence.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,28 @@ test_expect_success '--reset cleans up sequencer state' '
8282
test_path_is_missing .git/sequencer
8383
'
8484

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+
85109
test_done

0 commit comments

Comments
 (0)