Skip to content

Commit 9db59ee

Browse files
committed
Merge branch 'kh/format-patch-noprefix-is-boolean' into jch
* kh/format-patch-noprefix-is-boolean: doc: diff-options.adoc: show format.noprefix for format-patch format-patch: make format.noprefix a boolean
2 parents c627025 + 4136a3d commit 9db59ee

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

Documentation/diff-options.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,9 @@ endif::git-format-patch[]
860860

861861
`--default-prefix`::
862862
Use the default source and destination prefixes ("a/" and "b/").
863-
This overrides configuration variables such as `diff.noprefix`,
863+
This overrides configuration variables such as
864+
ifndef::git-format-patch[`diff.noprefix`,]
865+
ifdef::git-format-patch[`format.noprefix`,]
864866
`diff.srcPrefix`, `diff.dstPrefix`, and `diff.mnemonicPrefix`
865867
(see linkgit:git-config[1]).
866868

builtin/log.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,18 @@ static int git_format_config(const char *var, const char *value,
10951095
return 0;
10961096
}
10971097
if (!strcmp(var, "format.noprefix")) {
1098-
format_no_prefix = 1;
1098+
format_no_prefix = git_parse_maybe_bool(value);
1099+
if (format_no_prefix < 0) {
1100+
int status = die_message(
1101+
_("bad boolean config value '%s' for '%s'"),
1102+
value, var);
1103+
fprintf(stderr,
1104+
_("hint: '%s' used to accept any value but "
1105+
"now only\n"
1106+
"hint: accepts boolean values, like '%s'\n"),
1107+
var, "diff.noprefix");
1108+
exit(status);
1109+
}
10991110
return 0;
11001111
}
11011112

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 but now only
2567+
hint: accepts boolean values, like ${SQ}diff.noprefix${SQ}
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)