|
1 |
| -function [ftver, ftpath] = ft_version |
| 1 | +function [ftver, ftpath] = ft_version(command) |
2 | 2 |
|
3 | 3 | % FT_VERSION returns the version and installation directory of FieldTrip
|
4 | 4 | %
|
|
19 | 19 | %
|
20 | 20 | % See also VERSION, VER
|
21 | 21 |
|
22 |
| -% Copyright (C) 2012, Eelke Spaak |
| 22 | +% Copyright (C) 2012-2016, Eelke Spaak |
23 | 23 | %
|
24 | 24 | % This file is part of FieldTrip, see http://www.ru.nl/donders/fieldtrip
|
25 | 25 | % for the documentation and details.
|
|
42 | 42 | persistent issvn
|
43 | 43 | persistent isgit
|
44 | 44 |
|
| 45 | +if nargin<1 |
| 46 | + % this is only supported for git |
| 47 | + command='revision'; |
| 48 | +end |
| 49 | + |
45 | 50 | ftpath = fileparts(mfilename('fullpath'));
|
46 | 51 | ftpath = ftpath(1:end-10); % strip away '/utilities' where this function is located
|
47 | 52 |
|
|
81 | 86 | end
|
82 | 87 |
|
83 | 88 | elseif isgit
|
84 |
| - % use git system call to determine latest revision |
85 |
| - olddir = pwd(); |
86 |
| - cd(ftpath); |
87 |
| - [status, output] = system(sprintf('git%s rev-parse --short HEAD', ext)); |
88 |
| - cd(olddir); |
89 |
| - if status > 0 |
| 89 | + % test whether the git executable is available |
| 90 | + [status, output] = system(sprintf('git%s --version', ext)); |
| 91 | + if status>0 |
90 | 92 | if ~ispc
|
91 | 93 | % the command line tools will probably not be available on windows
|
92 |
| - warning('you seem to have an GIT development copy of FieldTrip, yet ''git rev-parse'' does not work as expected'); |
| 94 | + warning('you seem to have an GIT development copy of FieldTrip, yet ''git'' does not work as expected'); |
93 | 95 | end
|
94 | 96 | ftver = 'unknown';
|
| 97 | + |
95 | 98 | else
|
96 |
| - ftver = strtrim(output); % remove trailing newline character |
97 |
| - end |
| 99 | + % use git system call to determine latest revision |
| 100 | + olddir = pwd(); |
| 101 | + cd(ftpath); |
| 102 | + switch command |
| 103 | + case 'branch' |
| 104 | + [status, output] = system(sprintf('git%s rev-parse --abbrev-ref HEAD', ext)); |
| 105 | + ftver = strtrim(output); % remove trailing newline character |
| 106 | + case 'revision' |
| 107 | + [status, output] = system(sprintf('git%s rev-parse --short HEAD', ext)); |
| 108 | + ftver = strtrim(output); % remove trailing newline character |
| 109 | + case 'clean' |
| 110 | + [status, output] = system(sprintf('git%s diff --quiet --exit-code', ext)); |
| 111 | + if status |
| 112 | + ftver = 'no'; |
| 113 | + else |
| 114 | + ftver = 'yes'; |
| 115 | + end |
| 116 | + otherwise |
| 117 | + error('unsupported command "%s"'); |
| 118 | + end |
| 119 | + cd(olddir); |
| 120 | + |
| 121 | + end % if git available |
98 | 122 |
|
99 | 123 | elseif isequal(regexp(ftpath, ['.*' filesep 'fieldtrip-fieldtrip-[[0-9][a-z]]{7}']), 1)
|
100 | 124 | % this corresponds with being downloaded from the Mathworks file exchange link to github
|
|
114 | 138 | end % if issvn, isgit or otherwise
|
115 | 139 |
|
116 | 140 | if nargout==0
|
117 |
| - fprintf('\nThis is FieldTrip, version %s.\n\n', ftver); |
118 |
| - clear ftver |
| 141 | + fprintf('\nThis is FieldTrip, %s %s.\n\n', command, ftver); |
| 142 | + clear ftver ftpath |
119 | 143 | end
|
0 commit comments