11function 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
1719fetch_head = fullfile(root , ' .git' , ' FETCH_HEAD' );
1820lastFetch = 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
3133end
3234disp(' Updating code...' )
3335
3436% Get the path to the Git exe
3537gitexepath = getOr(dat .paths , ' gitExe' );
3638if isempty(gitexepath )
37- [~ ,gitexepath ] = system(' where git' ); % this doesn't always work
39+ [~ ,gitexepath ] = system(' where git' ); % todo: this doesn't always work
3840end
3941gitexepath = [' "' , strtrim(gitexepath ), ' "' ];
4042
4143% Temporarily change directory into Rigbox to git pull
4244origDir = pwd ;
4345cd(root )
4446
47+ % Create Windows system commands for git stashing, initializing submodules,
48+ % and pulling
4549cmdstrStash = [gitexepath , ' stash push -m "stash Rigbox working changes before scheduled git update"' ];
4650cmdstrStashSubs = [gitexepath , ' submodule foreach "git stash push"' ];
4751cmdstrInit = [gitexepath , ' submodule update --init' ];
@@ -65,4 +69,4 @@ function update(scheduled)
6569 delete(changesPath );
6670end
6771cd(origDir )
68- end
72+ end
0 commit comments