├── .gitignore ├── README └── git.m /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore temporary MLB editor files 2 | *.asv 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | -- Versioning -- 2 | This repo contains the latest version of git.m. 3 | Whenever there is a stable release, the submission on MATLAB Central's File Exchange will be periodically synched from the latest stable release here. 4 | 5 | -- OS, Distributions -- 6 | This version was developed on OS X, but is expected to work on POSIX-compliant systems like OS X, BSD, and GNU/Linux. 7 | Windows is a different beast, and it should work as well anecdotally, but your mileage may vary. 8 | 9 | -- To make changes -- 10 | Fork this project from Github, make your changes, and issue a pull request so I can quickly consider them. 11 | If you're new to Git and Github, this is really easy: 12 | http://help.github.com/send-pull-requests/ 13 | 14 | -- Usage -- 15 | Documented examples of usage are listed here: 16 | http://manur.github.io/blog/2010/10/30/make-matlab-git-play-well-together/ 17 | 18 | 19 | -- License -- 20 | The MIT License (MIT) 21 | 22 | Copyright (c) 2013 Manu Raghavan 23 | 24 | Permission is hereby granted, free of charge, to any person obtaining a copy 25 | of this software and associated documentation files (the "Software"), to deal 26 | in the Software without restriction, including without limitation the rights 27 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | copies of the Software, and to permit persons to whom the Software is 29 | furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice shall be included in 32 | all copies or substantial portions of the Software. 33 | 34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | THE SOFTWARE. 41 | 42 | -------------------------------------------------------------------------------- /git.m: -------------------------------------------------------------------------------- 1 | function [cmdout, statout] = git(varargin) 2 | % A thin MATLAB wrapper for Git. 3 | % 4 | % Short instructions: 5 | % Use this exactly as you would use the OS command-line verison of Git. 6 | % 7 | % Long instructions are: 8 | % This is not meant to be a comprehensive guide to the near-omnipotent 9 | % Git SCM: 10 | % http://git-scm.com/documentation 11 | % 12 | % Common MATLAB workflow: 13 | % 14 | % % Creates initial repository tracking all files under some root 15 | % % folder 16 | % >> cd ~/ 17 | % >> git init 18 | % 19 | % % Shows changes made to all files in repo (none so far) 20 | % >> git status 21 | % 22 | % % Create a new file and add some code 23 | % >> edit foo.m 24 | % 25 | % % Check repo status, after new file created 26 | % >> git status 27 | % 28 | % % Stage/unstage files for commit 29 | % >> git add foo.m % Add file to repo or to stage 30 | % >> git reset HEAD . % To unstage your files from current commit area 31 | % 32 | % % Commit your changes to a new branch, with comments 33 | % >> git commit -m 'Created new file, foo.m' 34 | % 35 | % % Other useful commands (replace ellipses with appropriate args) 36 | % >> git checkout ... % To restore files to last commit 37 | % >> git branch ... % To create or move to another branch 38 | % >> git diff ... % See line-by-line changes 39 | % 40 | % Useful resources: 41 | % 1. GitX: A visual interface for Git on the OS X client 42 | % 2. Github.com: Remote hosting for Git repos 43 | % 3. Git on Wikipedia: Further reading 44 | % 45 | % v0.1, 27 October 2010 -- MR: Initial support for OS X & Linux, 46 | % untested on PCs, but expected to work 47 | % 48 | % v0.2, 11 March 2011 -- TH: Support for PCs 49 | % 50 | % v0.3, 12 March 2011 -- MR: Fixed man pages hang bug using redirection 51 | % 52 | % v0.4, 20 November 2013-- TN: Searching for git in default directories, 53 | % returning results as variable 54 | % 55 | % v0.5, 22 January 2015 -- TP: Suppressed printing of ans before 56 | % git command output 57 | % 58 | % v0.6, 26 January 2015 -- HG: Add path to git 59 | % 60 | % v0.7 09 April 2015 -- VF: If user requests it, return Git results 61 | % as a variable instead of displaying them. 62 | % 63 | % v0.8 24 Juli 2015 -- MvdL: Return status output 64 | % 65 | % 66 | % Contributors: (MR) Manu Raghavan 67 | % (TH) Timothy Hansell 68 | % (TN) Tassos Natsakis 69 | % (TP) Tyler Parsons 70 | % (HG) Han Geerligs 71 | % (VF) Vadim Frolov 72 | % (MvdL) Marcel van der Linden 73 | % 74 | orgpath=getenv('PATH'); 75 | quit_function=0; 76 | try 77 | % Test to see if git is installed 78 | [status,~] = system('git --version'); 79 | % if git is in the path this will return a status of 0 80 | % it will return a 1 only if the command is not found 81 | 82 | % git command output 83 | result = ''; 84 | 85 | if status 86 | % Checking if git exists in the default installation folders (for 87 | % Windows) 88 | if ispc 89 | search = ~isempty(dir('c:\Program Files\Git\bin\git.exe')); 90 | searchx86 = ~isempty(dir('c:\Program Files (x86)\Git\bin\git.exe')); 91 | else 92 | search = 0; 93 | searchx86 = 0; 94 | end 95 | 96 | if ~(search||searchx86) 97 | % If git is NOT installed, then this should end the function. 98 | result = sprintf('git is not installed\n%s\n',... 99 | 'Download it at http://git-scm.com/download'); 100 | quit_function=1; % set quit_function flag: only result is displayed 101 | end 102 | end 103 | 104 | % if quit_function then only display message 105 | if ~quit_function 106 | % If git exists but the status is 1, then it means that it is 107 | % not in the path. We should add the path 108 | if status 109 | if search 110 | gitpath='c:\Program Files\Git\bin'; 111 | else if searchx86 112 | gitpath='c:\Program Files (x86)\Git\bin'; 113 | end 114 | end 115 | setenv('PATH',[gitpath pathsep orgpath]); % add path to git 116 | end 117 | 118 | % We can call the real git with the arguments 119 | arguments = parse(varargin{:}); 120 | if ispc 121 | prog = ''; 122 | else 123 | prog = ' | cat'; 124 | end 125 | if strcmp(arguments, 'commit ') 126 | answer = inputdlg('Comments:','Commit''s comments'); 127 | arguments = [arguments '-m"' char(answer) '"']; 128 | end 129 | [status,result] = system(['git ',arguments,prog]); 130 | end 131 | if nargout >= 1 132 | cmdout = strtrim(result); 133 | statout = status; 134 | else 135 | % Display result instead of returning it 136 | % to suppress output of ans 137 | disp(result); 138 | end 139 | 140 | % restore the original path 141 | setenv(orgpath); 142 | catch 143 | % restore the original path 144 | setenv(orgpath); 145 | end 146 | end 147 | 148 | function space_delimited_list = parse(varargin) 149 | space_delimited_list = cell2mat(... 150 | cellfun(@(s)([s,' ']),varargin,'UniformOutput',false)); 151 | end 152 | --------------------------------------------------------------------------------