Commit ba4cf4bb authored by Jan-Gerrit Richter's avatar Jan-Gerrit Richter

added more options and more failsafes to ita_gitHash

parent da0d386c
......@@ -159,8 +159,10 @@ classdef itaSuper < itaMeta
%% Add history line
commitID = ita_git_getMasterCommitHash;
if ~isempty(commitID)
this = ita_metainfo_add_historyline(this,'itaSuperGitVersion',commitID);
end
end
%% Get/set Stuff
......
function commitID = ita_git_getMasterCommitHash
function commitID = ita_git_getMasterCommitHash(varargin)
%ITA_GIT_GETMASTERCOMMITHASH - Get hash of last used master commit
% This function reads the git config and returns the hash of the last
% commit in the master branch
......@@ -8,6 +8,12 @@ function commitID = ita_git_getMasterCommitHash
%
% Syntax:
% commitID = ita_git_getMasterCommitHash()
% commitID = ita_git_getMasterCommitHash('path','.','branch','test')
%
% Options (default):
% 'branch' (master) : the branch of the returned commit id
% 'path' (ita_toolbox_path) : the path of the repository
%
%
% See also:
% itaSuper.init
......@@ -25,12 +31,28 @@ function commitID = ita_git_getMasterCommitHash
% Created: 13-Sep-2017
sArgs.branch = 'master';
sArgs.path = '';
sArgs = ita_parse_arguments(sArgs,varargin);
if isempty(sArgs.path)
repPath = ita_toolbox_path;
else
repPath = sArgs.path;
end
commitID = '';
try
workingDir = pwd;
cd(ita_toolbox_path)
[~,commitID] = system('git merge-base master HEAD');
commitID = strrep(commitID,sprintf('\n'),'');
cd(repPath)
[status,commitID] = system(sprintf('git merge-base %s HEAD',sArgs.branch));
if status == 0
commitID = strrep(commitID,newline,'');
else
ita_verbose_info(sprintf('Git Hash Failed: %s',commitID), 1);
commitID = '';
end
cd(workingDir);
catch e
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment