File: GetGitPath.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (76 lines) | stat: -rw-r--r-- 2,610 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function gitpath = GetGitPath
% gitpath = GetGitPath -- Return auto-detected installation path
% for git client, if any. Return empty string if auto-detection not
% possible. Typical usage is like this:
%
% mygitcommand = [GetGitPath 'git describe']; system(mygitcommand);
%
% GetGitPath will return the path to be prefixed in front of the git
% executable. If none can be found, the git executable will be executed
% without path spec. If it is installed in the system executable search
% path, it will then still work.
%
% The function simply checks if the git executable is in the Matlab path
% and returns a proper path-spec. If it isn't found in the Matlab path, it
% tries default path locations for OS-X and Windows. If that doesn't work,
% it returns an empty string.

% History:
% 07/11/13 Written, based on GetSubversionPath (DHB).
% 10/28/13 Add IsLinux where we try out various possible UNIX paths.
%          Maria Olkkonen reports that doing so makes this work properly
%          on her linux system. (DHB)

% Check for alternative install location of Git:
if IsWin
    % Search for Windows executable in Matlab's path:
    gitpath = which('git.exe');
else
    % Search for Unix executable in Matlab's path:
    gitpath = which('git.');
end

% Found one?
if ~isempty(gitpath)
    % Extract basepath and use it:
    gitpath=[fileparts(gitpath) filesep];
else
    % Could not find git executable in Matlabs path. Check the default
    % install location on OS-X and abort if it isn't there. On M$-Win we
    % simply have to hope that it is in some system dependent search path.
    
    % Currently, we only know how to check this for Mac OSX and Linux.
    if (IsOSX || IsLinux)
        gitpath = '';
        
        if isempty(gitpath) && exist('/usr/bin/git','file')
            gitpath='/usr/bin/';
        end
        
        if isempty(gitpath) && exist('/usr/local/git/bin/git','file')
            gitpath='/usr/local/git/bin/';
        end
        
        if isempty(gitpath) && exist('/usr/local/bin/git','file')
            gitpath='/usr/local/bin/';
        end
        
        if isempty(gitpath) && exist('/bin/git','file')
            gitpath='/bin/';
        end
        
        if isempty(gitpath) && exist('/opt/local/bin/git', 'file')
            gitpath = '/opt/local/bin/';
        end
    elseif IsWin
        [returnCode,gitpath] = system('where git');
        if returnCode==0
            gitpath = [fileparts(strtrim(gitpath)) filesep];
        else
            % failed, clear whatever the command returned
            gitpath = '';
        end
    end
end

return;