From 2b0ba8e1f3223491df00ce95883b537b113802cc Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 29 Apr 2021 11:18:46 -0400 Subject: [PATCH] update-microsoft-git: use brew on macOS The steps to update the microsoft-git cask are: 1. brew update 2. brew upgrade --cask microsoft-git This is adapted from the UpgradeVerb within microsoft/scalar. There is one important simplification: Scalar needed to check 'brew list --cask' to find out if the 'scalar' cask or the 'scalar-azrepos' cask was installed (which determined if the 'microsoft-git' cask was a necessary dependency). We do not need that here, since we are already in the microsoft-git cask. Signed-off-by: Derrick Stolee --- builtin/update-microsoft-git.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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) {