MatrixBerryCore
gitcall.m
Go to the documentation of this file.
1 function [gitMsgLineList, varargout]=gitcall(ParamStr,pathStr)
2 isPath=nargin>1;
3 
4 SMsg=struct([]);
5 % call git with the given parameter string
6 if isPath
7  curDirStr=pwd();
8  cd(pathStr);
9 end
10 gitDirStr=pwd();
11 callStr=sprintf('git %s',ParamStr);
12 if isunix
13  callStr=['TERM=ansi ',callStr];
14 end
15 %
16 [gitErr,gitMsg]=system(callStr);
17 if isPath
18  cd(curDirStr);
19 end
20 
21 % create cellstring with one row per line
22 gitMsgLineList=strsplit(gitMsg,sprintf('\r\n'));
23 %
24 % check for an error reported by the operating system
25 if gitErr~=0
26  % an error is reported
27  if isempty(gitMsgLineList)
28  SMsg(1).identifier='GIT:versioningProblem';
29  SMsg(1).message=['Problem using version control system:' 10 ...
30  ' Git could not be executed! Error code is ' ...
31  num2str(gitErr) 10 ' Path is ' gitDirStr];
32  elseif strncmp('''git',gitMsgLineList{1},4)
33  SMsg(1).identifier='GIT:installationProblem';
34  SMsg(1).message=['Problem using version control system:' 10 ...
35  ' Git could not be executed!' 10 'Path is ' gitDirStr];
36  else
37  SMsg(1).identifier='GIT:versioningProblem';
38  SMsg(1).message=['Problem using version control system:' 10 ...
39  mxberry.core.cell.cellstr2colstr(gitMsgLineList,' ') 10 ' Path is ' gitDirStr];
40  end
41 elseif ~isempty(gitMsgLineList)
42  if strncmp('git:',gitMsgLineList{1},4)
43  SMsg(1).identifier='GIT:versioningProblem';
44  SMsg(1).message=['Problem using version control system:' 10 ...
45  mxberry.core.cell.cellstr2colstr(gitMsgLineList,' ') 10 ...
46  ' Path is ' gitDirStr];
47  end
48 end
49 
50 if nargout>1
51  varargout{1}=SMsg;
52 else
53  error(SMsg);
54 end
function gitcall(in ParamStr, in pathStr)