diff options
author | Andrew Klotz <agc.klotz@gmail.com> | 2021-02-11 20:30:53 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-11 13:44:55 -0800 |
commit | f276e2a469430999ff7e3735ea7b41508ed1abd8 (patch) | |
tree | fc503d5c5161f8c78267e17aa16e9397c5d1f128 /config.c | |
parent | 773e25afc41b1b6533fa9ae2cd825d0b4a697fad (diff) | |
download | git-f276e2a469430999ff7e3735ea7b41508ed1abd8.tar.gz |
config: improve error message for boolean config
Currently invalid boolean config values return messages about 'bad
numeric', which is slightly misleading when the error was due to a
boolean value. We can improve the developer experience by returning a
boolean error message when we know the value is neither a bool text or
int.
before with an invalid boolean value of `non-boolean`, its unclear what
numeric is referring to:
fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
now the error message mentions `non-boolean` is a bad boolean value:
fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
Signed-off-by: Andrew Klotz <agc.klotz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -1030,6 +1030,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; @@ -1102,8 +1116,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) |