Skip to content

Commit f7b2ff9

Browse files
avargitster
authored andcommitted
for-each-repo: error on bad --config
As noted in 6c62f01 (for-each-repo: do nothing on empty config, 2021-01-08) this command wants to ignore a non-existing config key, but let's not conflate that with bad config. Before this, all these added tests would pass with an exit code of 0. We could preserve the comment added in 6c62f01, but now that we're directly using the documented repo_config_get_value_multi() value it's just narrating something that should be obvious from the API use, so let's drop it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a428619 commit f7b2ff9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

builtin/for-each-repo.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
3232
static const char *config_key = NULL;
3333
int i, result = 0;
3434
const struct string_list *values;
35+
int err;
3536

3637
const struct option options[] = {
3738
OPT_STRING(0, "config", &config_key, N_("config"),
@@ -45,11 +46,11 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
4546
if (!config_key)
4647
die(_("missing --config=<config>"));
4748

48-
/*
49-
* Do nothing on an empty list, which is equivalent to the case
50-
* where the config variable does not exist at all.
51-
*/
52-
if (repo_config_get_value_multi(the_repository, config_key, &values))
49+
err = repo_config_get_value_multi(the_repository, config_key, &values);
50+
if (err < 0)
51+
usage_msg_optf(_("got bad config --config=%s"),
52+
for_each_repo_usage, options, config_key);
53+
else if (err)
5354
return 0;
5455

5556
for (i = 0; !result && i < values->nr; i++)

t/t0068-for-each-repo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ test_expect_success 'do nothing on empty config' '
3939
git for-each-repo --config=bogus.config -- help --no-such-option
4040
'
4141

42+
test_expect_success 'error on bad config keys' '
43+
test_expect_code 129 git for-each-repo --config=a &&
44+
test_expect_code 129 git for-each-repo --config=a.b. &&
45+
test_expect_code 129 git for-each-repo --config="'\''.b"
46+
'
47+
4248
test_done

0 commit comments

Comments
 (0)