diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index 73678d88a1..8cf6f00d93 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -144,3 +144,10 @@ will only show notes from `refs/notes/bar`. format.mboxrd:: A boolean value which enables the robust "mboxrd" format when `--stdout` is in use to escape "^>+From " lines. + +format.noprefix:: + If set, do not show any source or destination prefix in patches. + This is equivalent to the `diff.noprefix` option used by `git + diff` (but which is not respected by `format-patch`). Note that + by setting this, the receiver of any patches you generate will + have to apply them using the `-p0` option. diff --git a/builtin/log.c b/builtin/log.c index eaf511aab8..b1f59062f4 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -56,6 +56,7 @@ static int stdout_mboxrd; static const char *fmt_patch_subject_prefix = "PATCH"; static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT; static const char *fmt_pretty; +static int format_no_prefix; static const char * const builtin_log_usage[] = { N_("git log [] [] [[--] ...]"), @@ -1084,6 +1085,10 @@ static int git_format_config(const char *var, const char *value, void *cb) stdout_mboxrd = git_config_bool(var, value); return 0; } + if (!strcmp(var, "format.noprefix")) { + format_no_prefix = 1; + return 0; + } /* * ignore some porcelain config which would otherwise be parsed by @@ -2002,6 +2007,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) s_r_opt.def = "HEAD"; s_r_opt.revarg_opt = REVARG_COMMITTISH; + if (format_no_prefix) + diff_set_noprefix(&rev.diffopt); + if (default_attach) { rev.mime_boundary = default_attach; rev.no_inline = 1; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index f5a41fd47e..2711fd09ca 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -2391,4 +2391,15 @@ test_expect_success 'format-patch does not respect diff.noprefix' ' grep "^--- a/blorp" actual ' +test_expect_success 'format-patch respects format.noprefix' ' + git -c format.noprefix format-patch -1 --stdout >actual && + grep "^--- blorp" actual +' + +test_expect_success 'format-patch --default-prefix overrides format.noprefix' ' + git -c format.noprefix \ + format-patch -1 --default-prefix --stdout >actual && + grep "^--- a/blorp" actual +' + test_done