diff --git a/cadetrdm/initialize_repo.py b/cadetrdm/initialize_repo.py index 5001730b9c4e5a23d1abe12374fdea3fcea5367a..c3eb722ae7d007875659efc85dc4e292a7bc35f4 100644 --- a/cadetrdm/initialize_repo.py +++ b/cadetrdm/initialize_repo.py @@ -182,6 +182,8 @@ def clone(project_url, path_to_repo: str = None): output_folder_name = os.path.join(path_to_repo, meta_dict["output_folder_name"]) ssh_remotes = list(meta_dict["output_remotes"].values()) http_remotes = [ssh_url_to_http_url(url) for url in ssh_remotes] + if len(ssh_remotes + http_remotes) == 0: + raise RuntimeError("No output remotes configured in output_remotes.json") for output_remote in ssh_remotes + http_remotes: try: print(f"Attempting to clone {output_remote} into {output_folder_name}") diff --git a/cadetrdm/repositories.py b/cadetrdm/repositories.py index de34d09dd5c3009e144add784f23937215c7e0fe..ab4c0e9daab4a4812735840c6bb2f5e817513cc5 100644 --- a/cadetrdm/repositories.py +++ b/cadetrdm/repositories.py @@ -115,6 +115,13 @@ class BaseRepo: :return: """ self._git_repo.create_remote(remote_name, url=remote_url) + with open(self.data_json_path, "r") as handle: + rdm_data = json.load(handle) + if rdm_data["is_project_repo"]: + pass + if rdm_data["is_output_repo"]: + project_repo = ProjectRepo(os.path.split(self.working_dir)[0]) + project_repo.update_output_remotes_json() def import_remote_repo(self, source_repo_location, source_repo_branch, target_repo_location=None): """ @@ -726,17 +733,19 @@ class ProjectRepo(BaseRepo): Option to add all changed and new files to git automatically. """ + self.update_output_remotes_json() + + super().commit(message=message, add_all=add_all) + + def update_output_remotes_json(self): output_repo_remotes = self.output_repo.remote_urls self.add_list_of_remotes_in_readme_file("output_repo", output_repo_remotes) - output_json_filepath = os.path.join(self.working_dir, "output_remotes.json") with open(output_json_filepath, "w") as file_handle: remotes_dict = {remote.name: str(remote.url) for remote in self.output_repo.remotes} json_dict = {"output_folder_name": self.output_folder, "output_remotes": remotes_dict} json.dump(json_dict, file_handle, indent=2) - super().commit(message=message, add_all=add_all) - def download_file(self, url, file_path): """ Download the file from the url and put it in the output+file_path location.