Skip to content

Commit 0ff7427

Browse files
author
Jai Bhagat
authored
additional comments for git.update
1 parent 3d90407 commit 0ff7427

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

cortexlab/+git/update.m

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
11
function update(scheduled)
22
% GIT.UPDATE Pull latest Rigbox code
3-
% Pulls the latest code from the remote repository. If scheduled is a
4-
% value in the range [1 7] corresponding to the days of the week starting
5-
% Sunday, the function will only continue on that day, provided the last
6-
% fetch was over a day ago. If it is not the scheduled day, but the last
7-
% fetch was over a week ago, the function will pull changes. If
8-
% scheduled is false, the function will pull changes provided the last
9-
% fetch was over an hour ago.
3+
% Pulls the latest code from the remote Github repository. If 'scheduled'
4+
% is a value in the range [1 7] - corresponding to the days of the week,
5+
% with Sunday=1 - code will be pulled only on the 'scheduled' day,
6+
% provided the last fetch was over a day ago. Code will also be pulled if
7+
% it is not the scheduled day, but the last fetch was over a week ago. If
8+
% scheduled is 0, the function will pull changes provided the last fetch
9+
% was over an hour ago.
1010
%
1111
% TODO Find quicker way to check for changes
1212
% See also DAT.PATHS
13-
if nargin < 1; scheduled = getOr(dat.paths, 'updateSchedule', 0); end
1413

15-
root = fileparts(which('addRigboxPaths'));
14+
% If not given as input argument, find 'scheduled' in 'dat.paths'. If not
15+
% found, set 'scheduled' to 0.
16+
if nargin < 1; scheduled = getOr(dat.paths, 'updateSchedule', 0); end
17+
root = fileparts(which('addRigboxPaths')); % Rigbox root directory
1618
% Attempt to find date of last fetch
1719
fetch_head = fullfile(root, '.git', 'FETCH_HEAD');
1820
lastFetch = iff(exist(fetch_head,'file')==2, ... % If FETCH_HEAD file exists
1921
@()getOr(dir(fetch_head), 'datenum'), 0); % Retrieve date modified
2022

2123
% Don't pull changes if the following conditions are met:
22-
% 1. The updates are scheduled for a different day and the last fetch was less
23-
% than a week ago.
24+
% 1. The updates are scheduled for a different day and the last fetch was
25+
% less than a week ago.
2426
% 2. The updates are scheduled for today and the last fetch was today.
2527
% 3. The updates are scheduled for every day and the last fetch was less
2628
% than an hour ago.
27-
if (scheduled && weekday(now) ~= scheduled && now - lastFetch < 7) || ...
28-
(scheduled && weekday(now) == scheduled && now - lastFetch < 1) || ...
29-
(~scheduled && now - lastFetch < 1/24)
29+
if ((scheduled && weekday(now)) ~= (scheduled && (now - lastFetch < 7))) || ...
30+
((scheduled && weekday(now)) == (scheduled && (now - lastFetch < 1))) || ...
31+
(~scheduled && (now - lastFetch < 1/24))
3032
return
3133
end
3234
disp('Updating code...')
3335

3436
% Get the path to the Git exe
3537
gitexepath = getOr(dat.paths, 'gitExe');
3638
if isempty(gitexepath)
37-
[~,gitexepath] = system('where git'); % this doesn't always work
39+
[~,gitexepath] = system('where git'); % todo: this doesn't always work
3840
end
3941
gitexepath = ['"', strtrim(gitexepath), '"'];
4042

4143
% Temporarily change directory into Rigbox to git pull
4244
origDir = pwd;
4345
cd(root)
4446

47+
% Create Windows system commands for git stashing, initializing submodules,
48+
% and pulling
4549
cmdstrStash = [gitexepath, ' stash push -m "stash Rigbox working changes before scheduled git update"'];
4650
cmdstrStashSubs = [gitexepath, ' submodule foreach "git stash push"'];
4751
cmdstrInit = [gitexepath, ' submodule update --init'];
@@ -65,4 +69,4 @@ function update(scheduled)
6569
delete(changesPath);
6670
end
6771
cd(origDir)
68-
end
72+
end

0 commit comments

Comments
 (0)