{"thread":{"id":"51226","subject":"[PATCH] am: add --check option","startedAt":"2019-06-03T14:25:27Z","lastAt":"2019-06-04T15:38:09Z","messageCount":4,"participants":["Drew DeVault","SZEDER Gábor","Johannes Sixt","René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"376569","messageId":"20190603142523.3826-1-sir@cmpwn.com","threadId":"51226","inReplyTo":null,"subject":"[PATCH] am: add --check option","fromName":"Drew DeVault","fromEmail":"sir@cmpwn.com","sentAt":"2019-06-03T14:25:23Z","receivedAt":"2019-06-03T14:25:27Z","isPatch":true,"sender":{"key":"sir@cmpwn.com","avatar":"https://avatars.githubusercontent.com/u/1310872?v=4"},"body":"---\n Documentation/git-am.txt |  7 ++++++-\n builtin/am.c             | 13 +++++++++++++\n 2 files changed, 19 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\nindex fc3b993c33..bc01e87d85 100644\n--- a/Documentation/git-am.txt\n+++ b/Documentation/git-am.txt\n@@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox\n SYNOPSIS\n --------\n [verse]\n-'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]\n+'git am' [--signoff] [--keep] [--check] [--[no-]keep-cr] [--[no-]utf8]\n \t [--[no-]3way] [--interactive] [--committer-date-is-author-date]\n \t [--ignore-date] [--ignore-space-change | --ignore-whitespace]\n \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n@@ -44,6 +44,11 @@ OPTIONS\n --keep-non-patch::\n \tPass `-b` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).\n \n+--check::\n+\tInstead of applying the patch(es), see if they are\n+\tapplicable to the current working tree and/or the index\n+\tfile and detects errors.\n+\n --[no-]keep-cr::\n \tWith `--keep-cr`, call 'git mailsplit' (see linkgit:git-mailsplit[1])\n \twith the same option, to prevent it from stripping CR at the end of\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 912d9821b1..9ae90dec28 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -112,6 +112,7 @@ struct am_state {\n \tint keep; /* enum keep_type */\n \tint message_id;\n \tint scissors; /* enum scissors_type */\n+\tint check;\n \tstruct argv_array git_apply_opts;\n \tconst char *resolvemsg;\n \tint committer_date_is_author_date;\n@@ -1422,6 +1423,8 @@ static int run_apply(const struct am_state *state, const char *index_file)\n \t} else\n \t\tapply_state.check_index = 1;\n \n+\tapply_state.check = state->check;\n+\n \t/*\n \t * If we are allowed to fall back on 3-way merge, don't give false\n \t * errors during the initial attempt.\n@@ -1565,6 +1568,9 @@ static void do_commit(const struct am_state *state)\n \tconst char *reflog_msg, *author;\n \tstruct strbuf sb = STRBUF_INIT;\n \n+\tif (state->check)\n+\t\treturn;\n+\n \tif (run_hook_le(NULL, \"pre-applypatch\", NULL))\n \t\texit(1);\n \n@@ -1775,6 +1781,11 @@ static void am_run(struct am_state *state, int resume)\n \t\t\tprintf_ln(_(\"Patch failed at %s %.*s\"), msgnum(state),\n \t\t\t\tlinelen(state->msg), state->msg);\n \n+\t\t\tif (state->check) {\n+\t\t\t\tam_destroy(state);\n+\t\t\t\texit(128);\n+\t\t\t}\n+\n \t\t\tif (advice_amworkdir)\n \t\t\t\tadvise(_(\"Use 'git am --show-current-patch' to see the failed patch\"));\n \n@@ -2195,6 +2206,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n \t\t\t0, PARSE_OPT_NONEG),\n \t\tOPT_BOOL('c', \"scissors\", &state.scissors,\n \t\t\tN_(\"strip everything before a scissors line\")),\n+\t\tOPT_BOOL(0, \"check\", &state.check,\n+\t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n \t\tOPT_PASSTHRU_ARGV(0, \"whitespace\", &state.git_apply_opts, N_(\"action\"),\n \t\t\tN_(\"pass it through git-apply\"),\n \t\t\t0),\n-- \n2.21.0\n\n"},{"id":"376574","messageId":"20190603154644.GQ951@szeder.dev","threadId":"51226","inReplyTo":"20190603142523.3826-1-sir@cmpwn.com","subject":"Re: [PATCH] am: add --check option","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-06-03T15:46:44Z","receivedAt":"2019-06-03T15:46:50Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Mon, Jun 03, 2019 at 10:25:23AM -0400, Drew DeVault wrote:\n> ---\n>  Documentation/git-am.txt |  7 ++++++-\n>  builtin/am.c             | 13 +++++++++++++\n>  2 files changed, 19 insertions(+), 1 deletion(-)\n> \n> diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt\n> index fc3b993c33..bc01e87d85 100644\n> --- a/Documentation/git-am.txt\n> +++ b/Documentation/git-am.txt\n> @@ -9,7 +9,7 @@ git-am - Apply a series of patches from a mailbox\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git am' [--signoff] [--keep] [--[no-]keep-cr] [--[no-]utf8]\n> +'git am' [--signoff] [--keep] [--check] [--[no-]keep-cr] [--[no-]utf8]\n>  \t [--[no-]3way] [--interactive] [--committer-date-is-author-date]\n>  \t [--ignore-date] [--ignore-space-change | --ignore-whitespace]\n>  \t [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]\n> @@ -44,6 +44,11 @@ OPTIONS\n>  --keep-non-patch::\n>  \tPass `-b` flag to 'git mailinfo' (see linkgit:git-mailinfo[1]).\n>  \n> +--check::\n> +\tInstead of applying the patch(es), see if they are\n> +\tapplicable to the current working tree and/or the index\n> +\tfile and detects errors.\n\nNote that in \"real\" patch series a later patch quite often depends on\nthe changes made in earlier patches, and this option should somehow\naccount for that.  I'm not sure how to do that without actually\napplying the patches, though...\n\n  # Create two patches, each modifying the same line in the same file.\n  $ echo 0 >file\n  $ git add file\n  $ git commit -m initial\n  [master 956965a] initial\n   1 file changed, 1 insertion(+)\n   create mode 100644 file\n  $ echo 1 >file\n  $ git commit -m one file\n  [master fd65db1] one\n   1 file changed, 1 insertion(+), 1 deletion(-)\n  $ echo 2 >file\n  $ git commit -m two file\n  [master 1b878f1] two\n   1 file changed, 1 insertion(+), 1 deletion(-)\n  $ git format-patch -2\n  0001-one.patch\n  0002-two.patch\n\n  # This shows that the second patch is applicable on top of the\n  # first:\n  $ git checkout HEAD^\n  HEAD is now at fd65db1 one\n  $ git apply --check 0002-two.patch ; echo $?\n  0\n\n  # But 'git am --check' reports that the two patches can't be\n  # applied on the initial commit, because it attempts to apply the\n  # second patch on the initial commit as well, instead on top of the\n  # first:\n  $ git checkout HEAD^\n  Previous HEAD position was fd65db1 one\n  HEAD is now at 956965a initial\n  $ ~/src/git/bin-wrappers/git am --check 0001-one.patch 0002-two.patch\n  Applying: one\n  Applying: two\n  error: patch failed: file:1\n  error: file: patch does not apply\n  Patch failed at 0002 two\n\n  # Though, of course, they can be applied just fine:\n  $ ~/src/git/bin-wrappers/git am 0001-one.patch 0002-two.patch\n  Applying: one\n  Applying: two\n\n"},{"id":"376621","messageId":"34b269e6-0172-42a3-b7b0-f0c7751007a4@kdbg.org","threadId":"51226","inReplyTo":"20190603142523.3826-1-sir@cmpwn.com","subject":"Re: [PATCH] am: add --check option","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-06-03T21:09:11Z","receivedAt":"2019-06-03T21:58:22Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 03.06.19 um 16:25 schrieb Drew DeVault:\n> +--check::\n> +\tInstead of applying the patch(es), see if they are\n> +\tapplicable to the current working tree and/or the index\n> +\tfile and detects errors.\n\nI have to wonder how --check works when 'am' applies multiple patches.\n\nWhen the second patch in a patch series depends on that the first patch\nis fully applied, what does --check do? Without the first patch applied,\nthen a naive check of the second patch will certainly fail, doesn't it?\n\n-- Hannes\n"},{"id":"376669","messageId":"0683d141-544e-12da-17ae-dc1157a2985b@web.de","threadId":"51226","inReplyTo":"20190603142523.3826-1-sir@cmpwn.com","subject":"Re: [PATCH] am: add --check option","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-06-04T15:37:52Z","receivedAt":"2019-06-04T15:38:09Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 03.06.19 um 16:25 schrieb Drew DeVault:\n> @@ -2195,6 +2206,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)\n>  \t\t\t0, PARSE_OPT_NONEG),\n>  \t\tOPT_BOOL('c', \"scissors\", &state.scissors,\n>  \t\t\tN_(\"strip everything before a scissors line\")),\n> +\t\tOPT_BOOL(0, \"check\", &state.check,\n> +\t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n>  \t\tOPT_PASSTHRU_ARGV(0, \"whitespace\", &state.git_apply_opts, N_(\"action\"),\n>  \t\t\tN_(\"pass it through git-apply\"),\n>  \t\t\t0),\n>\n\nGit apply has a --check option as well for the same purpose.  Other\ncommands have an equivalent option called --dry-run instead.  Would it\nmake sense to move towards the latter for greater consistency?\n\nRené\n"}]}