Skip to content

Commit 483e09e

Browse files
committed
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
2 parents e68f62b + f276e2a commit 483e09e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

config.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,20 @@ static void die_bad_number(const char *name, const char *value)
11801180
}
11811181
}
11821182

1183+
NORETURN
1184+
static void die_bad_bool(const char *name, const char *value)
1185+
{
1186+
if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
1187+
/*
1188+
* We explicitly *don't* use _() here since it would
1189+
* cause an infinite loop with _() needing to call
1190+
* use_gettext_poison().
1191+
*/
1192+
die("bad boolean config value '%s' for '%s'", value, name);
1193+
else
1194+
die(_("bad boolean config value '%s' for '%s'"), value, name);
1195+
}
1196+
11831197
int git_config_int(const char *name, const char *value)
11841198
{
11851199
int ret;
@@ -1252,8 +1266,10 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
12521266

12531267
int git_config_bool(const char *name, const char *value)
12541268
{
1255-
int discard;
1256-
return !!git_config_bool_or_int(name, value, &discard);
1269+
int v = git_parse_maybe_bool(value);
1270+
if (v < 0)
1271+
die_bad_bool(name, value);
1272+
return v;
12571273
}
12581274

12591275
int git_config_string(const char **dest, const char *var, const char *value)

t/t1300-config.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ test_expect_success 'invalid unit' '
675675
test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
676676
'
677677

678+
test_expect_success 'invalid unit boolean' '
679+
git config commit.gpgsign "1true" &&
680+
test_cmp_config 1true commit.gpgsign &&
681+
test_must_fail git config --bool --get commit.gpgsign 2>actual &&
682+
test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
683+
'
684+
678685
test_expect_success 'line number is reported correctly' '
679686
printf "[bool]\n\tvar\n" >invalid &&
680687
test_must_fail git config -f invalid --path bool.var 2>actual &&

0 commit comments

Comments
 (0)