Skip to content

Commit

Permalink
for-each-repo: do nothing on empty config
Browse files Browse the repository at this point in the history
'git for-each-repo --config=X' should return success without calling any
subcommands when the config key 'X' has no value. The current
implementation instead segfaults.

A user could run into this issue if they used 'git maintenance start' to
initialize their cron schedule using 'git for-each-repo
--config=maintenance.repo ...' but then using 'git maintenance
unregister' to remove the config option. (Note: 'git maintenance stop'
would remove the config _and_ remove the cron schedule.)

Add a simple test to ensure this works.

Reported-by: Andreas Bühmann <dev@uuml.de>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Jan 5, 2021
1 parent 4950b2a commit 36dccbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/for-each-repo.c
Expand Up @@ -51,6 +51,9 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
values = repo_config_get_value_multi(the_repository,
config_key);

if (!values)
return result;

for (i = 0; !result && i < values->nr; i++)
result = run_command_on_repo(values->items[i].string, &args);

Expand Down
4 changes: 4 additions & 0 deletions t/t0068-for-each-repo.sh
Expand Up @@ -27,4 +27,8 @@ test_expect_success 'run based on configured value' '
grep again message
'

test_expect_success 'do nothing on empty config' '
git for-each-repo --config=bogus.config -- these args would fail
'

test_done

0 comments on commit 36dccbb

Please sign in to comment.