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

added more options and more failsafes to ita_gitHash

parent da0d386c
...@@ -159,7 +159,9 @@ classdef itaSuper < itaMeta ...@@ -159,7 +159,9 @@ classdef itaSuper < itaMeta
%% Add history line %% Add history line
commitID = ita_git_getMasterCommitHash; commitID = ita_git_getMasterCommitHash;
this = ita_metainfo_add_historyline(this,'itaSuperGitVersion',commitID); if ~isempty(commitID)
this = ita_metainfo_add_historyline(this,'itaSuperGitVersion',commitID);
end
end end
......
function commitID = ita_git_getMasterCommitHash function commitID = ita_git_getMasterCommitHash(varargin)
%ITA_GIT_GETMASTERCOMMITHASH - Get hash of last used master commit %ITA_GIT_GETMASTERCOMMITHASH - Get hash of last used master commit
% This function reads the git config and returns the hash of the last % This function reads the git config and returns the hash of the last
% commit in the master branch % commit in the master branch
...@@ -8,6 +8,12 @@ function commitID = ita_git_getMasterCommitHash ...@@ -8,6 +8,12 @@ function commitID = ita_git_getMasterCommitHash
% %
% Syntax: % Syntax:
% commitID = ita_git_getMasterCommitHash() % 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: % See also:
% itaSuper.init % itaSuper.init
...@@ -25,12 +31,28 @@ function commitID = ita_git_getMasterCommitHash ...@@ -25,12 +31,28 @@ function commitID = ita_git_getMasterCommitHash
% Created: 13-Sep-2017 % 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 = ''; commitID = '';
try try
workingDir = pwd; workingDir = pwd;
cd(ita_toolbox_path) cd(repPath)
[~,commitID] = system('git merge-base master HEAD'); [status,commitID] = system(sprintf('git merge-base %s HEAD',sArgs.branch));
commitID = strrep(commitID,sprintf('\n'),''); if status == 0
commitID = strrep(commitID,newline,'');
else
ita_verbose_info(sprintf('Git Hash Failed: %s',commitID), 1);
commitID = '';
end
cd(workingDir); cd(workingDir);
catch e 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