From: pbonzini@redhat.com
To: git@vger.kernel.org
Cc: sunshine@sunshineco.com
Subject: [PATCH v2 5/5] am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch
Date: Thu, 20 Feb 2020 15:15:19 +0100 [thread overview]
Message-ID: <20200220141519.28315-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20200220141519.28315-1-pbonzini@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
When "git am --show-current-patch" was added in commit 984913a210 ("am:
add --show-current-patch", 2018-02-12), "git am" started recommending it
as a replacement for .git/rebase-merge/patch. Unfortunately the suggestion
is somewhat misguided; for example, the output of "git am --show-current-patch"
cannot be passed to "git apply" if it is encoded as quoted-printable
or base64. Add a new mode to "git am --show-current-patch" in order to
straighten the suggestion.
Reported-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
v1->v2: - replace "diff|raw" with "(diff|raw)" in docs and help [Eric]
- improve docs wording [Eric]
Documentation/git-am.txt | 11 ++++++-----
builtin/am.c | 9 +++++++--
contrib/completion/git-completion.bash | 2 +-
t/t4150-am.sh | 10 ++++++++++
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 590b711536..ab5754e05d 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -16,7 +16,7 @@ SYNOPSIS
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
[(<mbox> | <Maildir>)...]
-'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=raw])
+'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)])
DESCRIPTION
-----------
@@ -176,10 +176,11 @@ default. You can use `--no-utf8` to override this.
Abort the patching operation but keep HEAD and the index
untouched.
---show-current-patch[=raw]::
- Show the raw contents of the e-mail message at which `git am`
- has stopped due to conflicts. The argument must be omitted or
- `raw`.
+--show-current-patch[=(diff|raw)]::
+ Show the message at which `git am` has stopped due to
+ conflicts. If `raw` is specified, show the raw contents of
+ the e-mail message; if `diff`, show the diff portion only.
+ Defaults to `raw`.
DISCUSSION
----------
diff --git a/builtin/am.c b/builtin/am.c
index 54b04da86d..e3dfd93c25 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -83,6 +83,7 @@ enum signoff_type {
enum show_patch_type {
SHOW_PATCH_RAW = 0,
+ SHOW_PATCH_DIFF = 1,
};
struct am_state {
@@ -1767,7 +1768,7 @@ static void am_run(struct am_state *state, int resume)
linelen(state->msg), state->msg);
if (advice_amworkdir)
- advise(_("Use 'git am --show-current-patch' to see the failed patch"));
+ advise(_("Use 'git am --show-current-patch=diff' to see the failed patch"));
die_user_resolve(state);
}
@@ -2086,6 +2087,9 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
case SHOW_PATCH_RAW:
patch_path = am_path(state, msgnum(state));
break;
+ case SHOW_PATCH_DIFF:
+ patch_path = am_path(state, "patch");
+ break;
default:
BUG("invalid mode for --show-current-patch");
}
@@ -2154,6 +2158,7 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
* when you add new options
*/
const char *valid_modes[] = {
+ [SHOW_PATCH_DIFF] = "diff",
[SHOW_PATCH_RAW] = "raw"
};
int new_value = SHOW_PATCH_RAW;
@@ -2279,7 +2284,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
N_("abort the patching operation but keep HEAD where it is."),
RESUME_QUIT),
{ OPTION_CALLBACK, 0, "show-current-patch", &resume.mode,
- "raw",
+ "(diff|raw)",
N_("show the patch being applied"),
PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
parse_opt_show_current_patch, RESUME_SHOW_PATCH },
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 247f34f1fa..1151697f01 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1197,7 +1197,7 @@ __git_count_arguments ()
__git_whitespacelist="nowarn warn error error-all fix"
__git_patchformat="mbox stgit stgit-series hg mboxrd"
-__git_showcurrentpatch="raw"
+__git_showcurrentpatch="diff raw"
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
_git_am ()
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index afe456e75e..cb45271457 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -671,11 +671,21 @@ test_expect_success 'am --show-current-patch=raw' '
test_cmp .git/rebase-apply/0001 actual.patch
'
+test_expect_success 'am --show-current-patch=diff' '
+ git am --show-current-patch=diff >actual.patch &&
+ test_cmp .git/rebase-apply/patch actual.patch
+'
+
test_expect_success 'am accepts repeated --show-current-patch' '
git am --show-current-patch --show-current-patch=raw >actual.patch &&
test_cmp .git/rebase-apply/0001 actual.patch
'
+test_expect_success 'am detects incompatible --show-current-patch' '
+ test_must_fail git am --show-current-patch=raw --show-current-patch=diff &&
+ test_must_fail git am --show-current-patch --show-current-patch=diff
+'
+
test_expect_success 'am --skip works' '
echo goodbye >expected &&
git am --skip &&
--
2.21.1
prev parent reply other threads:[~2020-02-20 14:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-20 14:15 [PATCH v2 0/5] am: provide a replacement for "cat .git/rebase-apply/patch" pbonzini
2020-02-20 14:15 ` [PATCH v2 1/5] parse-options: add testcases for OPT_CMDMODE() pbonzini
2020-02-20 14:15 ` [PATCH v2 2/5] parse-options: convert "command mode" to a flag pbonzini
2020-02-20 14:15 ` [PATCH v2 3/5] am: convert "resume" variable to a struct pbonzini
2020-02-20 14:15 ` [PATCH v2 4/5] am: support --show-current-patch=raw as a synonym for--show-current-patch pbonzini
2020-02-20 14:15 ` pbonzini [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200220141519.28315-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.com \
/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.
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 NNTP newsgroup(s).