Skip to content

Commit d465be2

Browse files
pks-tgitster
authored andcommitted
builtin/maintenance: don't silently ignore invalid strategy
When parsing maintenance strategies we completely ignore the user-configured value in case it is unknown to us. This makes it basically undiscoverable to the user that scheduled maintenance is devolving into a no-op. Change this to instead die when seeing an unknown maintenance strategy. While at it, pull out the parsing logic into a separate function so that we can reuse it in a subsequent commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5c2ad50 commit d465be2

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

builtin/gc.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,13 @@ static const struct maintenance_strategy incremental_strategy = {
18551855
},
18561856
};
18571857

1858+
static struct maintenance_strategy parse_maintenance_strategy(const char *name)
1859+
{
1860+
if (!strcasecmp(name, "incremental"))
1861+
return incremental_strategy;
1862+
die(_("unknown maintenance strategy: '%s'"), name);
1863+
}
1864+
18581865
static void initialize_task_config(struct maintenance_run_opts *opts,
18591866
const struct string_list *selected_tasks)
18601867
{
@@ -1890,12 +1897,10 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
18901897
* override specific aspects of our strategy.
18911898
*/
18921899
if (opts->schedule) {
1893-
strategy = none_strategy;
1894-
1895-
if (!repo_config_get_string_tmp(the_repository, "maintenance.strategy", &config_str)) {
1896-
if (!strcasecmp(config_str, "incremental"))
1897-
strategy = incremental_strategy;
1898-
}
1900+
if (!repo_config_get_string_tmp(the_repository, "maintenance.strategy", &config_str))
1901+
strategy = parse_maintenance_strategy(config_str);
1902+
else
1903+
strategy = none_strategy;
18991904
} else {
19001905
strategy = default_strategy;
19011906
}

t/t7900-maintenance.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,11 @@ test_expect_success 'fails when running outside of a repository' '
12631263
nongit test_must_fail git maintenance unregister
12641264
'
12651265

1266+
test_expect_success 'fails when configured to use an invalid strategy' '
1267+
test_must_fail git -c maintenance.strategy=invalid maintenance run --schedule=hourly 2>err &&
1268+
test_grep "unknown maintenance strategy: .invalid." err
1269+
'
1270+
12661271
test_expect_success 'register and unregister bare repo' '
12671272
test_when_finished "git config --global --unset-all maintenance.repo || :" &&
12681273
test_might_fail git config --global --unset-all maintenance.repo &&

0 commit comments

Comments
 (0)