-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitcheck.m
More file actions
43 lines (43 loc) · 1.24 KB
/
gitcheck.m
File metadata and controls
43 lines (43 loc) · 1.24 KB
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
function [status msg] = gitcheck(repopath,threshold_seconds);
%GITCHECK check to see if a repository is out of date
%msg = gitcheck(repopath,threshold_seconds);
if ~exist('threshold_seconds','var')
threshold_seconds = 60*60*24;
end
return_path = pwd;
cd (repopath)
fetch_head = fullfile(repopath,'.git','FETCH_HEAD');
if ~exist(fetch_head,'file')
msg = printf('%s: Unable to locate GIT info\n',repopath);
status = -1;
return
end
f = dir(fetch_head);
seconds_since_fetch = (now-f.datenum)*24*60*60;
fid = fopen(fetch_head,'rt');
s = fread(fid);
fclose(fid);
A = textscan(char(s'),'%s','delimiter',sprintf('\t'));
repo_name = A{1}{end};
if seconds_since_fetch>threshold_seconds
try
[status fmsg] = system('git fetch');
[status stmsg] = system('git status');
catch
msg = sprintf('%s: Unable to obtain GIT status from the remote',repo_name);
status = -1;
return
end
MSG = textscan(stmsg,'%s','delimiter',sprintf('\n'));
stmsg = MSG{1}{2};
msg = sprintf('%s: %s',repo_name,stmsg);
if ~isempty(strfind(stmsg,'up-to-date'));
status = 0;
else
status = 1;
end
else
msg = sprintf('%s last fetched %0.0f seconds ago',repo_name);
status = 0;
end
cd(return_path);