Skip to content

Commit 689a2aa

Browse files
derrickstoleegitster
authored andcommitted
maintenance: disable cron on macOS
In eba1ba9 (maintenance: `git maintenance run` learned `--scheduler=<scheduler>`, 2021-09-04), we introduced the ability to specify a scheduler explicitly. This led to some extra checks around whether an alternative scheduler was available. This added the functionality of removing background maintenance from schedulers other than the one selected. On macOS, cron is technically available, but running 'crontab' triggers a UI prompt asking for special permissions. This is the major reason why launchctl is used as the default scheduler. The is_crontab_available() method triggers this UI prompt, causing user disruption. Remove this disruption by using an #ifdef to prevent running crontab this way on macOS. This has the unfortunate downside that if a user manually selects cron via the '--scheduler' option, then adjusting the scheduler later will not remove the schedule from cron. The '--scheduler' option ignores the is_available checks, which is how we can get into this situation. Extract the new check_crontab_process() method to avoid making the 'child' variable unused on macOS. The method is marked MAYBE_UNUSED because it has no callers on macOS. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 670e597 commit 689a2aa

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

builtin/gc.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,15 +1961,11 @@ static int schtasks_update_schedule(int run_maintenance, int fd)
19611961
return schtasks_remove_tasks();
19621962
}
19631963

1964-
static int is_crontab_available(void)
1964+
MAYBE_UNUSED
1965+
static int check_crontab_process(const char *cmd)
19651966
{
1966-
const char *cmd = "crontab";
1967-
int is_available;
19681967
struct child_process child = CHILD_PROCESS_INIT;
19691968

1970-
if (get_schedule_cmd(&cmd, &is_available))
1971-
return is_available;
1972-
19731969
strvec_split(&child.args, cmd);
19741970
strvec_push(&child.args, "-l");
19751971
child.no_stdin = 1;
@@ -1984,6 +1980,25 @@ static int is_crontab_available(void)
19841980
return 1;
19851981
}
19861982

1983+
static int is_crontab_available(void)
1984+
{
1985+
const char *cmd = "crontab";
1986+
int is_available;
1987+
1988+
if (get_schedule_cmd(&cmd, &is_available))
1989+
return is_available;
1990+
1991+
#ifdef __APPLE__
1992+
/*
1993+
* macOS has cron, but it requires special permissions and will
1994+
* create a UI alert when attempting to run this command.
1995+
*/
1996+
return 0;
1997+
#else
1998+
return check_crontab_process(cmd);
1999+
#endif
2000+
}
2001+
19872002
#define BEGIN_LINE "# BEGIN GIT MAINTENANCE SCHEDULE"
19882003
#define END_LINE "# END GIT MAINTENANCE SCHEDULE"
19892004

0 commit comments

Comments
 (0)