11function update(scheduled )
22% GIT.UPDATE Pull latest Rigbox code
33% 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, the
5- % function will only continue on that day, or if the last fetch was over
6- % a week ago.
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.
10+ %
711% TODO Find quicker way to check for changes
8- % See also
12+ % See also DAT.PATHS
913if nargin < 1 ; scheduled = getOr(dat .paths , ' updateSchedule' , 0 ); end
1014
1115root = fileparts(which(' addRigboxPaths' ));
1216% Attempt to find date of last fetch
1317fetch_head = fullfile(root , ' .git' , ' FETCH_HEAD' );
1418lastFetch = iff(exist(fetch_head ,' file' )==2 , ... % If FETCH_HEAD file exists
1519 @()getOr(dir(fetch_head ), ' datenum' ), 0 ); % Retrieve date modified
16- % If the code has not been fetched in over a week, force and update,
17- % otherwise return
20+
21+ % 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+ % 2. The updates are scheduled for today and the last fetch was today.
25+ % 3. The updates are scheduled for every day and the last fetch was less
26+ % than an hour ago.
1827if (scheduled && weekday(now ) ~= scheduled && now - lastFetch < 7 ) || ...
28+ (scheduled && weekday(now ) == scheduled && now - lastFetch < 1 ) || ...
1929 (~scheduled && now - lastFetch < 1 / 24 )
2030 return
2131end
@@ -39,10 +49,10 @@ function update(scheduled)
3949
4050% Stash any WIP, check submodules are initialized, pull
4151try
42- [status , cmdout ] = system(cmdstrStash , ' -echo' );
43- [status , cmdout ] = system(cmdstrStashSubs , ' -echo' );
44- [status , cmdout ] = system(cmdstrInit , ' -echo' );
45- [status , cmdout ] = system(cmdstrPull , ' -echo' );
52+ [~ , cmdout ] = system(cmdstrStash , ' -echo' );
53+ [~ , cmdout ] = system(cmdstrStashSubs , ' -echo' );
54+ [~ , cmdout ] = system(cmdstrInit , ' -echo' );
55+ [~ , cmdout ] = system(cmdstrPull , ' -echo' ); % #ok<ASGLU>
4656catch ex
4757 cd(origDir )
4858 error(' gitUpdate:pull:pullFailed' , ' Failed to pull latest changes:, %s ' , cmdout )
@@ -55,4 +65,4 @@ function update(scheduled)
5565 delete(changesPath );
5666end
5767cd(origDir )
58- end
68+ end
0 commit comments