1
function gitpath = GetGitPath
2
% gitpath = GetGitPath -- Return auto-detected installation path
3
% for git client, if any. Return empty string if auto-detection not
4
% possible. Typical usage is like this:
6
% mygitcommand = [GetGitPath 'git describe']; system(mygitcommand);
8
% GetGitPath will return the path to be prefixed in front of the git
9
% executable. If none can be found, the git executable will be executed
10
% without path spec. If it is installed in the system executable search
11
% path, it will then still work.
13
% The function simply checks if the git executable is in the Matlab path
14
% and returns a proper path-spec. If it isn't found in the Matlab path, it
15
% tries default path locations for OS-X and Windows. If that doesn't work,
16
% it returns an empty string.
19
% 07/11/13 Written, based on GetSubversionPath (DHB).
21
% Check for alternative install location of Git:
23
% Search for Windows executable in Matlab's path:
24
gitpath = which('git.exe');
26
% Search for Unix executable in Matlab's path:
27
gitpath = which('git.');
32
% Extract basepath and use it:
33
gitpath=[fileparts(gitpath) filesep];
35
% Could not find git executable in Matlabs path. Check the default
36
% install location on OS-X and abort if it isn't there. On M$-Win we
37
% simply have to hope that it is in some system dependent search path.
39
% Currently, we only know how to check this for Mac OSX.
43
if isempty(gitpath) && exist('/usr/bin/git','file')
47
if isempty(gitpath) && exist('/usr/local/git/bin/git','file')
48
gitpath='/usr/local/git/bin/';
51
if isempty(gitpath) && exist('/usr/local/bin/git','file')
52
gitpath='/usr/local/bin/';
55
if isempty(gitpath) && exist('/bin/git','file')
59
if isempty(gitpath) && exist('/opt/local/bin/git', 'file')
60
gitpath = '/opt/local/bin/';