From: Drew DeVault <sir@cmpwn.com>
To: git@vger.kernel.org
Cc: Drew DeVault <sir@cmpwn.com>
Subject: [PATCH] am: add --check option
Date: Mon, 3 Jun 2019 10:25:23 -0400 [thread overview]
Message-ID: <20190603142523.3826-1-sir@cmpwn.com> (raw)
---
Documentation/git-am.txt | 7 ++++++-
builtin/am.c | 13 +++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index fc3b993c33..bc01e87d85 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox
SYNOPSIS
--------
[verse]
-'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]
+'git am' [--signoff] [--keep] [--check] [--[no-]keep-cr] [--[no-]utf8]
[--[no-]3way] [--interactive] [--committer-date-is-author-date]
[--ignore-date] [--ignore-space-change | --ignore-whitespace]
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
@@ -44,6 +44,11 @@ OPTIONS
--keep-non-patch::
Pass `-b` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).
+--check::
+ Instead of applying the patch(es), see if they are
+ applicable to the current working tree and/or the index
+ file and detects errors.
+
--[no-]keep-cr::
With `--keep-cr`, call 'git mailsplit' (see linkgit:git-mailsplit[1])
with the same option, to prevent it from stripping CR at the end of
diff --git a/builtin/am.c b/builtin/am.c
index 912d9821b1..9ae90dec28 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -112,6 +112,7 @@ struct am_state {
int keep; /* enum keep_type */
int message_id;
int scissors; /* enum scissors_type */
+ int check;
struct argv_array git_apply_opts;
const char *resolvemsg;
int committer_date_is_author_date;
@@ -1422,6 +1423,8 @@ static int run_apply(const struct am_state *state, const char *index_file)
} else
apply_state.check_index = 1;
+ apply_state.check = state->check;
+
/*
* If we are allowed to fall back on 3-way merge, don't give false
* errors during the initial attempt.
@@ -1565,6 +1568,9 @@ static void do_commit(const struct am_state *state)
const char *reflog_msg, *author;
struct strbuf sb = STRBUF_INIT;
+ if (state->check)
+ return;
+
if (run_hook_le(NULL, "pre-applypatch", NULL))
exit(1);
@@ -1775,6 +1781,11 @@ static void am_run(struct am_state *state, int resume)
printf_ln(_("Patch failed at %s %.*s"), msgnum(state),
linelen(state->msg), state->msg);
+ if (state->check) {
+ am_destroy(state);
+ exit(128);
+ }
+
if (advice_amworkdir)
advise(_("Use 'git am --show-current-patch' to see the failed patch"));
@@ -2195,6 +2206,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
0, PARSE_OPT_NONEG),
OPT_BOOL('c', "scissors", &state.scissors,
N_("strip everything before a scissors line")),
+ OPT_BOOL(0, "check", &state.check,
+ N_("instead of applying the patch, see if the patch is applicable")),
OPT_PASSTHRU_ARGV(0, "whitespace", &state.git_apply_opts, N_("action"),
N_("pass it through git-apply"),
0),
--
2.21.0
next reply other threads:[~2019-06-03 14:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-03 14:25 Drew DeVault [this message]
2019-06-03 15:46 ` [PATCH] am: add --check option SZEDER Gábor
2019-06-03 21:09 ` Johannes Sixt
2019-06-04 15:37 ` René Scharfe
[not found] <BUKFSM2OTJUH.38N6DGWH9KX7H@homura>
2019-06-04 5:58 ` Johannes Sixt
2019-06-04 13:40 ` Johannes Schindelin
2019-06-04 14:06 ` Christian Couder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190603142523.3826-1-sir@cmpwn.com \
--to=sir@cmpwn.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).