@matheusbsbs / matheus-bagliano / commits / 02bc5b03f5
Fork 0

format-patch: Always generate a patch

Jeff King recently reinstated -p to suppress the default diffstat (as -p used to work before 68daa64, about 14 months ago). However, -p is also needed in combination with certain options (e.g. --stat or --numstat) in order to produce any patch at all. The documentation does not mention this. Since the purpose of format-patch is to produce a patch that can be emailed, it does not make sense that certain combination of options will suppress the generation of the patch itself. Therefore: * Update 'git format-patch' to always generate a patch. * Since the --name-only, --name-status, and --check suppresses the generation of the patch, disallow those options, and remove the description of them in the documentation. * Remove the reference to -p in the description of -U. * Remove the descriptions of the options that are synonyms for -p plus another option (--patch-with-raw and --patch-with-stat). * While at it, slightly tweak the description of -p itself to say that it generates "plain patches", so that you can think of -p as "plain patch" as an mnemonic aid. Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Björn Gustavsson committed Nov 7, 2009 at 10:51 UTC 02bc5b03f54b51f8b45c81cce74284ced602e6de
3 files changed +47 -10
Documentation/diff-options.txt
+13 -3
@@ -14,7 +14,7 @@ endif::git-format-patch[]
14
15 ifdef::git-format-patch[]
16 -p::
17 - Generate patches without diffstat.
17 + Generate plain patches without any diffstats.
18 endif::git-format-patch[]
19
20 ifndef::git-format-patch[]
@@ -27,14 +27,19 @@ endif::git-format-patch[]
27 -U<n>::
28 --unified=<n>::
29 Generate diffs with <n> lines of context instead of
30 - the usual three. Implies "-p".
30 + the usual three.
31 +ifndef::git-format-patch[]
32 + Implies "-p".
33 +endif::git-format-patch[]
34
35 --raw::
36 Generate the raw format.
37 {git-diff-core? This is the default.}
38
39 +ifndef::git-format-patch[]
40 --patch-with-raw::
41 Synonym for "-p --raw".
42 +endif::git-format-patch[]
43
44 --patience::
45 Generate a diff using the "patience diff" algorithm.
@@ -71,21 +76,24 @@ endif::git-format-patch[]
76 Output a condensed summary of extended header information
77 such as creations, renames and mode changes.
78
79 +ifndef::git-format-patch[]
80 --patch-with-stat::
81 Synonym for "-p --stat".
76 - {git-format-patch? This is the default.}
82 +endif::git-format-patch[]
83
84 -z::
85 NUL-line termination on output. This affects the --raw
86 output field terminator. Also output from commands such
87 as "git-log" will be delimited with NUL between commits.
88
89 +ifndef::git-format-patch[]
90 --name-only::
91 Show only names of changed files.
92
93 --name-status::
94 Show only names and status of changed files. See the description
95 of the `--diff-filter` option on what the status letters mean.
96 +endif::git-format-patch[]
97
98 --color::
99 Show colored diff.
@@ -115,11 +123,13 @@ override configuration settings.
123 Turn off rename detection, even when the configuration
124 file gives the default to do so.
125
126 +ifndef::git-format-patch[]
127 --check::
128 Warn if changes introduce trailing whitespace
129 or an indent that uses a space before a tab. Exits with
130 non-zero status if problems are found. Not compatible with
131 --exit-code.
132 +endif::git-format-patch[]
133
134 --full-index::
135 Instead of the first handful of characters, show the full
builtin-log.c
+16 -7
@@ -921,10 +921,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
921 PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
922 OPT_BOOLEAN(0, "no-binary", &no_binary_diff,
923 "don't output binary diffs"),
924 - OPT_BOOLEAN('p', NULL, &use_patch_format,
925 - "show patch format instead of default (patch + stat)"),
924 OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
925 "don't include a patch matching a commit upstream"),
926 + OPT_BOOLEAN('p', NULL, &use_patch_format,
927 + "show patch format instead of default (patch + stat)"),
928 OPT_GROUP("Messaging"),
929 { OPTION_CALLBACK, 0, "add-header", NULL, "header",
930 "add email header", PARSE_OPT_NONEG,
@@ -1030,11 +1030,20 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1030 if (argc > 1)
1031 die ("unrecognized argument: %s", argv[1]);
1032
1033 - if (use_patch_format)
1034 - rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1035 - else if (!rev.diffopt.output_format ||
1036 - rev.diffopt.output_format == DIFF_FORMAT_PATCH)
1037 - rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
1033 + if (rev.diffopt.output_format & DIFF_FORMAT_NAME)
1034 + die("--name-only does not make sense");
1035 + if (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS)
1036 + die("--name-status does not make sense");
1037 + if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
1038 + die("--check does not make sense");
1039 +
1040 + if (!use_patch_format &&
1041 + (!rev.diffopt.output_format ||
1042 + rev.diffopt.output_format == DIFF_FORMAT_PATCH))
1043 + rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
1044 +
1045 + /* Always generate a patch */
1046 + rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1047
1048 if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
1049 DIFF_OPT_SET(&rev.diffopt, BINARY);
t/t4014-format-patch.sh
+18
@@ -536,4 +536,22 @@ test_expect_success 'format-patch --signoff' '
536 grep "^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
537 '
538
539 +echo "fatal: --name-only does not make sense" > expect.name-only
540 +echo "fatal: --name-status does not make sense" > expect.name-status
541 +echo "fatal: --check does not make sense" > expect.check
542 +
543 +test_expect_success 'options no longer allowed for format-patch' '
544 + test_must_fail git format-patch --name-only 2> output &&
545 + test_cmp expect.name-only output &&
546 + test_must_fail git format-patch --name-status 2> output &&
547 + test_cmp expect.name-status output &&
548 + test_must_fail git format-patch --check 2> output &&
549 + test_cmp expect.check output'
550 +
551 +test_expect_success 'format-patch --numstat should produce a patch' '
552 + git format-patch --numstat --stdout master..side |
553 + grep "^diff --git a/" |
554 + wc -l |
555 + xargs test 6 = '
556 +
557 test_done