]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/maintenance: mark "--task=" and "--schedule=" as incompatible
authorPatrick Steinhardt <ps@pks.im>
Tue, 3 Jun 2025 14:01:12 +0000 (16:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jun 2025 15:30:49 +0000 (08:30 -0700)
The "--task=" option explicitly allows the user to say which maintenance
tasks should be run, whereas "--schedule=" only respects the maintenance
strategy configured for a specific repository. As such, it is not
sensible to accept both options at the same time.

Mark them as incompatible with one another. While at it, also convert
the existing logic that marks "--auto" and "--schedule=" as incompatible
to use `die_for_incompatible_opt2()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
t/t7900-maintenance.sh

index c4af9b1128711b0f739edd01d10ebe3c582033b2..57d7602596a864efca2862e148c5326225b949e5 100644 (file)
@@ -1785,8 +1785,10 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
                             builtin_maintenance_run_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
 
-       if (opts.auto_flag && opts.schedule)
-               die(_("use at most one of --auto and --schedule=<frequency>"));
+       die_for_incompatible_opt2(opts.auto_flag, "--auto",
+                                 opts.schedule, "--schedule=");
+       die_for_incompatible_opt2(selected_tasks.nr, "--task=",
+                                 opts.schedule, "--schedule=");
 
        gc_config(&cfg);
        initialize_task_config(&selected_tasks, opts.schedule);
index 8cf89e285f49e5d2f891636d39b089f03e571156..1ada52466065cbf80cb134d418cf79c00d51b593 100755 (executable)
@@ -610,7 +610,12 @@ test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.aut
 
 test_expect_success '--auto and --schedule incompatible' '
        test_must_fail git maintenance run --auto --schedule=daily 2>err &&
-       test_grep "at most one" err
+       test_grep "cannot be used together" err
+'
+
+test_expect_success '--task and --schedule incompatible' '
+       test_must_fail git maintenance run --task=pack-refs --schedule=daily 2>err &&
+       test_grep "cannot be used together" err
 '
 
 test_expect_success 'invalid --schedule value' '