Skip to content

Commit 65ed8ff

Browse files
pcloudsgitster
authored andcommitted
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>
1 parent b2e45c6 commit 65ed8ff

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Documentation/git-am.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SYNOPSIS
1616
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
1717
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
1818
[(<mbox> | <Maildir>)...]
19-
'git am' (--continue | --skip | --abort)
19+
'git am' (--continue | --skip | --abort | --quit)
2020

2121
DESCRIPTION
2222
-----------
@@ -167,6 +167,10 @@ default. You can use `--no-utf8` to override this.
167167
--abort::
168168
Restore the original branch and abort the patching operation.
169169

170+
--quit::
171+
Abort the patching operation but keep HEAD and the index
172+
untouched.
173+
170174
DISCUSSION
171175
----------
172176

builtin/am.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,8 @@ enum resume_mode {
21492149
RESUME_APPLY,
21502150
RESUME_RESOLVED,
21512151
RESUME_SKIP,
2152-
RESUME_ABORT
2152+
RESUME_ABORT,
2153+
RESUME_QUIT
21532154
};
21542155

21552156
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)
22492250
OPT_CMDMODE(0, "abort", &resume,
22502251
N_("restore the original branch and abort the patching operation."),
22512252
RESUME_ABORT),
2253+
OPT_CMDMODE(0, "quit", &resume,
2254+
N_("abort the patching operation but keep HEAD where it is."),
2255+
RESUME_QUIT),
22522256
OPT_BOOL(0, "committer-date-is-author-date",
22532257
&state.committer_date_is_author_date,
22542258
N_("lie about committer date")),
@@ -2317,7 +2321,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23172321
* stray directories.
23182322
*/
23192323
if (file_exists(state.dir) && !state.rebasing) {
2320-
if (resume == RESUME_ABORT) {
2324+
if (resume == RESUME_ABORT || resume == RESUME_QUIT) {
23212325
am_destroy(&state);
23222326
am_state_release(&state);
23232327
return 0;
@@ -2359,6 +2363,10 @@ int cmd_am(int argc, const char **argv, const char *prefix)
23592363
case RESUME_ABORT:
23602364
am_abort(&state);
23612365
break;
2366+
case RESUME_QUIT:
2367+
am_rerere_clear();
2368+
am_destroy(&state);
2369+
break;
23622370
default:
23632371
die("BUG: invalid resume value");
23642372
}

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ _git_am ()
10771077
{
10781078
__git_find_repo_path
10791079
if [ -d "$__git_repo_path"/rebase-apply ]; then
1080-
__gitcomp "--skip --continue --resolved --abort"
1080+
__gitcomp "--skip --continue --resolved --abort --quit"
10811081
return
10821082
fi
10831083
case "$cur" in

t/t4150-am.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,4 +1045,16 @@ test_expect_success 'am works with multi-line in-body headers' '
10451045
git cat-file commit HEAD | grep "^$LONG$"
10461046
'
10471047

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

0 commit comments

Comments
 (0)