Commit 24c6af81 authored by jayd1860's avatar jayd1860
Browse files

-- Fix problems in setpaths with creating new submodule branches

-- Fix issue in setpaths with non-git submodule download and install.
   a) Fix some bugs and typos preventing correct download.
   b) Clean up and delete downloaded submodules files which are no longer needed after installation like the zip file and initial unzipped folder
   c) Clarify input dialog message and try to guess and or suggest the correct branch that matches parent repo

-- Add exception handling to setpaths. in case of error return to original folder

-- Add comprehensive help comments to setpaths describing it's use
parent a9632431
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
function [cmds, errs, msgs] = downloadSharedLibs(options)
function [cmds, errs, msgs] = downloadSharedLibs(options, appname)
cmds = {};
errs = 0;
msgs = {};
@@ -15,10 +15,10 @@ if isempty(kk) && optionExists_startup(options, 'init')
    return;
end

if optionExists_startup(options, 'init')
    [cmds, errs, msgs] = gitSubmodulesInit();
elseif optionExists_startup(options, 'update')
    [cmds, errs, msgs] = gitSubmodulesUpdate();
if optionExists_startup(options, 'update')
    [cmds, errs, msgs] = gitSubmodulesUpdate(pwd, options);
else
    [cmds, errs, msgs] = gitSubmodulesInit(pwd, options);
end

% Check again for missing libs
@@ -28,7 +28,7 @@ if isempty(kk) && (optionExists_startup(options, 'init') || all(errs==0))
end

% Try to install missing libs without git
branch = warningGitFailedToInstall(s(kk,:));
branch = warningGitFailedToInstall(s(kk,:), appname);
if ~isempty(branch)
    if optionExists_startup(options, 'init')
        downloadSubmodulesWithoutGit(s(kk,:), branch);
@@ -70,7 +70,7 @@ end


% ----------------------------------------------------------
function branch = warningGitFailedToInstall(s)
function branch = warningGitFailedToInstall(s, appname)
ii = 1;
msg{ii} = sprintf('WARNING: Git failed to install the following libraries required by this application:\n\n'); ii = ii+1;
for jj = 1:size(s,1)
@@ -78,11 +78,13 @@ for jj = 1:size(s,1)
end
msg{ii} = sprintf('\n'); ii = ii+1; %#ok<SPRINTFN>
msg{ii} = sprintf('Git might not be installed on your computer. '); ii = ii+1;
msg{ii} = sprintf('These libraries can still be installed without git. Please provide a branch name (default: ''development'') '); ii = ii+1;
msg{ii} = sprintf('of the submodles branches to download that matches the branch of the parent repo (this application).');
msg{ii} = sprintf('These libraries can still be installed without git. The assumed submodule branch that matches '); ii = ii+1;
msg{ii} = sprintf('the branch of the parent repo, ''%s'', is ''%s'' (see edit box below). Please edit it ', appname, guessBranch(appname)); ii = ii+1;
msg{ii} = sprintf('if this assumption is not correct.\n\n');  ii = ii+1;
msg{ii} = sprintf('Submodule source branch name:');  ii = ii+1;
msg = [msg{:}];

branch = inputdlg(msg, 'MISSING LIBRARIES', 1);
branch = inputdlg(msg, 'MISSING LIBRARIES', 1,{guessBranch(appname)});
if ~isempty(branch)
    branch = branch{1};
end
@@ -134,3 +136,18 @@ if isunix() || ismac()
end




% ----------------------------------------------------
function branchGuess = guessBranch(appname)
branchGuess = 'development';
[~, rootdir] = fileparts(fileparts(which([appname, '.m'])));
k = strfind(rootdir, appname);
if (k+length(appname)) <= length(rootdir)
    j = 0;
    if rootdir(k+length(appname))=='-'
        j = 1;
    end
    branchGuess = rootdir(k+length(appname)+j:end);
end
+14 −0
Original line number Diff line number Diff line
@@ -58,3 +58,17 @@ if ispathvalid_startup(filenameDownload)
    fprintf('Copying %s/*  to  %s\n', filenameDownload, submodulepath);
    copyFolderContents(filenameDownload, submodulepath);
end
if ispathvalid_startup([filenameDownload, '.zip'])
    fprintf('Removing %s\n', [filenameDownload, '.zip']);
    try
        delete([filenameDownload, '.zip']);        
    catch
    end
end
if ispathvalid_startup(filenameDownload)
    fprintf('Removing %s\n', filenameDownload);
    try
        rmdir(filenameDownload, 's');
    catch
    end
