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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 16, 2018 at 18:06 UTC 3e7dd9920823fc2a88f8ec5390bd100d707f9129
2 files changed +13 -3
builtin/revert.c
+7 -2
@@ -7,6 +7,7 @@
7 #include "rerere.h"
8 #include "dir.h"
9 #include "sequencer.h"
10 +#include "branch.h"
11
12 /*
13 * 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)
192 opts->gpg_sign = xstrdup_or_null(opts->gpg_sign);
193 opts->strategy = xstrdup_or_null(opts->strategy);
194
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 + }
201 if (cmd == 'c')
202 return sequencer_continue(opts);
203 if (cmd == 'a')
t/t3510-cherry-pick-sequence.sh
+6 -1
@@ -103,7 +103,8 @@ test_expect_success '--quit cleans up sequencer state' '
103 pristine_detach initial &&
104 test_expect_code 1 git cherry-pick base..picked &&
105 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
108 '
109
110 test_expect_success '--quit keeps HEAD and conflicted index intact' '
@@ -132,6 +133,7 @@ test_expect_success '--abort to cancel multiple cherry-pick' '
133 test_expect_code 1 git cherry-pick base..anotherpick &&
134 git cherry-pick --abort &&
135 test_path_is_missing .git/sequencer &&
136 + test_path_is_missing .git/CHERRY_PICK_HEAD &&
137 test_cmp_rev initial HEAD &&
138 git update-index --refresh &&
139 git diff-index --exit-code HEAD
@@ -142,6 +144,7 @@ test_expect_success '--abort to cancel single cherry-pick' '
144 test_expect_code 1 git cherry-pick picked &&
145 git cherry-pick --abort &&
146 test_path_is_missing .git/sequencer &&
147 + test_path_is_missing .git/CHERRY_PICK_HEAD &&
148 test_cmp_rev initial HEAD &&
149 git update-index --refresh &&
150 git diff-index --exit-code HEAD
@@ -162,6 +165,7 @@ test_expect_success 'cherry-pick --abort to cancel multiple revert' '
165 test_expect_code 1 git revert base..picked &&
166 git cherry-pick --abort &&
167 test_path_is_missing .git/sequencer &&
168 + test_path_is_missing .git/CHERRY_PICK_HEAD &&
169 test_cmp_rev anotherpick HEAD &&
170 git update-index --refresh &&
171 git diff-index --exit-code HEAD
@@ -239,6 +243,7 @@ test_expect_success '--abort after last commit in sequence' '
243 test_expect_code 1 git cherry-pick base..picked &&
244 git cherry-pick --abort &&
245 test_path_is_missing .git/sequencer &&
246 + test_path_is_missing .git/CHERRY_PICK_HEAD &&
247 test_cmp_rev initial HEAD &&
248 git update-index --refresh &&
249 git diff-index --exit-code HEAD