Skip to content

Commit b0d4a8b

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request #329: Add git update-microsoft-git
This adds a new builtin, `git update-microsoft-git`, that executes the platform-specific upgrade steps to get the latest version of `microsoft-git`. On Windows, this means running `git update-git-for-windows` which was updated to use the `microsoft/git` releases page, when appropriate. See #321 for details. On macOS, this means running a sequence of `brew` commands. These are adapted from the `UpgradeVerb` in `microsoft/scalar`, with an important simplification: we don't need to differentiate between the `scalar` and `scalar-azrepos` cask.
2 parents 48ed842 + aef1761 commit b0d4a8b

9 files changed

+107
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
/git-unpack-file
175175
/git-unpack-objects
176176
/git-update-index
177+
/git-update-microsoft-git
177178
/git-update-ref
178179
/git-update-server-info
179180
/git-upload-archive
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
git-update-microsoft-git(1)
2+
===========================
3+
4+
NAME
5+
----
6+
git-update-microsoft-git - Update the installed version of Git
7+
8+
9+
SYNOPSIS
10+
--------
11+
[verse]
12+
'git update-microsoft-git'
13+
14+
DESCRIPTION
15+
-----------
16+
This version of Git is based on the Microsoft fork of Git, which
17+
has custom capabilities focused on supporting monorepos. This
18+
command checks for the latest release of that fork and installs
19+
it on your machine.
20+
21+
22+
GIT
23+
---
24+
Part of the linkgit:git[1] suite

Documentation/lint-manpages.sh

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ check_missing_docs () (
2828
git-remote-*) continue;;
2929
git-stage) continue;;
3030
git-gvfs-helper) continue;;
31+
git-update-microsoft-git) continue;;
3132
git-legacy-*) continue;;
3233
git-?*--?* ) continue ;;
3334
esac

Documentation/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ manpages = {
149149
'git-unpack-file.adoc' : 1,
150150
'git-unpack-objects.adoc' : 1,
151151
'git-update-index.adoc' : 1,
152+
'git-update-microsoft-git.adoc' : 1,
152153
'git-update-ref.adoc' : 1,
153154
'git-update-server-info.adoc' : 1,
154155
'git-upload-archive.adoc' : 1,

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ BUILTIN_OBJS += builtin/tag.o
13361336
BUILTIN_OBJS += builtin/unpack-file.o
13371337
BUILTIN_OBJS += builtin/unpack-objects.o
13381338
BUILTIN_OBJS += builtin/update-index.o
1339+
BUILTIN_OBJS += builtin/update-microsoft-git.o
13391340
BUILTIN_OBJS += builtin/update-ref.o
13401341
BUILTIN_OBJS += builtin/update-server-info.o
13411342
BUILTIN_OBJS += builtin/upload-archive.o

builtin.h

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix, struct repository *
239239
int cmd_unpack_file(int argc, const char **argv, const char *prefix, struct repository *repo);
240240
int cmd_unpack_objects(int argc, const char **argv, const char *prefix, struct repository *repo);
241241
int cmd_update_index(int argc, const char **argv, const char *prefix, struct repository *repo);
242+
int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix, struct repository *repo);
242243
int cmd_update_ref(int argc, const char **argv, const char *prefix, struct repository *repo);
243244
int cmd_update_server_info(int argc, const char **argv, const char *prefix, struct repository *repo);
244245
int cmd_upload_archive(int argc, const char **argv, const char *prefix, struct repository *repo);

builtin/update-microsoft-git.c

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 * const update_microsoft_git_usage[] = {
61+
N_("git update-microsoft-git"),
62+
NULL,
63+
};
64+
65+
66+
int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix UNUSED, struct repository *repo UNUSED)
67+
{
68+
static struct option microsoft_git_options[] = {
69+
OPT_END(),
70+
};
71+
show_usage_with_options_if_asked(argc, argv,
72+
update_microsoft_git_usage,
73+
microsoft_git_options);
74+
75+
return platform_specific_upgrade();
76+
}

git.c

+1
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ static struct cmd_struct commands[] = {
710710
{ "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT },
711711
{ "unpack-objects", cmd_unpack_objects, RUN_SETUP | NO_PARSEOPT },
712712
{ "update-index", cmd_update_index, RUN_SETUP },
713+
{ "update-microsoft-git", cmd_update_microsoft_git },
713714
{ "update-ref", cmd_update_ref, RUN_SETUP },
714715
{ "update-server-info", cmd_update_server_info, RUN_SETUP },
715716
{ "upload-archive", cmd_upload_archive, NO_PARSEOPT },

meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ builtin_sources = [
626626
'builtin/unpack-file.c',
627627
'builtin/unpack-objects.c',
628628
'builtin/update-index.c',
629+
'builtin/update-microsoft-git.c',
629630
'builtin/update-ref.c',
630631
'builtin/update-server-info.c',
631632
'builtin/upload-archive.c',

0 commit comments

Comments
 (0)