Skip to content

Commit 82db149

Browse files
committed
update-microsoft-git: interface with apt-get on Linux
The 'git update-microsoft-git' builtin already interfaces with the git-for-windows/git upgrader on Windows and brew on macOS. Add an integration with apt-get on Ubuntu. The implementation attempts to call apt-get on all Linux machines, but it will report a failure when that is not available. The two commands are: 1. sudo apt-get update 2. sudo apt-get upgrade microsoft-git The first has an error message because that will likely only fail when apt-get does not exist on the path (or the user fails to supply the sudo password). The error condition for the second is passed to the user. It is possible that a user installs a package manually and not through a Microsoft feed, in which case the 'upgrade' command will fail with an error message. Extra newlines are added to provide whitespace between the Git messages and the dense output from apt-get. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 3011dc5 commit 82db149

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

builtin/update-microsoft-git.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,26 @@ static int platform_specific_upgrade(void)
5656
#else
5757
static int platform_specific_upgrade(void)
5858
{
59-
error(_("update-microsoft-git is not supported on this platform"));
60-
return 1;
59+
int res;
60+
struct strvec args = STRVEC_INIT;
61+
62+
printf("Updating apt-get with 'sudo apt-get update'\n\n");
63+
64+
strvec_pushl(&args, "sudo", "apt-get", "update", NULL);
65+
res = run_command_v_opt(args.v, 0);
66+
strvec_clear(&args);
67+
68+
if (res) {
69+
error(_("'sudo apt-get update' failed; is apt-get installed?"));
70+
return 1;
71+
}
72+
73+
printf("\nUpgrading microsoft-git with 'sudo apt-get upgrade microsoft-git'\n\n");
74+
strvec_pushl(&args, "sudo", "apt-get", "upgrade", "microsoft-git", NULL);
75+
res = run_command_v_opt(args.v, 0);
76+
strvec_clear(&args);
77+
78+
return res;
6179
}
6280
#endif
6381

0 commit comments

Comments
 (0)