Skip to content

Commit aa416b2

Browse files
bonzinigitster
authored andcommitted
am: support --show-current-patch=diff to retrieve .git/rebase-apply/patch
When "git am --show-current-patch" was added in commit 984913a ("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 <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3b4822 commit aa416b2

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

Documentation/git-am.txt

Lines changed: 6 additions & 5 deletions
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 | --quit | --show-current-patch[=raw])
19+
'git am' (--continue | --skip | --abort | --quit | --show-current-patch[=(diff|raw)])
2020

2121
DESCRIPTION
2222
-----------
@@ -176,10 +176,11 @@ default. You can use `--no-utf8` to override this.
176176
Abort the patching operation but keep HEAD and the index
177177
untouched.
178178

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`.
183184

184185
DISCUSSION
185186
----------

builtin/am.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ enum signoff_type {
8383

8484
enum show_patch_type {
8585
SHOW_PATCH_RAW = 0,
86+
SHOW_PATCH_DIFF = 1,
8687
};
8788

8889
struct am_state {
@@ -1767,7 +1768,7 @@ static void am_run(struct am_state *state, int resume)
17671768
linelen(state->msg), state->msg);
17681769

17691770
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"));
17711772

17721773
die_user_resolve(state);
17731774
}
@@ -2086,6 +2087,9 @@ static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
20862087
case SHOW_PATCH_RAW:
20872088
patch_path = am_path(state, msgnum(state));
20882089
break;
2090+
case SHOW_PATCH_DIFF:
2091+
patch_path = am_path(state, "patch");
2092+
break;
20892093
default:
20902094
BUG("invalid mode for --show-current-patch");
20912095
}
@@ -2154,6 +2158,7 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
21542158
* when you add new options
21552159
*/
21562160
const char *valid_modes[] = {
2161+
[SHOW_PATCH_DIFF] = "diff",
21572162
[SHOW_PATCH_RAW] = "raw"
21582163
};
21592164
int new_value = SHOW_PATCH_RAW;
@@ -2279,7 +2284,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
22792284
N_("abort the patching operation but keep HEAD where it is."),
22802285
RESUME_QUIT),
22812286
{ OPTION_CALLBACK, 0, "show-current-patch", &resume.mode,
2282-
"raw",
2287+
"(diff|raw)",
22832288
N_("show the patch being applied"),
22842289
PARSE_OPT_CMDMODE | PARSE_OPT_OPTARG | PARSE_OPT_NONEG | PARSE_OPT_LITERAL_ARGHELP,
22852290
parse_opt_show_current_patch, RESUME_SHOW_PATCH },

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ __git_count_arguments ()
11801180

11811181
__git_whitespacelist="nowarn warn error error-all fix"
11821182
__git_patchformat="mbox stgit stgit-series hg mboxrd"
1183-
__git_showcurrentpatch="raw"
1183+
__git_showcurrentpatch="diff raw"
11841184
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
11851185

11861186
_git_am ()

t/t4150-am.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,21 @@ test_expect_success 'am --show-current-patch=raw' '
671671
test_cmp .git/rebase-apply/0001 actual.patch
672672
'
673673

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+
674679
test_expect_success 'am accepts repeated --show-current-patch' '
675680
git am --show-current-patch --show-current-patch=raw >actual.patch &&
676681
test_cmp .git/rebase-apply/0001 actual.patch
677682
'
678683

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+
679689
test_expect_success 'am --skip works' '
680690
echo goodbye >expected &&
681691
git am --skip &&

0 commit comments

Comments
 (0)