end
+29 −0
Original line number Diff line number Diff line
function [b, cmds, errs, msgs] = gitBranchExists(repo, branch)
b = false;
cmds = {};

currdir = pwd;

if ~exist('repo','var') || isempty(repo)
    repo = [pwd, '/'];
end

repoFull = filesepStandard_startup(repo,'full');
ii = 1;

cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('git branch --list'); ii = ii+1; %#ok<NASGU>

[errs, msgs] = exeShellCmds(cmds, false, true);

if length(msgs) == ii-1
    c = str2cell_startup(msgs{ii-1}, {char(32), char(10), char(13)}); %#ok<CHARTEN>
    for ii = 1:length(c)
        if strcmp(branch, c{ii})
            b = true;
            break;
        end
    end
end
cd(currdir);
+55 −7
Original line number Diff line number Diff line
function [cmds, errs, msgs] = gitSubmodulesInit(repo, preview)
function [cmds, errs, msgs] = gitSubmodulesInit(repo, options, preview)
cmds = {};

currdir = pwd;
@@ -6,6 +6,9 @@ currdir = pwd;
if ~exist('repo','var') || isempty(repo)
    repo = [pwd, '/'];
end
if ~exist('options','var')
    options = 'init';
end
if ~exist('preview','var')
    preview = false;
end
@@ -14,21 +17,66 @@ repoFull = filesepStandard_startup(repo,'full');
ii = 1;

cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('git config --global http.sslverify "false"');
cmds{ii,1} = sprintf('git submodule update --init'); ii = ii+1;
cmds{ii,1} = sprintf('git config --global http.sslverify "false"'); ii = ii+1;
cmds{ii,1} = sprintf('git submodule update --init'); ii = ii+1; %#ok<NASGU>

[errs, msgs] = exeShellCmds(cmds, preview);

submodules = parseGitSubmodulesFile(repo);

% Set origin for submodules to be same as origin for parent repo
url = gitGetOrigin(repoFull);
urlroot = fileparts(url);
branch = gitGetBranch(repo);

submodules = parseGitSubmodulesFile(repo);
for ii = 1:size(submodules,1)
    [~, submodulename] = fileparts(submodules{ii,1});
    gitSetBranch([repoFull, submodules{ii,3}], branch);
    gitSetOrigin([repoFull, submodules{ii,3}], [urlroot, '/', submodulename]);
end

% Checkout branch for parent repo and submodules. First checkout the source
% branch then destination. Source branch is the branch from which the
% destination branch is derived if destination branch is a new branch. 
[branchSrc, branchDst] = gitGetSrcDstBranches(repoFull, options);
if isempty(branchSrc) || isempty(branchDst)
    return
end
for ii = 1:size(submodules,1)
    gitSetBranch([repoFull, submodules{ii,3}], branchSrc);
end
for ii = 1:size(submodules,1)
    gitSetBranch([repoFull, submodules{ii,3}], branchDst);
end
gitSetBranch(repoFull, branchSrc);
gitSetBranch(repoFull, branchDst);

cd(currdir);




% ----------------------------------------------------------------
function [branchSrc, branchDst] = gitGetSrcDstBranches(repo, options)
branchSrc = '';
branchDst = '';
c = str2cell_startup(options, {':',','});
for ii = 1:length(c)
    c{ii} = strtrim(deblank(c{ii}));
end
if optionExists_startup(c, 'branch')
    if length(c)==2        
        branchSrc = gitGetBranch(repo);
        branchDst = c{2};
    elseif length(c)==3
        if ~gitBranchExists(repo, c{2})
            h = msgbox(sprintf('ERROR: source branch ''%s'' does not exist in this repo. Source branch must exist to create the destination branch (''%s'')\n', ...
                c{2}, c{3}));
            waitForGui_startup(h);
            return
        end
        branchSrc = c{2};
        branchDst = c{3};
    end
else
    branchSrc = gitGetBranch(repo);
    branchDst = branchSrc;
end
+5 −1
Original line number Diff line number Diff line
function [cmds, errs, msgs] = gitSubmodulesUpdate(repo, preview)
function [cmds, errs, msgs] = gitSubmodulesUpdate(repo, options, preview)
cmds = {};


currdir = pwd;

if ~exist('repo','var') || isempty(repo)
    repo = [pwd, '/'];
end
if ~exist('options','var')
    options = 'init';
end
if ~exist('preview','var')
    preview = false;
end
Loading