diff options
| author | Junio C Hamano <gitster@pobox.com> | 2021-02-17 17:21:43 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2021-02-17 17:21:43 -0800 |
| commit | 483e09e810796786baf7a9139680f6d2f2470829 (patch) | |
| tree | 41a503f778c0140db8dc565a94aa6f23869efad8 | |
| parent | Merge branch 'js/reflog-expire-stale-fix' (diff) | |
| parent | config: improve error message for boolean config (diff) | |
| download | git-483e09e810796786baf7a9139680f6d2f2470829.tar.gz git-483e09e810796786baf7a9139680f6d2f2470829.zip | |
Merge branch 'ak/config-bad-bool-error'
The error message given when a configuration variable that is
expected to have a boolean value has been improved.
* ak/config-bad-bool-error:
config: improve error message for boolean config
| -rw-r--r-- | config.c | 20 | ||||
| -rwxr-xr-x | t/t1300-config.sh | 7 |
2 files changed, 25 insertions, 2 deletions
@@ -1180,6 +1180,20 @@ static void die_bad_number(const char *name, const char *value) } } +NORETURN +static void die_bad_bool(const char *name, const char *value) +{ + if (!strcmp(name, "GIT_TEST_GETTEXT_POISON")) + /* + * We explicitly *don't* use _() here since it would + * cause an infinite loop with _() needing to call + * use_gettext_poison(). + */ + die("bad boolean config value '%s' for '%s'", value, name); + else + die(_("bad boolean config value '%s' for '%s'"), value, name); +} + int git_config_int(const char *name, const char *value) { int ret; @@ -1252,8 +1266,10 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool) int git_config_bool(const char *name, const char *value) { - int discard; - return !!git_config_bool_or_int(name, value, &discard); + int v = git_parse_maybe_bool(value); + if (v < 0) + die_bad_bool(name, value); + return v; } int git_config_string(const char **dest, const char *var, const char *value) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 936d72041b..e0dd5d65ce 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -675,6 +675,13 @@ test_expect_success 'invalid unit' ' test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual ' +test_expect_success 'invalid unit boolean' ' + git config commit.gpgsign "1true" && + test_cmp_config 1true commit.gpgsign && + test_must_fail git config --bool --get commit.gpgsign 2>actual && + test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual +' + test_expect_success 'line number is reported correctly' ' printf "[bool]\n\tvar\n" >invalid && test_must_fail git config -f invalid --path bool.var 2>actual && |
