diff --git a/builtin/log.c b/builtin/log.c index 5c9a8ef363..275122b807 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -40,6 +40,7 @@ #include "mailmap.h" #include "progress.h" #include "commit-slab.h" +#include "advice.h" #include "commit-reach.h" #include "range-diff.h" @@ -1096,7 +1097,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; } diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 21d6d0cd9e..c20091e36f 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -2541,10 +2541,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