1
- function git(varargin )
1
+ function cmdout = git(varargin )
2
2
% A thin MATLAB wrapper for Git.
3
3
%
4
4
% Short instructions:
@@ -57,24 +57,27 @@ function git(varargin)
57
57
%
58
58
% v0.6, 26 January 2015 -- HG: Add path to git
59
59
%
60
+ % v0.7 09 April 2015 -- VF: If user requests it, return Git results
61
+ % as a variable instead of displaying them.
62
+ %
60
63
% Contributors: (MR) Manu Raghavan
61
64
% (TH) Timothy Hansell
62
65
% (TN) Tassos Natsakis
63
66
% (TP) Tyler Parsons
64
67
% (HG) Han Geerligs
68
+ % (VF) Vadim Frolov
65
69
%
66
-
67
70
orgpath= getenv(' PATH' );
68
71
quit_function= 0 ;
69
72
try
70
73
% Test to see if git is installed
71
74
[status ,~ ] = system(' git --version' );
72
75
% if git is in the path this will return a status of 0
73
76
% it will return a 1 only if the command is not found
74
-
77
+
75
78
% git command output
76
79
result = ' ' ;
77
-
80
+
78
81
if status
79
82
% Checking if git exists in the default installation folders (for
80
83
% Windows)
@@ -85,15 +88,15 @@ function git(varargin)
85
88
search = 0 ;
86
89
searchx86 = 0 ;
87
90
end
88
-
91
+
89
92
if ~(search || searchx86 )
90
93
% If git is NOT installed, then this should end the function.
91
94
result = sprintf(' git is not installed\n%s\n ' ,...
92
95
' Download it at http://git-scm.com/download' );
93
96
quit_function= 1 ; % set quit_function flag: only result is displayed
94
97
end
95
98
end
96
-
99
+
97
100
% if quit_function then only display message
98
101
if ~quit_function
99
102
% If git exists but the status is 1, then it means that it is
@@ -107,7 +110,7 @@ function git(varargin)
107
110
end
108
111
setenv(' PATH' ,[gitpath pathsep orgpath ]); % add path to git
109
112
end
110
-
113
+
111
114
% We can call the real git with the arguments
112
115
arguments = parse(varargin{: });
113
116
if ispc
@@ -121,10 +124,14 @@ function git(varargin)
121
124
end
122
125
[~ ,result ] = system([' git ' ,arguments ,prog ]);
123
126
end
124
- % Display result instead of returning it
125
- % to suppress output of ans
126
- disp(result );
127
-
127
+ if nargout >= 1
128
+ cmdout = strtrim(result );
129
+ else
130
+ % Display result instead of returning it
131
+ % to suppress output of ans
132
+ disp(result );
133
+ end
134
+
128
135
% restore the original path
129
136
setenv(orgpath );
130
137
catch
0 commit comments