Merge branch 'kh/format-patch-noprefix-is-boolean' into next

The configuration variable format.noprefix did not behave as a
proper boolean variable, which has now been fixed and documented.

* kh/format-patch-noprefix-is-boolean:
  doc: diff-options.adoc: show format.noprefix for format-patch
  format-patch: make format.noprefix a boolean
This commit is contained in:
Junio C Hamano
2026-02-26 10:06:15 -08:00
3 changed files with 32 additions and 2 deletions

View File

@@ -860,7 +860,9 @@ endif::git-format-patch[]
`--default-prefix`::
Use the default source and destination prefixes ("a/" and "b/").
This overrides configuration variables such as `diff.noprefix`,
This overrides configuration variables such as
ifndef::git-format-patch[`diff.noprefix`,]
ifdef::git-format-patch[`format.noprefix`,]
`diff.srcPrefix`, `diff.dstPrefix`, and `diff.mnemonicPrefix`
(see linkgit:git-config[1]).

View File

@@ -39,6 +39,7 @@
#include "mailmap.h"
#include "progress.h"
#include "commit-slab.h"
#include "advice.h"
#include "commit-reach.h"
#include "range-diff.h"
@@ -1095,7 +1096,18 @@ static int git_format_config(const char *var, const char *value,
return 0;
}
if (!strcmp(var, "format.noprefix")) {
format_no_prefix = 1;
format_no_prefix = git_parse_maybe_bool(value);
if (format_no_prefix < 0) {
int status = die_message(
_("bad boolean config value '%s' for '%s'"),
value, var);
advise(_("'%s' used to accept any value and "
"treat that as 'true'.\n"
"Now it only accepts boolean values, "
"like what '%s' does.\n"),
var, "diff.noprefix");
exit(status);
}
return 0;
}

View File

@@ -2549,10 +2549,26 @@ test_expect_success 'format-patch respects format.noprefix' '
grep "^--- blorp" actual
'
test_expect_success 'format.noprefix=false' '
git -c format.noprefix=false format-patch -1 --stdout >actual &&
grep "^--- a/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_expect_success 'errors on format.noprefix which is not boolean' '
cat >expect <<-EOF &&
fatal: bad boolean config value ${SQ}not-a-bool${SQ} for ${SQ}format.noprefix${SQ}
hint: ${SQ}format.noprefix${SQ} used to accept any value and treat that as ${SQ}true${SQ}.
hint: Now it only accepts boolean values, like what ${SQ}diff.noprefix${SQ} does.
EOF
test_must_fail git -c format.noprefix=not-a-bool \
format-patch -1 --stdout 2>actual &&
test_cmp expect actual
'
test_done