Skip to content

Commit 9a8aeba

Browse files
committed
Merge branch 'kh/format-patch-noprefix-is-boolean'
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: make *.noprefix split translatable doc: diff-options.adoc: show format.noprefix for format-patch format-patch: make format.noprefix a boolean
2 parents d181b93 + ea3a62c commit 9a8aeba

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

Documentation/diff-options.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,18 @@ endif::git-format-patch[]
859859
Do not show any source or destination prefix.
860860

861861
`--default-prefix`::
862+
ifdef::git-format-patch[]
863+
Use the default source and destination prefixes ("a/" and "b/").
864+
This overrides configuration variables such as `format.noprefix`,
865+
`diff.srcPrefix`, `diff.dstPrefix`, and `diff.mnemonicPrefix`
866+
(see linkgit:git-config[1]).
867+
endif::git-format-patch[]
868+
ifndef::git-format-patch[]
862869
Use the default source and destination prefixes ("a/" and "b/").
863870
This overrides configuration variables such as `diff.noprefix`,
864871
`diff.srcPrefix`, `diff.dstPrefix`, and `diff.mnemonicPrefix`
865872
(see linkgit:git-config[1]).
873+
endif::git-format-patch[]
866874

867875
`--line-prefix=<prefix>`::
868876
Prepend an additional _<prefix>_ to every line of output.

builtin/log.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "mailmap.h"
4040
#include "progress.h"
4141
#include "commit-slab.h"
42+
#include "advice.h"
4243

4344
#include "commit-reach.h"
4445
#include "range-diff.h"
@@ -1095,7 +1096,18 @@ static int git_format_config(const char *var, const char *value,
10951096
return 0;
10961097
}
10971098
if (!strcmp(var, "format.noprefix")) {
1098-
format_no_prefix = 1;
1099+
format_no_prefix = git_parse_maybe_bool(value);
1100+
if (format_no_prefix < 0) {
1101+
int status = die_message(
1102+
_("bad boolean config value '%s' for '%s'"),
1103+
value, var);
1104+
advise(_("'%s' used to accept any value and "
1105+
"treat that as 'true'.\n"
1106+
"Now it only accepts boolean values, "
1107+
"like what '%s' does.\n"),
1108+
var, "diff.noprefix");
1109+
exit(status);
1110+
}
10991111
return 0;
11001112
}
11011113

t/t4014-format-patch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,10 +2549,26 @@ test_expect_success 'format-patch respects format.noprefix' '
25492549
grep "^--- blorp" actual
25502550
'
25512551

2552+
test_expect_success 'format.noprefix=false' '
2553+
git -c format.noprefix=false format-patch -1 --stdout >actual &&
2554+
grep "^--- a/blorp" actual
2555+
'
2556+
25522557
test_expect_success 'format-patch --default-prefix overrides format.noprefix' '
25532558
git -c format.noprefix \
25542559
format-patch -1 --default-prefix --stdout >actual &&
25552560
grep "^--- a/blorp" actual
25562561
'
25572562

2563+
test_expect_success 'errors on format.noprefix which is not boolean' '
2564+
cat >expect <<-EOF &&
2565+
fatal: bad boolean config value ${SQ}not-a-bool${SQ} for ${SQ}format.noprefix${SQ}
2566+
hint: ${SQ}format.noprefix${SQ} used to accept any value and treat that as ${SQ}true${SQ}.
2567+
hint: Now it only accepts boolean values, like what ${SQ}diff.noprefix${SQ} does.
2568+
EOF
2569+
test_must_fail git -c format.noprefix=not-a-bool \
2570+
format-patch -1 --stdout 2>actual &&
2571+
test_cmp expect actual
2572+
'
2573+
25582574
test_done

0 commit comments

Comments
 (0)