From d2074eb7f39f88a693c1b7611fb0c703bb8a9595 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 29 Apr 2021 10:58:39 -0400 Subject: [PATCH 1/3] update-microsoft-git: create barebones builtin Just do the boilerplate stuff of making a new builtin, including documentation and integration with git.c. Signed-off-by: Derrick Stolee --- .gitignore | 1 + Documentation/git-update-microsoft-git.txt | 24 ++++++++++++++++++++++ Documentation/lint-manpages.sh | 1 + Makefile | 1 + builtin.h | 1 + builtin/update-microsoft-git.c | 20 ++++++++++++++++++ git.c | 1 + meson.build | 1 + 8 files changed, 50 insertions(+) create mode 100644 Documentation/git-update-microsoft-git.txt create mode 100644 builtin/update-microsoft-git.c diff --git a/.gitignore b/.gitignore index a461bdd35b2985..3e0b4d016cb1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -174,6 +174,7 @@ /git-unpack-file /git-unpack-objects /git-update-index +/git-update-microsoft-git /git-update-ref /git-update-server-info /git-upload-archive diff --git a/Documentation/git-update-microsoft-git.txt b/Documentation/git-update-microsoft-git.txt new file mode 100644 index 00000000000000..724bfc172f8ab7 --- /dev/null +++ b/Documentation/git-update-microsoft-git.txt @@ -0,0 +1,24 @@ +git-update-microsoft-git(1) +=========================== + +NAME +---- +git-update-microsoft-git - Update the installed version of Git + + +SYNOPSIS +-------- +[verse] +'git update-microsoft-git' + +DESCRIPTION +----------- +This version of Git is based on the Microsoft fork of Git, which +has custom capabilities focused on supporting monorepos. This +command checks for the latest release of that fork and installs +it on your machine. + + +GIT +--- +Part of the linkgit:git[1] suite diff --git a/Documentation/lint-manpages.sh b/Documentation/lint-manpages.sh index 8bc316ba7646e3..2622a493566950 100755 --- a/Documentation/lint-manpages.sh +++ b/Documentation/lint-manpages.sh @@ -28,6 +28,7 @@ check_missing_docs () ( git-remote-*) continue;; git-stage) continue;; git-gvfs-helper) continue;; + git-update-microsoft-git) continue;; git-legacy-*) continue;; git-?*--?* ) continue ;; esac diff --git a/Makefile b/Makefile index bd1034b6f0a027..a2e2a58f6bc198 100644 --- a/Makefile +++ b/Makefile @@ -1326,6 +1326,7 @@ BUILTIN_OBJS += builtin/tag.o BUILTIN_OBJS += builtin/unpack-file.o BUILTIN_OBJS += builtin/unpack-objects.o BUILTIN_OBJS += builtin/update-index.o +BUILTIN_OBJS += builtin/update-microsoft-git.o BUILTIN_OBJS += builtin/update-ref.o BUILTIN_OBJS += builtin/update-server-info.o BUILTIN_OBJS += builtin/upload-archive.o diff --git a/builtin.h b/builtin.h index 5f64730cf0273d..f99519a65bcba6 100644 --- a/builtin.h +++ b/builtin.h @@ -239,6 +239,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix, struct repository * int cmd_unpack_file(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_unpack_objects(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo); +int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo); int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo); diff --git a/builtin/update-microsoft-git.c b/builtin/update-microsoft-git.c new file mode 100644 index 00000000000000..2d555a1ece21e8 --- /dev/null +++ b/builtin/update-microsoft-git.c @@ -0,0 +1,20 @@ +#include "builtin.h" +#include "repository.h" +#include "parse-options.h" +#include "run-command.h" + +static int platform_specific_upgrade(void) +{ + return 1; +} + +static const char builtin_update_microsoft_git_usage[] = + N_("git update-microsoft-git"); + +int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED) +{ + if (argc == 2 && !strcmp(argv[1], "-h")) + usage(builtin_update_microsoft_git_usage); + + return platform_specific_upgrade(); +} diff --git a/git.c b/git.c index 7e244b82f450eb..c24ba4924ee5c4 100644 --- a/git.c +++ b/git.c @@ -708,6 +708,7 @@ static struct cmd_struct commands[] = { { "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT }, { "unpack-objects", cmd_unpack_objects, RUN_SETUP | NO_PARSEOPT }, { "update-index", cmd_update_index, RUN_SETUP }, + { "update-microsoft-git", cmd_update_microsoft_git }, { "update-ref", cmd_update_ref, RUN_SETUP }, { "update-server-info", cmd_update_server_info, RUN_SETUP }, { "upload-archive", cmd_upload_archive, NO_PARSEOPT }, diff --git a/meson.build b/meson.build index e977eda6e6a349..5c1672b89c40b8 100644 --- a/meson.build +++ b/meson.build @@ -603,6 +603,7 @@ builtin_sources = [ 'builtin/unpack-file.c', 'builtin/unpack-objects.c', 'builtin/update-index.c', + 'builtin/update-microsoft-git.c', 'builtin/update-ref.c', 'builtin/update-server-info.c', 'builtin/upload-archive.c', From d8f3ba1f2b634ac0e67e5312a2ad7c8da4e2ac77 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 29 Apr 2021 11:02:07 -0400 Subject: [PATCH 2/3] update-microsoft-git: Windows implementation On Windows, we have the 'git update-git-for-windows' command. It is poorly named within the microsoft/git fork, because the script has been updated to look at the GitHub releases of microsoft/git, not git-for-windows/git. Still, it handles all the complicated details about downloading, verifying, and running the installer. Signed-off-by: Derrick Stolee --- builtin/update-microsoft-git.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builtin/update-microsoft-git.c b/builtin/update-microsoft-git.c index 2d555a1ece21e8..6c426d66ea5f16 100644 --- a/builtin/update-microsoft-git.c +++ b/builtin/update-microsoft-git.c @@ -2,11 +2,28 @@ #include "repository.h" #include "parse-options.h" #include "run-command.h" +#include "strvec.h" +#if defined(GIT_WINDOWS_NATIVE) +/* + * On Windows, run 'git update-git-for-windows' which + * is installed by the installer, based on the script + * in git-for-windows/build-extra. + */ static int platform_specific_upgrade(void) { + struct child_process cp = CHILD_PROCESS_INIT; + + strvec_push(&cp.args, "git-update-git-for-windows"); + return run_command(&cp); +} +#else +static int platform_specific_upgrade(void) +{ + error(_("update-microsoft-git is not supported on this platform")); return 1; } +#endif static const char builtin_update_microsoft_git_usage[] = N_("git update-microsoft-git"); From 84d3139755f7c46653af6c009651b48ecd299366 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 29 Apr 2021 11:18:46 -0400 Subject: [PATCH 3/3] 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 6c426d66ea5f16..54e196b70116f2 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) {