Skip to content

Commit 7233c62

Browse files
derrickstoleedscho
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 <phillip.wood123@gmail.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com>
1 parent b896f1d commit 7233c62

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
@@ -2771,9 +2771,12 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)
27712771
opts.scheduler = resolve_scheduler(opts.scheduler);
27722772
validate_scheduler(opts.scheduler);
27732773

2774+
if (update_background_schedule(&opts, 1))
2775+
die(_("failed to set up maintenance schedule"));
2776+
27742777
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))
27752778
warning(_("failed to add repo to global config"));
2776-
return update_background_schedule(&opts, 1);
2779+
return 0;
27772780
}
27782781

27792782
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
@@ -866,4 +866,17 @@ test_expect_success 'register and unregister bare repo' '
866866
)
867867
'
868868

869+
test_expect_success 'failed schedule prevents config change' '
870+
git init --bare failcase &&
871+
872+
for scheduler in crontab launchctl schtasks systemctl
873+
do
874+
GIT_TEST_MAINT_SCHEDULER="$scheduler:false" &&
875+
export GIT_TEST_MAINT_SCHEDULER &&
876+
test_must_fail \
877+
git -C failcase maintenance start &&
878+
test_must_fail git -C failcase config maintenance.auto || return 1
879+
done
880+
'
881+
869882
test_done

0 commit comments

Comments
 (0)