diff --git a/SaveTranscriptions.m b/SaveTranscriptions.m index 7efbc0c789beca17f4aea53c65d0e18216db2bcf..9c35e810f2d8b0c654f530a81184220e83847e5b 100644 --- a/SaveTranscriptions.m +++ b/SaveTranscriptions.m @@ -3,7 +3,7 @@ % Prepare work space clc -% checkVersion() +checkVersion() % Check for miscelaneous transcriptions in the work space miscLS = who('-regexp', '^ls(([0-9]*$)|($))'); @@ -128,4 +128,51 @@ for iTrial = 1:nTrials end end +end + +%% Git managment +function checkVersion() + % Check if the current directory is a Git repository + if ~isGitRepository() + error('This is not a Git repository.'); + end + + % Fetch the latest changes from the remote repository + system('git fetch origin'); + + % Get the current branch name + [~, currentBranch] = system('git rev-parse --abbrev-ref HEAD'); + currentBranch = strtrim(currentBranch); + + % Get the local and remote commit hashes + localCommit = getGitCommitHash(); + remoteCommit = getRemoteCommit_hash(currentBranch); + + % Compare the local and remote commits + if strcmp(localCommit, remoteCommit) + disp('Your local branch is up-to-date with the remote branch.'); + else + fprintf(2, 'WARNING: Your local branch is out of date with the remote.\n'); + fprintf(['\tLocal commit: ' localCommit '\n']); + fprintf(['\tRemote commit: ' remoteCommit '\n']); + fprintf('\tPlease run "git pull" to update your local code.\n'); + error('Invalid version.') + end +end + +function isGit = isGitRepository() + % Check if the current directory is a Git repository by checking for the existence of a .git directory + isGit = exist('.git', 'dir') == 7; +end + +function commitHash = getGitCommitHash() + % Get the commit hash of the current branch locally + [~, commitHash] = system('git rev-parse HEAD'); + commitHash = strtrim(commitHash); % Remove any trailing newline or space +end + +function remoteCommit = getRemoteCommit_hash(branch) + % Get the commit hash of the remote branch + [~, remoteCommit] = system(['git rev-parse origin/' branch]); + remoteCommit = strtrim(remoteCommit); % Remove any trailing newline or space end \ No newline at end of file