Commit 28c997e4 authored by jayd1860's avatar jayd1860
Browse files

-- Fix issue in setpaths when attempting to download submodules using the...

-- Fix issue in setpaths when attempting to download submodules using the non-git method. Assumtion that Github creates empty folder as placeholders for submodules when downloading using the "Download ZIP" option is not always true. Sometimes it creates empty folder, somtimes it doesn't. So isemptyFolder doesn't work when folder is not created. Added code to create empty submodule folder placeholder when it is missing.

-- Clean up: remove more obsolete files
parent 7c26f18b
Loading
Loading
Loading
Loading
+0 −19
Original line number Diff line number Diff line
function [changedFilesStr, changedFiles] = GetChangedFilesStr(strs)
changedFilesStr = '';
changedFiles = {};
for ii = 1:length(strs)
    s = str2cell_startup(strs{ii}, ':');
    if strcmp(s{1}, 'untracked')
        continue;
    end
    if strcmp(s{1}, 'deleted')
        continue;
    end
    changedFiles{ii,1} = deblank(strtrim(s{2}));
    if isempty(changedFilesStr)
        changedFilesStr = changedFiles{ii,1};
    else
        changedFilesStr = sprintf('%s %s', changedFilesStr, changedFiles{ii,1});
    end
end

Utils/submodules/gitPush.m

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
function [cmds, errs, msgs] = gitPush(repo, preview)
cmds = {};
errs = [];
msgs = {};

if ~exist('submodule','var')
    return;
end
if ~exist('revid','var')
    return;
end
if ~exist('repo','var') || isempty(repo)
    repo = [pwd, '/'];
end
if ~exist('preview','var')
    preview = false;
end

currdir = pwd;
repoFull = filesepStandard_startup(repo,'full');

ii = 1;

cmds{ii,1} = sprintf('git push'); ii = ii+1;

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

cd(currdir)

Utils/submodules/gitRepoInit.m

deleted100644 → 0
+0 −82
Original line number Diff line number Diff line
function [cmds, errs, msgs] = gitRepoInit(repoLocal, url)
cmds = {};
errs = [];
msgs = {};

[~, repoName] = fileparts(repoLocal);

if isempty(repoLocal)
    repoLocal = pwd;
end
if isempty(url)
    url = '';
end
repoLocal = filesepStandard(repoLocal);
currdir = pwd;

cd(repoLocal)

if ispathvalid('./.git')
    rmdir('./.git','s')
end
if ispathvalid('./temp')
    rmdir('./temp','s')
end

%%%% 1. Check to make sure remote repo exists and is empty
mkdir('./temp')
cd('./temp');
cmd = sprintf('git clone %s', url);
[e, m] = system(cmd); %#ok<ASGLU>

% Does repo exist?
if ~ispathvalid(['./', repoName, '/.git'])
    cd(repoLocal);
    errs = -1;
    return;
end

% Is repo empty? That is if it contains any other file or folder 
% other than .git then we exit
if ~isRepoEmpty(['./', repoName])
    cd(repoLocal);
    errs = -1;
end

cd(repoLocal);
rmdir('./temp','s')

%%%% 2. Initialize empty repo with code 
ii = 1;
cmds{ii,1} = sprintf('git init'); ii = ii+1;
cmds{ii,1} = sprintf('git add .'); ii = ii+1;
cmds{ii,1} = sprintf('git commit -m "First commit for standalone code"'); ii = ii+1;
cmds{ii,1} = sprintf('git remote add origin %s', url); ii = ii+1;
cmds{ii,1} = sprintf('git push --set-upstream origin master'); ii = ii+1;
cmds{ii,1} = sprintf('git checkout -b development'); ii = ii+1;
cmds{ii,1} = sprintf('git push --set-upstream origin development'); ii = ii+1;
[errs, msgs] = exeShellCmds(cmds);




% ------------------------------------------------------------
function b = isRepoEmpty(repoName)
b = false;
dirs = dir([repoName, '/*']);
nfiles = 0;
for ii = 1:length(dirs)
    if strcmp(dirs(ii).name, '.')
        continue
    end
    if strcmp(dirs(ii).name, '..')
        continue
    end
    nfiles = nfiles+1;
end
if nfiles>1
    return;
end
b = true;

Utils/submodules/gitStatus.m

