Skip to content

Commit b8909bc

Browse files
LemmingAvalanchegitster
authored andcommitted
format-patch: make format.noprefix a boolean
The config `format.noprefix` was added in 8d5213d (format-patch: add format.noprefix option, 2023-03-09) to support no-prefix on paths. That was immediately after making git-format-patch(1) not respect `diff.noprefix`.[1] The intent was to mirror `diff.noprefix`. But this config was unintentionally[2] implemented by enabling no-prefix if any kind of value is set. † 1: c169af8 (format-patch: do not respect diff.noprefix, 2023-03-09) † 2: https://lore.kernel.org/all/20260211073553.GA1867915@coredump.intra.peff.net/ Let’s indeed mirror `diff.noprefix` by treating it as a boolean. This is a breaking change. And as far as breaking changes go it is pretty benign: • The documentation claims that this config is equivalent to `diff.noprefix`; this is just a bug fix if the documentation is what defines the application interface • Only users with non-boolean values will run into problems when we try to parse it as a boolean. But what would (1) make them suspect they could do that in the first place, and (2) have motivated them to do it? • Users who have set this to `false` and expect that to mean *enable format.noprefix* (current behavior) will now have the opposite experience. Which is not a reasonable setup. Let’s only offer a breaking change fig leaf by hinting about the previous behavior before dying. Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit b8909bc

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

builtin/log.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,18 @@ static int git_format_config(const char *var, const char *value,
10961096
return 0;
10971097
}
10981098
if (!strcmp(var, "format.noprefix")) {
1099-
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+
fprintf(stderr,
1105+
_("hint: '%s' used to accept any value but "
1106+
"now only\n"
1107+
"hint: accepts boolean values, like '%s'\n"),
1108+
var, "diff.noprefix");
1109+
exit(status);
1110+
}
11001111
return 0;
11011112
}
11021113

t/t4014-format-patch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,10 +2541,26 @@ test_expect_success 'format-patch respects format.noprefix' '
25412541
grep "^--- blorp" actual
25422542
'
25432543

2544+
test_expect_success 'format.noprefix=false' '
2545+
git -c format.noprefix=false format-patch -1 --stdout >actual &&
2546+
grep "^--- a/blorp" actual
2547+
'
2548+
25442549
test_expect_success 'format-patch --default-prefix overrides format.noprefix' '
25452550
git -c format.noprefix \
25462551
format-patch -1 --default-prefix --stdout >actual &&
25472552
grep "^--- a/blorp" actual
25482553
'
25492554

2555+
test_expect_success 'errors on format.noprefix which is not boolean' '
2556+
cat >expect <<-EOF &&
2557+
fatal: bad boolean config value ${SQ}not-a-bool${SQ} for ${SQ}format.noprefix${SQ}
2558+
hint: ${SQ}format.noprefix${SQ} used to accept any value but now only
2559+
hint: accepts boolean values, like ${SQ}diff.noprefix${SQ}
2560+
EOF
2561+
test_must_fail git -c format.noprefix=not-a-bool \
2562+
format-patch -1 --stdout 2>actual &&
2563+
test_cmp expect actual
2564+
'
2565+
25502566
test_done

0 commit comments

Comments
 (0)