Skip to content

Commit 61e56fa

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 d250977 + 1802775 commit 61e56fa

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
/git-unpack-file
174174
/git-unpack-objects
175175
/git-update-index
176+
/git-update-microsoft-git
176177
/git-update-ref
177178
/git-update-server-info
178179
/git-upload-archive
+24
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

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ BUILTIN_OBJS += builtin/tag.o
11751175
BUILTIN_OBJS += builtin/unpack-file.o
11761176
BUILTIN_OBJS += builtin/unpack-objects.o
11771177
BUILTIN_OBJS += builtin/update-index.o
1178+
BUILTIN_OBJS += builtin/update-microsoft-git.o
11781179
BUILTIN_OBJS += builtin/update-ref.o
11791180
BUILTIN_OBJS += builtin/update-server-info.o
11801181
BUILTIN_OBJS += builtin/upload-archive.o

builtin.h

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix);
230230
int cmd_unpack_file(int argc, const char **argv, const char *prefix);
231231
int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
232232
int cmd_update_index(int argc, const char **argv, const char *prefix);
233+
int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix);
233234
int cmd_update_ref(int argc, const char **argv, const char *prefix);
234235
int cmd_update_server_info(int argc, const char **argv, const char *prefix);
235236
int cmd_upload_archive(int argc, const char **argv, const char *prefix);

builtin/update-microsoft-git.c

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
int res;
16+
struct strvec args = STRVEC_INIT;
17+
18+
strvec_push(&args, "git-update-git-for-windows");
19+
res = run_command_v_opt(args.v, 0);
20+
strvec_clear(&args);
21+
return res;
22+
}
23+
#elif defined(__APPLE__)
24+
/*
25+
* On macOS, we expect the user to have the microsoft-git
26+
* cask installed via Homebrew. We check using these
27+
* commands:
28+
*
29+
* 1. 'brew update' to get latest versions.
30+
* 2. 'brew upgrade --cask microsoft-git' to get the
31+
* latest version.
32+
*/
33+
static int platform_specific_upgrade(void)
34+
{
35+
int res;
36+
struct strvec args = STRVEC_INIT;
37+
38+
printf("Updating Homebrew with 'brew update'\n");
39+
40+
strvec_pushl(&args, "brew", "update", NULL);
41+
res = run_command_v_opt(args.v, 0);
42+
strvec_clear(&args);
43+
44+
if (res) {
45+
error(_("'brew update' failed; is brew installed?"));
46+
return 1;
47+
}
48+
49+
printf("Upgrading microsoft-git with 'brew upgrade --cask microsoft-git'\n");
50+
strvec_pushl(&args, "brew", "upgrade", "--cask", "microsoft-git", NULL);
51+
res = run_command_v_opt(args.v, 0);
52+
strvec_clear(&args);
53+
54+
return res;
55+
}
56+
#else
57+
static int platform_specific_upgrade(void)
58+
{
59+
error(_("update-microsoft-git is not supported on this platform"));
60+
return 1;
61+
}
62+
#endif
63+
64+
static const char builtin_update_microsoft_git_usage[] =
65+
N_("git update-microsoft-git");
66+
67+
int cmd_update_microsoft_git(int argc, const char **argv, const char *prefix)
68+
{
69+
if (argc == 2 && !strcmp(argv[1], "-h"))
70+
usage(builtin_update_microsoft_git_usage);
71+
72+
return platform_specific_upgrade();
73+
}

git.c

+1
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ static struct cmd_struct commands[] = {
680680
{ "unpack-file", cmd_unpack_file, RUN_SETUP | NO_PARSEOPT },
681681
{ "unpack-objects", cmd_unpack_objects, RUN_SETUP | NO_PARSEOPT },
682682
{ "update-index", cmd_update_index, RUN_SETUP },
683+
{ "update-microsoft-git", cmd_update_microsoft_git },
683684
{ "update-ref", cmd_update_ref, RUN_SETUP },
684685
{ "update-server-info", cmd_update_server_info, RUN_SETUP },
685686
{ "upload-archive", cmd_upload_archive, NO_PARSEOPT },

0 commit comments

Comments
 (0)