diff --git a/builtin/update-microsoft-git.c b/builtin/update-microsoft-git.c index e2335aa594a4a9..3152ee23c30096 100644 --- a/builtin/update-microsoft-git.c +++ b/builtin/update-microsoft-git.c @@ -17,6 +17,38 @@ static int platform_specific_upgrade(void) strvec_push(&cp.args, "git-update-git-for-windows"); return run_command(&cp); } +#elif defined(__APPLE__) +/* + * On macOS, we expect the user to have the microsoft-git + * cask installed via Homebrew. We check using these + * commands: + * + * 1. 'brew update' to get latest versions. + * 2. 'brew upgrade --cask microsoft-git' to get the + * latest version. + */ +static int platform_specific_upgrade(void) +{ + int res; + struct child_process update = CHILD_PROCESS_INIT; + struct child_process upgrade = CHILD_PROCESS_INIT; + + printf("Updating Homebrew with 'brew update'\n"); + + strvec_pushl(&update.args, "brew", "update", NULL); + res = run_command(&update); + + if (res) { + error(_("'brew update' failed; is brew installed?")); + return 1; + } + + printf("Upgrading microsoft-git with 'brew upgrade --cask microsoft-git'\n"); + strvec_pushl(&upgrade.args, "brew", "upgrade", "--cask", "microsoft-git", NULL); + res = run_command(&upgrade); + + return res; +} #else static int platform_specific_upgrade(void) {