Skip to content

Commit 69ecfca

Browse files
derrickstoleegitster
authored andcommitted
maintenance: update schedule before config
When running 'git maintenance start', the current pattern is to configure global config settings to enable maintenance on the current repository and set 'maintenance.auto' to false and _then_ to set up the schedule with the system scheduler. This has a problematic error condition: if the scheduler fails to initialize, the repository still will not use automatic maintenance due to the 'maintenance.auto' setting. Fix this gap by swapping the order of operations. If Git fails to initialize maintenance, then the config changes should never happen. Reported-by: Phillip Wood <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c97ec03 commit 69ecfca

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

builtin/gc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2728,9 +2728,12 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)
27282728
opts.scheduler = resolve_scheduler(opts.scheduler);
27292729
validate_scheduler(opts.scheduler);
27302730

2731+
if (update_background_schedule(&opts, 1))
2732+
die(_("failed to set up maintenance schedule"));
2733+
27312734
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))
27322735
warning(_("failed to add repo to global config"));
2733-
return update_background_schedule(&opts, 1);
2736+
return 0;
27342737
}
27352738

27362739
static const char *const builtin_maintenance_stop_usage[] = {

t/t7900-maintenance.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,17 @@ test_expect_success 'register and unregister bare repo' '
849849
)
850850
'
851851

852+
test_expect_success 'failed schedule prevents config change' '
853+
git init --bare failcase &&
854+
855+
for scheduler in crontab launchctl schtasks systemctl
856+
do
857+
GIT_TEST_MAINT_SCHEDULER="$scheduler:false" &&
858+
export GIT_TEST_MAINT_SCHEDULER &&
859+
test_must_fail \
860+
git -C failcase maintenance start &&
861+
test_must_fail git -C failcase config maintenance.auto || return 1
862+
done
863+
'
864+
852865
test_done

0 commit comments

Comments
 (0)