From db86113fbb4bba869e45b97980aeb6269fb2290e Mon Sep 17 00:00:00 2001
From: Chirsophe <cbsmith2@uab.edu>
Date: Wed, 2 Apr 2025 10:50:20 -0500
Subject: [PATCH] Added Git version check

---
 SaveTranscriptions.m | 53 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/SaveTranscriptions.m b/SaveTranscriptions.m
index 8ab8108..47f5271 100644
--- a/SaveTranscriptions.m
+++ b/SaveTranscriptions.m
@@ -2,6 +2,8 @@
 % Prepare work space
 clc
 
+checkVersion()
+
 % Check for miscelaneous transcriptions in the work space
 miscLS = who('-regexp', '^ls.*[0-9]');
 newLS = CheckmiscLS(miscLS);
@@ -108,11 +110,48 @@ end
 
 end
 
-%% For testing
-% load('C:\Users\chris\Box\Nelson Lab Data\Other Data\NTAud Transcription\Transcript_OrigAudio_AudSentStim.mat', 'lss');
-% test = load('C:\Users\chris\Box\Nelson Lab Data\Other Data\NTAud Transcription\Transcript_Version2_AudSent.mat');
-% ls = test.lss;
+%% 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
+        disp('WARNING: Your local branch is out of date with the remote.');
+        disp(['Local commit: ' localCommit]);
+        disp(['Remote commit: ' remoteCommit]);
+        disp('Please run "git pull" to update your local code.');
+    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
 
-% testpos = 6;
-% resetLabelValues(lss, testpos)
-% setLabelValue(lss, testpos, 'Words', ls.Labels.Words{testpos}.ROILimits, ls.Labels.Words{testpos}.Value)
+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
-- 
GitLab