am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paolo Bonzini committed
Feb 20, 2020 at 15:15 UTC
aa416b22ea73321aba94c3c96db0491fb25ea7ea
4 files changed
+24
-8
Documentation/git-am.txt
+6
-5
@@ -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 | --quit | --show-current-patch[=raw])
19
+'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)])
20
21
DESCRIPTION
22
-----------
@@ -176,10 +176,11 @@ default. You can use `--no-utf8` to override this.
176
Abort the patching operation but keep HEAD and the index
177
untouched.
178
179
---show-current-patch[=raw]::
180
- Show the raw contents of the e-mail message at which `git am`
181
- has stopped due to conflicts. The argument must be omitted or
182
- `raw`.
179
+--show-current-patch[=(diff|raw)]::
180
+ Show the message at which `git am` has stopped due to
181
+ conflicts. If `raw` is specified, show the raw contents of
182
+ the e-mail message; if `diff`, show the diff portion only.
183
+ Defaults to `raw`.
184
185
DISCUSSION
186
----------
builtin/am.c
+7
-2
@@ -83,6 +83,7 @@ enum signoff_type {
83
84
enum show_patch_type {
85
SHOW_PATCH_RAW = 0,
86
+ SHOW_PATCH_DIFF = 1,
87
};
88
89
struct am_state {
@@ -1767,7 +1768,7 @@ static void am_run(struct am_state *state, int resume)
1768
linelen(state->msg), state->msg);
1769
1770
if (advice_amworkdir)
1770
- advise(_("Use 'git am --show-current-patch' to see the failed patch"));
1771
+ advise(_("Use 'git am --show-current-patch=diff' to see the failed patch"));
1772
1773
die_user_resolve(state);
1774
}
@@ -2086,6 +2087,9 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
2087
case SHOW_PATCH_RAW:
2088
patch_path = am_path(state, msgnum(state));
2089
break;
2090
+ case SHOW_PATCH_DIFF:
2091
+ patch_path = am_path(state, "patch");
2092
+ break;
2093
default:
2094
BUG("invalid mode for --show-current-patch");
2095
}
@@ -2154,6 +2158,7 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
2158
* when you add new options
2159
*/
2160
const char *valid_modes[] = {
2161
+ [SHOW_PATCH_DIFF] = "diff",
2162
[SHOW_PATCH_RAW] = "raw"
2163
};
2164
int new_value = SHOW_PATCH_RAW;
@@ -2279,7 +2284,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
2284
N_("abort the patching operation but keep HEAD where it is."),
2285
RESUME_QUIT),
2286
{ OPTION_CALLBACK, 0, "show-current-patch", &resume.mode,
2282
- "raw",
2287
+ "(diff|raw)",
2288
N_("show the patch being applied"),
2289
PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
2290
parse_opt_show_current_patch, RESUME_SHOW_PATCH },
contrib/completion/git-completion.bash
+1
-1
@@ -1180,7 +1180,7 @@ __git_count_arguments ()
1180
1181
__git_whitespacelist="nowarn warn error error-all fix"
1182
__git_patchformat="mbox stgit stgit-series hg mboxrd"
1183
-__git_showcurrentpatch="raw"
1183
+__git_showcurrentpatch="diff raw"
1184
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1185
1186
_git_am ()
t/t4150-am.sh
+10
@@ -671,11 +671,21 @@ test_expect_success 'am --show-current-patch=raw' '
671
test_cmp .git/rebase-apply/0001 actual.patch
672
'
673
674
+test_expect_success 'am --show-current-patch=diff' '
675
+ git am --show-current-patch=diff >actual.patch &&
676
+ test_cmp .git/rebase-apply/patch actual.patch
677
+'
678
+
679
test_expect_success 'am accepts repeated --show-current-patch' '
680
git am --show-current-patch --show-current-patch=raw >actual.patch &&
681
test_cmp .git/rebase-apply/0001 actual.patch
682
'
683
684
+test_expect_success 'am detects incompatible --show-current-patch' '
685
+ test_must_fail git am --show-current-patch=raw --show-current-patch=diff &&
686
+ test_must_fail git am --show-current-patch --show-current-patch=diff
687
+'
688
+
689
test_expect_success 'am --skip works' '
690
echo goodbye >expected &&
691
git am --skip &&