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>

Patrick Steinhardt committed Oct 24, 2025 at 08:57 UTC d465be2327d934f3506d412cc4f4067baba0d1c5
2 files changed +16 -6
builtin/gc.c
+11 -6
@@ -1855,6 +1855,13 @@ static const struct maintenance_strategy incremental_strategy = {
1855 },
1856 };
1857
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 +
1865 static void initialize_task_config(struct maintenance_run_opts *opts,
1866 const struct string_list *selected_tasks)
1867 {
@@ -1890,12 +1897,10 @@ static void initialize_task_config(struct maintenance_run_opts *opts,
1897 * override specific aspects of our strategy.
1898 */
1899 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;
1904 } else {
1905 strategy = default_strategy;
1906 }
t/t7900-maintenance.sh
+5
@@ -1263,6 +1263,11 @@ test_expect_success 'fails when running outside of a repository' '
1263 nongit test_must_fail git maintenance unregister
1264 '
1265
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 +
1271 test_expect_success 'register and unregister bare repo' '
1272 test_when_finished "git config --global --unset-all maintenance.repo || :" &&
1273 test_might_fail git config --global --unset-all maintenance.repo &&