From 01fc4aab1939db850884804ba96dd816004b11ec Mon Sep 17 00:00:00 2001 From: "r.jaepel" <r.jaepel@fz-juelich.de> Date: Sat, 19 Aug 2023 16:54:12 +0200 Subject: [PATCH] Add check if commit hash is identical on context enter and exit --- cadetrdm/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cadetrdm/utils.py b/cadetrdm/utils.py index 486ddb6..67f5bdb 100644 --- a/cadetrdm/utils.py +++ b/cadetrdm/utils.py @@ -45,6 +45,10 @@ class BaseRepo: def untracked_files(self): return self.git_repo.untracked_files + @property + def current_commit_hash(self): + return str(self.head.commit) + @property def working_dir(self): return self.git_repo.working_dir @@ -280,6 +284,7 @@ class ProjectRepo(BaseRepo): self._output_folder = "output" self._output_repo = ResultsRepo(os.path.join(self.working_dir, self._output_folder)) + self._on_context_enter_commit_hash = None @property def output_repo(self): @@ -434,6 +439,7 @@ class ProjectRepo(BaseRepo): The name of the newly created output branch. """ self.test_for_uncommitted_changes() + self._on_context_enter_commit_hash = self.current_commit_hash output_repo = self.output_repo if output_repo.exist_unstaged_changes: @@ -456,6 +462,8 @@ class ProjectRepo(BaseRepo): Commit message for the output repository commit. """ self.test_for_uncommitted_changes() + if self._on_context_enter_commit_hash != self.current_commit_hash: + raise RuntimeError("Code has changed since starting the context. Don't do that.") print("Completed computations, commiting results") self.output_repo.git.add(".") -- GitLab