deleted100644 → 0
+0 −81
Original line number Diff line number Diff line
function [modified, added, deleted, untracked, cmds, errs, msgs] = gitStatus(repo)
modified = {};
added = {};
deleted = {};
untracked = {};
cmds = {};
errs = -1;
msgs = {};

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

currdir = pwd;

repoFull = filesepStandard_startup(repo,'full');

ii = 1;
kk = 1;
cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('git status'); ii = ii+1; kk = ii-1;

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

kk1 = 1;
kk2 = 1;
kk3 = 1;
kk4 = 1;
lines = str2cell_startup(msgs{kk}, sprintf('\n'))';
untrackedFlag = false;
for jj = 1:length(lines)
    if ~isempty(strfind(lines{jj}, 'nothing to commit'))
        break
    end
    if ~isempty(strfind(lines{jj}, 'modified:'))
        k = strfind(lines{jj}, '(modified content)');
        if ~isempty(k)
            lines{jj} = sprintf('%s (submodule)', lines{jj}(1:k-1));
        end
        modified{kk1,1} = strtrim(deblank(lines{jj}));
        kk1 = kk1+1;
    end
    if ~isempty(strfind(lines{jj}, 'new file:'))
        k = strfind(lines{jj}, 'new file:');
        l = length('new file:');
        lines{jj} = sprintf('added: %s', lines{jj}(k+l:end));
        added{kk2,1} = strtrim(deblank(lines{jj}));
        kk2 = kk2+1;
    end
    if ~isempty(strfind(lines{jj}, 'deleted:'))
        deleted{kk3,1} = strtrim(deblank(lines{jj}));
        kk3 = kk3+1;
    end
    if ~isempty(strfind(lines{jj}, 'Untracked files:'))
        untrackedFlag = true;
        continue;
    end
    if ~isempty(strfind(lines{jj}, '(use "git add <file>..." to include in what will be committed)'))
        untrackedFlag = true;
        continue;
    end
    if untrackedFlag==true
        untrackedFlag = false;
        while 1
            if jj+kk4-1 > length(lines)
                break;
            end
            filename = strtrim(deblank(lines{jj+kk4-1}));
            if ~ispathvalid_startup(filename)
                break
            end
            untracked{kk4,1} = sprintf('untracked:  %s', filename);
            kk4 = kk4+1;
        end
    end

end

cmds{ii,1} = sprintf('cd %s', currdir); ii = ii+1;

cd(currdir)
 No newline at end of file
+0 −66
Original line number Diff line number Diff line
function [cmds, errs, msgs] = gitSubmoduleCommit(submodule, repo, changedFiles, preview)
cmds = {};
errs = [];
msgs = {};

if ~exist('submodule','var')
    return;
end
if ~exist('repo','var') || isempty(repo)
    repo = [pwd, '/'];
end
if ~exist('changedFiles','var') || isempty(changedFiles)
    changedFiles = '.';
end
if ~exist('preview','var')
    preview = false;
end

currdir = pwd;

repoFull = filesepStandard_startup(repo,'full');

ii = 1;

%%%% Commit submodule
[modified, added, deleted, untracked] = gitStatus([repo, submodule]);
changedFilesStr = getChangedFilesStr([modified; added; deleted; untracked]);
if isempty(changedFilesStr)
    cmds = {};
    cd(currdir)
    return;
end
cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('cd %s', submodule); ii = ii+1;
cmds{ii,1} = sprintf('git add %s', changedFilesStr); ii = ii+1;
commit = CommitGUI([repoFull, submodule], 'userargs');
if isempty(commit.changedFiles)
    msgs = {'cancelled'};
    cd(currdir)
    return;
end
cmds{ii,1} = sprintf('git commit -m "%s"', commit.comment); ii = ii+1;


%%%% Commit parent repo
[modified, added, deleted, untracked] = gitStatus(repo);
changedFilesStr = getChangedFilesStr([modified; added; deleted; untracked]);
if isempty(changedFilesStr)
    cmds = {};
    cd(currdir)
    return;
end
cmds{ii,1} = sprintf('cd %s', repoFull); ii = ii+1;
cmds{ii,1} = sprintf('git add %s', submodule); ii = ii+1;
commit = CommitGUI(repoFull, submodule, 'userargs');
if isempty(commit.changedFiles)
    msgs = {'cancelled'};
    cd(currdir)
    return;
end
cmds{ii,1} = sprintf('git commit -m "%s"', commit.comment); ii = ii+1;

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

cd(currdir)
Loading