|
| 1 | +#include "builtin.h" |
| 2 | +#include "repository.h" |
| 3 | +#include "parse-options.h" |
| 4 | +#include "run-command.h" |
| 5 | +#include "strvec.h" |
| 6 | + |
| 7 | +#if defined(GIT_WINDOWS_NATIVE) |
| 8 | +/* |
| 9 | + * On Windows, run 'git update-git-for-windows' which |
| 10 | + * is installed by the installer, based on the script |
| 11 | + * in git-for-windows/build-extra. |
| 12 | + */ |
| 13 | +static int platform_specific_upgrade(void) |
| 14 | +{ |
| 15 | + struct child_process cp = CHILD_PROCESS_INIT; |
| 16 | + |
| 17 | + strvec_push(&cp.args, "git-update-git-for-windows"); |
| 18 | + return run_command(&cp); |
| 19 | +} |
| 20 | +#elif defined(__APPLE__) |
| 21 | +/* |
| 22 | + * On macOS, we expect the user to have the microsoft-git |
| 23 | + * cask installed via Homebrew. We check using these |
| 24 | + * commands: |
| 25 | + * |
| 26 | + * 1. 'brew update' to get latest versions. |
| 27 | + * 2. 'brew upgrade --cask microsoft-git' to get the |
| 28 | + * latest version. |
| 29 | + */ |
| 30 | +static int platform_specific_upgrade(void) |
| 31 | +{ |
| 32 | + int res; |
| 33 | + struct child_process update = CHILD_PROCESS_INIT; |
| 34 | + struct child_process upgrade = CHILD_PROCESS_INIT; |
| 35 | + |
| 36 | + printf("Updating Homebrew with 'brew update'\n"); |
| 37 | + |
| 38 | + strvec_pushl(&update.args, "brew", "update", NULL); |
| 39 | + res = run_command(&update); |
| 40 | + |
| 41 | + if (res) { |
| 42 | + error(_("'brew update' failed; is brew installed?")); |
| 43 | + return 1; |
| 44 | + } |
| 45 | + |
| 46 | + printf("Upgrading microsoft-git with 'brew upgrade --cask microsoft-git'\n"); |
| 47 | + strvec_pushl(&upgrade.args, "brew", "upgrade", "--cask", "microsoft-git", NULL); |
| 48 | + res = run_command(&upgrade); |
| 49 | + |
| 50 | + return res; |
| 51 | +} |
| 52 | +#else |
| 53 | +static int platform_specific_upgrade(void) |
| 54 | +{ |
| 55 | + error(_("update-microsoft-git is not supported on this platform")); |
| 56 | + return 1; |
| 57 | +} |
| 58 | +#endif |
| 59 | + |
| 60 | +static const char builtin_update_microsoft_git_usage[] = |
| 61 | + N_("git update-microsoft-git"); |
| 62 | + |
| 63 | +int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) |
| 64 | +{ |
| 65 | + if (argc == 2 && !strcmp(argv[1], "-h")) |
| 66 | + usage(builtin_update_microsoft_git_usage); |
| 67 | + |
| 68 | + return platform_specific_upgrade(); |
| 69 | +} |
0 commit comments