am: support --quit
Among the "in progress" commands, only git-am and git-merge do not support --quit. Support --quit in git-am too. 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
Feb 14, 2018 at 18:16 UTC
65ed8ff376c4fdd8dd560b3ddbf7d6cd771f860e
4 files changed
+28
-4
Documentation/git-am.txt
+5
-1
@@ -16,7 +16,7 @@ SYNOPSIS
16
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
17
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
18
[(<mbox> | <Maildir>)...]
19
-'git am' (--continue | --skip | --abort)
19
+'git am' (--continue | --skip | --abort | --quit)
20
21
DESCRIPTION
22
-----------
@@ -167,6 +167,10 @@ default. You can use `--no-utf8` to override this.
167
--abort::
168
Restore the original branch and abort the patching operation.
169
170
+--quit::
171
+ Abort the patching operation but keep HEAD and the index
172
+ untouched.
173
+
174
DISCUSSION
175
----------
176
builtin/am.c
+10
-2
@@ -2149,7 +2149,8 @@ enum resume_mode {
2149
RESUME_APPLY,
2150
RESUME_RESOLVED,
2151
RESUME_SKIP,
2152
- RESUME_ABORT
2152
+ RESUME_ABORT,
2153
+ RESUME_QUIT
2154
};
2155
2156
static int git_am_config(const char *k, const char *v, void *cb)
@@ -2249,6 +2250,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2250
OPT_CMDMODE(0, "abort", &resume,
2251
N_("restore the original branch and abort the patching operation."),
2252
RESUME_ABORT),
2253
+ OPT_CMDMODE(0, "quit", &resume,
2254
+ N_("abort the patching operation but keep HEAD where it is."),
2255
+ RESUME_QUIT),
2256
OPT_BOOL(0, "committer-date-is-author-date",
2257
&state.committer_date_is_author_date,
2258
N_("lie about committer date")),
@@ -2317,7 +2321,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2321
* stray directories.
2322
*/
2323
if (file_exists(state.dir) && !state.rebasing) {
2320
- if (resume == RESUME_ABORT) {
2324
+ if (resume == RESUME_ABORT || resume == RESUME_QUIT) {
2325
am_destroy(&state);
2326
am_state_release(&state);
2327
return 0;
@@ -2359,6 +2363,10 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2363
case RESUME_ABORT:
2364
am_abort(&state);
2365
break;
2366
+ case RESUME_QUIT:
2367
+ am_rerere_clear();
2368
+ am_destroy(&state);
2369
+ break;
2370
default:
2371
die("BUG: invalid resume value");
2372
}
contrib/completion/git-completion.bash
+1
-1
@@ -1077,7 +1077,7 @@ _git_am ()
1077
{
1078
__git_find_repo_path
1079
if [ -d "$__git_repo_path"/rebase-apply ]; then
1080
- __gitcomp "--skip --continue --resolved --abort"
1080
+ __gitcomp "--skip --continue --resolved --abort --quit"
1081
return
1082
fi
1083
case "$cur" in
t/t4150-am.sh
+12
@@ -1045,4 +1045,16 @@ test_expect_success 'am works with multi-line in-body headers' '
1045
git cat-file commit HEAD | grep "^$LONG$"
1046
'
1047
1048
+test_expect_success 'am --quit keeps HEAD where it is' '
1049
+ mkdir .git/rebase-apply &&
1050
+ >.git/rebase-apply/last &&
1051
+ >.git/rebase-apply/next &&
1052
+ git rev-parse HEAD^ >.git/ORIG_HEAD &&
1053
+ git rev-parse HEAD >expected &&
1054
+ git am --quit &&
1055
+ test_path_is_missing .git/rebase-apply &&
1056
+ git rev-parse HEAD >actual &&
1057
+ test_cmp expected actual
1058
+'
1059
+
1060
test_done