builtin/maintenance: mark "--task=" and "--schedule=" as incompatible
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>
Patrick Steinhardt committed
Jun 3, 2025 at 16:01 UTC
a7c86d328ffe2d93cb1bfaf557dba7a2034ec17b
2 files changed
+10
-3
builtin/gc.c
+4
-2
@@ -1785,8 +1785,10 @@ static int maintenance_run(int argc, const char **argv, const char *prefix,
1785
builtin_maintenance_run_usage,
1786
PARSE_OPT_STOP_AT_NON_OPTION);
1787
1788
- if (opts.auto_flag && opts.schedule)
1789
- die(_("use at most one of --auto and --schedule=<frequency>"));
1788
+ die_for_incompatible_opt2(opts.auto_flag, "--auto",
1789
+ opts.schedule, "--schedule=");
1790
+ die_for_incompatible_opt2(selected_tasks.nr, "--task=",
1791
+ opts.schedule, "--schedule=");
1792
1793
gc_config(&cfg);
1794
initialize_task_config(&selected_tasks, opts.schedule);
t/t7900-maintenance.sh
+6
-1
@@ -610,7 +610,12 @@ test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.aut
610
611
test_expect_success '--auto and --schedule incompatible' '
612
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
613
- test_grep "at most one" err
613
+ test_grep "cannot be used together" err
614
+'
615
+
616
+test_expect_success '--task and --schedule incompatible' '
617
+ test_must_fail git maintenance run --task=pack-refs --schedule=daily 2>err &&
618
+ test_grep "cannot be used together" err
619
'
620
621
test_expect_success 'invalid --schedule value' '