Skip to content

Commit 3e7dd99

Browse files
pcloudsgitster
authored andcommitted
cherry-pick: fix --quit not deleting CHERRY_PICK_HEAD
--quit is supposed to be --abort but without restoring HEAD. Leaving CHERRY_PICK_HEAD behind could make other commands mistake that cherry-pick is still ongoing (e.g. "git commit --amend" will refuse to work). Clean it too. For --abort, this job of deleting CHERRY_PICK_HEAD is on "git reset" so we don't need to do anything else. But let's add extra checks in --abort tests to confirm. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4dde7b8 commit 3e7dd99

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

builtin/revert.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "rerere.h"
88
#include "dir.h"
99
#include "sequencer.h"
10+
#include "branch.h"
1011

1112
/*
1213
* This implements the builtins revert and cherry-pick.
@@ -191,8 +192,12 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
191192
opts->gpg_sign = xstrdup_or_null(opts->gpg_sign);
192193
opts->strategy = xstrdup_or_null(opts->strategy);
193194

194-
if (cmd == 'q')
195-
return sequencer_remove_state(opts);
195+
if (cmd == 'q') {
196+
int ret = sequencer_remove_state(opts);
197+
if (!ret)
198+
remove_branch_state();
199+
return ret;
200+
}
196201
if (cmd == 'c')
197202
return sequencer_continue(opts);
198203
if (cmd == 'a')

t/t3510-cherry-pick-sequence.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ test_expect_success '--quit cleans up sequencer state' '
103103
pristine_detach initial &&
104104
test_expect_code 1 git cherry-pick base..picked &&
105105
git cherry-pick --quit &&
106-
test_path_is_missing .git/sequencer
106+
test_path_is_missing .git/sequencer &&
107+
test_path_is_missing .git/CHERRY_PICK_HEAD
107108
'
108109

109110
test_expect_success '--quit keeps HEAD and conflicted index intact' '
@@ -132,6 +133,7 @@ test_expect_success '--abort to cancel multiple cherry-pick' '
132133
test_expect_code 1 git cherry-pick base..anotherpick &&
133134
git cherry-pick --abort &&
134135
test_path_is_missing .git/sequencer &&
136+
test_path_is_missing .git/CHERRY_PICK_HEAD &&
135137
test_cmp_rev initial HEAD &&
136138
git update-index --refresh &&
137139
git diff-index --exit-code HEAD
@@ -142,6 +144,7 @@ test_expect_success '--abort to cancel single cherry-pick' '
142144
test_expect_code 1 git cherry-pick picked &&
143145
git cherry-pick --abort &&
144146
test_path_is_missing .git/sequencer &&
147+
test_path_is_missing .git/CHERRY_PICK_HEAD &&
145148
test_cmp_rev initial HEAD &&
146149
git update-index --refresh &&
147150
git diff-index --exit-code HEAD
@@ -162,6 +165,7 @@ test_expect_success 'cherry-pick --abort to cancel multiple revert' '
162165
test_expect_code 1 git revert base..picked &&
163166
git cherry-pick --abort &&
164167
test_path_is_missing .git/sequencer &&
168+
test_path_is_missing .git/CHERRY_PICK_HEAD &&
165169
test_cmp_rev anotherpick HEAD &&
166170
git update-index --refresh &&
167171
git diff-index --exit-code HEAD
@@ -239,6 +243,7 @@ test_expect_success '--abort after last commit in sequence' '
239243
test_expect_code 1 git cherry-pick base..picked &&
240244
git cherry-pick --abort &&
241245
test_path_is_missing .git/sequencer &&
246+
test_path_is_missing .git/CHERRY_PICK_HEAD &&
242247
test_cmp_rev initial HEAD &&
243248
git update-index --refresh &&
244249
git diff-index --exit-code HEAD

0 commit comments

Comments
 (0)