diff --git a/cadetrdm/utils.py b/cadetrdm/utils.py index 4b43027e3ff69df5f359c5ca0247eb92c91c2b3c..486ddb600953246deb0fab40861680fcbf4cfbf4 100644 --- a/cadetrdm/utils.py +++ b/cadetrdm/utils.py @@ -64,6 +64,20 @@ class BaseRepo: self._earliest_commit = earliest_commit return self._earliest_commit + def add_remote(self, remote_url, remote_name="origin"): + self.git_repo.create_remote(remote_name, url=remote_url) + + def push(self, remote=None, local_branch=None, remote_branch=None): + if local_branch is None: + local_branch = self.active_branch + if remote_branch is None: + remote_branch = local_branch + if remote is None: + remote = list(sorted(self.git_repo.remotes.keys()))[0] + + remote_interface = self.git_repo.remotes[remote] + remote_interface.push(refspec=f'{local_branch}:{remote_branch}') + def delete_active_branch_if_branch_is_empty(self): """ Delete the currently active branch and checkout the master branch @@ -317,7 +331,7 @@ class ProjectRepo(BaseRepo): "Output repo commit hash": output_repo_hash, "Project repo commit hash": str(self.head.commit), "Project repo folder name": os.path.split(self.working_dir)[-1], - "Project repo remotes": self.remotes, + "Project repo remotes": [str(remote.url) for remote in self.remotes], } csv_header = ",".join(meta_info_dict.keys()) csv_data = ",".join([str(x) for x in meta_info_dict.values()]) @@ -471,4 +485,3 @@ class ProjectRepo(BaseRepo): class ResultsRepo(BaseRepo): pass - diff --git a/tests/test_git_adapter.py b/tests/test_git_adapter.py index a00e171a405bdca6453ef6370565f83e31b316a5..bb47faaa5d1a9cc4cc225c0d954361109a450b38 100644 --- a/tests/test_git_adapter.py +++ b/tests/test_git_adapter.py @@ -128,10 +128,17 @@ def try_load_previous_result(path_to_repo, branch_name): assert os.path.exists(extended_array_file_path) +def try_add_remote(path_to_repo): + repo = ProjectRepo(path_to_repo) + repo.add_remote("git@jugit.fz-juelich.de:IBG-1/ModSim/cadet/CADET-RDM.git") + assert "origin" in repo.git_repo.remotes + + def test_cadet_rdm(path_to_repo): # because these depend on one-another and there is no native support afaik for sequential tests # these tests are called sequentially here as try_ functions. try_initialize_git_repo(path_to_repo) + try_add_remote(path_to_repo) try_commit_code(path_to_repo) try_commit_code_without_code_changes(path_to_repo) results_branch_name = try_commit_results_data(path_to_repo)