summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2022-11-18 20:04:58 -0500
committerTaylor Blau <me@ttaylorr.com>2022-11-18 20:04:58 -0500
commitc6bb019724237deb91ba4a9185fd04507aadeb6a (patch)
tree885f749a84017a4c993188af19b76afcaf0304fc
parent01e19872862cd2235c14c6bb348fbeb170abbab7 (diff)
parent99d0b829c7b376b1ff562a5782e24df47747bb65 (diff)
downloadgit-jch.tar.gz
Merge branch 'ew/format-patch-mboxrd' into jchjch
Teach `format-patch` a convenient alias for `--pretty=mboxrd`. * ew/format-patch-mboxrd: format-patch: add --mboxrd alias for --pretty=mboxrd
-rw-r--r--Documentation/git-format-patch.txt6
-rw-r--r--builtin/log.c7
-rw-r--r--contrib/completion/git-completion.bash2
-rwxr-xr-xt/t4014-format-patch.sh6
-rwxr-xr-xt/t4150-am.sh2
5 files changed, 18 insertions, 5 deletions
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index dfcc7da4c2..b080d3c61e 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission
SYNOPSIS
--------
[verse]
-'git format-patch' [-k] [(-o|--output-directory) <dir> | --stdout]
+'git format-patch' [-k] [(-o|--output-directory) <dir> | --stdout] [--mboxrd]
[--no-thread | --thread[=<style>]]
[(--attach|--inline)[=<boundary>] | --no-attach]
[-s | --signoff]
@@ -145,6 +145,10 @@ include::diff-options.txt[]
Print all commits to the standard output in mbox format,
instead of creating a file for each one.
+--mboxrd::
+ Use the robust "mboxrd" format with `--stdout` to escape
+ "^>+From " lines.
+
--attach[=<boundary>]::
Create multipart/mixed attachment, the first part of
which is the commit message and the patch itself in the
diff --git a/builtin/log.c b/builtin/log.c
index 5eafcf26b4..13f5deb7a5 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1872,6 +1872,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
struct strbuf rdiff2 = STRBUF_INIT;
struct strbuf rdiff_title = STRBUF_INIT;
int creation_factor = -1;
+ int mboxrd = 0;
const struct option builtin_format_patch_options[] = {
OPT_CALLBACK_F('n', "numbered", &numbered, NULL,
@@ -1883,6 +1884,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
OPT_BOOL('s', "signoff", &do_signoff, N_("add a Signed-off-by trailer")),
OPT_BOOL(0, "stdout", &use_stdout,
N_("print patches to standard out")),
+ OPT_BOOL(0, "mboxrd", &mboxrd,
+ N_("use the robust mboxrd format with --stdout")),
OPT_BOOL(0, "cover-letter", &cover_letter,
N_("generate a cover letter")),
OPT_BOOL(0, "numbered-files", &just_numbers,
@@ -2106,6 +2109,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
rev.diffopt.close_file, "--output",
!!output_directory, "--output-directory");
+ /* should we warn on --mboxrd w/o --stdout? */
+ if (mboxrd)
+ rev.commit_format = CMIT_FMT_MBOXRD;
+
if (use_stdout) {
setup_pager();
} else if (!rev.diffopt.close_file) {
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 161327057d..930359bcef 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1860,7 +1860,7 @@ _git_fetch ()
__git_format_patch_extra_options="
--full-index --not --all --no-prefix --src-prefix=
- --dst-prefix= --notes
+ --dst-prefix= --notes --mboxrd
"
_git_format_patch ()
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index de1da4673d..69ed8b1ffa 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -2281,7 +2281,7 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
test_line_count = 1 output
'
-test_expect_success 'format-patch --pretty=mboxrd' '
+test_expect_success 'format-patch --mboxrd' '
sp=" " &&
cat >msg <<-INPUT_END &&
mboxrd should escape the body
@@ -2316,7 +2316,9 @@ test_expect_success 'format-patch --pretty=mboxrd' '
INPUT_END
C=$(git commit-tree HEAD^^{tree} -p HEAD <msg) &&
- git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >patch &&
+ git format-patch --mboxrd --stdout -1 $C~1..$C >patch &&
+ git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >compat &&
+ test_cmp patch compat &&
git grep -h --no-index -A11 \
"^>From could trip up a loose mbox parser" patch >actual &&
test_cmp expect actual
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index cdad4b6880..9a128c16a6 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -1033,7 +1033,7 @@ test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
>From extra escape for reversibility
INPUT_END
git commit -F msg &&
- git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
+ git format-patch --mboxrd --stdout -1 >mboxrd1 &&
grep "^>From could trip up a loose mbox parser" mboxrd1 &&
git checkout -f first &&
git am --patch-format=mboxrd mboxrd1 &&