-
Notifications
You must be signed in to change notification settings - Fork 308
/
getGitBashVersion.m
42 lines (37 loc) · 1.49 KB
/
getGitBashVersion.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [installedVersion, installedVersionNum] = getGitBashVersion()
% On Windows, this function determines the version of gitBash.
% This function can only be run on Windows, and throws an error when run on a UNIX system.
%
% USAGE:
% [installedVersion, installedVersionNum] = getGitBashVersion()
%
% OUTPUT:
% installedVersion: String of installed version of gitBash in the form `2.13.2`
% installedVersionNum: Integer of `installedVersion`, e.g. `2132`
%
global gitBashVersion
% define the name of the temporary folder
tmpFolder = '.tmp';
if ispc
installedVersion = [];
installedVersionNum = 0;
% determine the installed version
pathVersion = getsysenvironvar('Path');
index1 = strfind(pathVersion, [tmpFolder filesep 'PortableGit-']);
index2 = strfind(pathVersion, [filesep 'usr' filesep 'bin']);
catchLength = length([tmpFolder filesep 'PortableGit-']);
index1 = index1 + catchLength;
if ~isempty(index2) && ~isempty(index1)
if index2(1) > index1(1)
installedVersion = pathVersion(index1(1):index1(1) + index2(1) - index1(1) - 1);
installedVersionNum = str2num(strrep(installedVersion, '.', ''));
end
end
% define a minimal version to be installed should there
if isempty(installedVersion)
installedVersion = gitBashVersion;
end
else
error('gitBash can only be installed on Windows.');
end
end