forked from manur/MATLAB-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.m
100 lines (95 loc) · 3.38 KB
/
git.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function result = git(varargin)
% A thin MATLAB wrapper for Git.
%
% Short instructions:
% Use this exactly as you would use the OS command-line verison of Git.
%
% Long instructions are:
% This is not meant to be a comprehensive guide to the near-omnipotent
% Git SCM:
% http://git-scm.com/documentation
%
% Common MATLAB workflow:
%
% % Creates initial repository tracking all files under some root
% % folder
% >> cd ~/
% >> git init
%
% % Shows changes made to all files in repo (none so far)
% >> git status
%
% % Create a new file and add some code
% >> edit foo.m
%
% % Check repo status, after new file created
% >> git status
%
% % Stage/unstage files for commit
% >> git add foo.m % Add file to repo or to stage
% >> git reset HEAD . % To unstage your files from current commit area
%
% % Commit your changes to a new branch, with comments
% >> git commit -m 'Created new file, foo.m'
%
% % Other useful commands (replace ellipses with appropriate args)
% >> git checkout ... % To restore files to last commit
% >> git branch ... % To create or move to another branch
% >> git diff ... % See line-by-line changes
%
% Useful resources:
% 1. GitX: A visual interface for Git on the OS X client
% 2. Github.com: Remote hosting for Git repos
% 3. Git on Wikipedia: Further reading
%
% v0.1, 27 October 2010 -- MR: Initial support for OS X & Linux,
% untested on PCs, but expected to work
%
% v0.2, 11 March 2011 -- TH: Support for PCs
%
% v0.3, 12 March 2011 -- MR: Fixed man pages hang bug using redirection
%
% v0.4, 20 November 2013-- TN: Searching for git in default directories,
% returning results as variable
%
% Contributors: (MR) Manu Raghavan
% (TH) Timothy Hansell
% (TN) Tassos Natsakis
% Test to see if git is installed
[status,~] = system('git --version');
% if git is in the path this will return a status of 0
% it will return a 1 only if the command is not found
if status
% Checking if git exists in the default installation folders (for
% Windows)
if ispc
search = system('dir /s /b "c:\Program Files\Git\bin\git.exe');
searchx86 = system('dir /s /b "c:\Program Files (x86)\Git\bin\git.exe');
else
search = 0;
searchx86 = 0;
end
if (search||searchx86)
% If git exists but the status is 0, then it means that it is
% not in the path.
result = 'git is not included in the path';
else
% If git is NOT installed, then this should end the function.
result = sprintf('git is not installed\n%s\n',...
'Download it at http://git-scm.com/download');
end
else
% Otherwise we can call the real git with the arguments
arguments = parse(varargin{:});
if ispc
prog = '';
else
prog = ' | cat';
end
[~,result] = system(['git ',arguments,prog]);
end
end
function space_delimited_list = parse(varargin)
space_delimited_list = cell2mat(...
cellfun(@(s)([s,' ']),varargin,'UniformOutput',false));
end