diff --git a/cadetrdm/cli_integration.py b/cadetrdm/cli_integration.py index edf9105..58be2df 100644 --- a/cadetrdm/cli_integration.py +++ b/cadetrdm/cli_integration.py @@ -89,6 +89,17 @@ def commit(message, all): repo.commit(message, all) del repo +@cli.command(help="Stage changes") +@click.option("--filepath", "-f", help="Stage changes at filepath") +def add(filepath): + if not filepath: + raise click.UsageError( + "You must specify --filepath/-f" + ) + from cadetrdm.repositories import ProjectRepo + repo = ProjectRepo(".") + repo.add(filepath) + del repo @cli.group(help="Execute commands and track the results.") def run(): diff --git a/cadetrdm/initialize_repo.py b/cadetrdm/initialize_repo.py index 683c26f..da4c9e9 100644 --- a/cadetrdm/initialize_repo.py +++ b/cadetrdm/initialize_repo.py @@ -224,6 +224,7 @@ def initialize_output_repo(output_directory_name, gitignore: list = None, create_output_readme() repo = OutputRepo(".") + repo.add_all_files() repo.commit("initial commit") os.chdir(starting_directory) diff --git a/cadetrdm/repositories.py b/cadetrdm/repositories.py index 99eb310..4951a4e 100644 --- a/cadetrdm/repositories.py +++ b/cadetrdm/repositories.py @@ -291,7 +291,7 @@ def remote_set_url(self, name: str, url: str): def commit( self, message: str | None = None, - add_all=True, + add_all=False, verbosity=1, ) -> None: """ @@ -584,7 +584,7 @@ def add_remote(self, remote_url, remote_name=None): output_repo.checkout(output_repo.main_branch) output_repo.add_list_of_remotes_in_readme_file("Link to Project Repository", self.remote_urls) output_repo.add("README.md") - output_repo.commit("Add remote for project repo", verbosity=0, add_all=False) + output_repo.commit("Add remote for project repo", verbosity=0) if self.metadata["is_output_repo"]: # This directory is an output repository. project_repo = ProjectRepo(self.path.parent) @@ -592,7 +592,7 @@ def add_remote(self, remote_url, remote_name=None): project_repo.add_list_of_remotes_in_readme_file("Link to Output Repository", self.remote_urls) project_repo.add(project_repo.data_json_path) project_repo.add("README.md") - project_repo.commit("Add remote for output repo", verbosity=0, add_all=False) + project_repo.commit("Add remote for output repo", verbosity=0) def import_remote_repo(self, source_repo_location, source_repo_branch, target_repo_location=None): """ @@ -1167,13 +1167,13 @@ def check(self, commit=True): """ self.update_output_remotes_json() if commit: - super().commit(message="Update remote links", add_all=False, verbosity=1) + super().commit(message="Update remote links", verbosity=1) # update urls in main branch of output_repo self.output_repo._git.checkout(self.output_repo.main_branch) self.output_repo.add_list_of_remotes_in_readme_file("Link to Project Repository", self.remote_urls) if commit: - self.output_repo.commit(message="Update remote links", add_all=False, verbosity=1) + self.output_repo.commit(message="Update remote links", verbosity=1) def update_output_remotes_json(self, load_metadata=True): output_repo_remotes = self.output_repo.remote_urls @@ -1714,7 +1714,7 @@ def _convert_csv_to_tsv_if_necessary(self) -> None: ) self.add(self.path / "log.csv") self.add(self.path / "log.tsv") - self.commit("Convert csv to tsv", add_all=False) + self.commit("Convert csv to tsv") def _expand_tsv_header(self): """Update tsv header.""" @@ -1740,7 +1740,7 @@ def _expand_tsv_header(self): f.writelines(lines[1:]) self.add(self.output_log_file_path) - self.commit("Update tsv header", add_all=False) + self.commit("Update tsv header") def _update_headers(self): """Update tsv header.""" @@ -1766,7 +1766,7 @@ def _update_headers(self): f.writelines(lines[1:]) self.add(self.output_log_file_path) - self.commit("Update tsv header", add_all=False) + self.commit("Update tsv header") def _fix_gitattributes_log_tsv(self): """Update .gitattributes to account for changed logfile name.""" @@ -1778,7 +1778,7 @@ def _fix_gitattributes_log_tsv(self): handle.writelines(lines) self.add(".gitattributes") - self.commit("Update .gitattributes", add_all=False) + self.commit("Update .gitattributes") def _update_log_hashes(self): if self.has_uncomitted_changes: @@ -1803,7 +1803,7 @@ def _update_log_hashes(self): log.write() self.add(self.output_log_file_path) - self.commit(message="Updated log hashes", add_all=False) + self.commit(message="Updated log hashes") def _rename_project_repo_folder_to_directory_in_log(self) -> None: """Rename the TSV column header from folder to directory.""" @@ -1892,7 +1892,7 @@ def _add_branch_name_to_log(self) -> None: class JupyterInterfaceRepo(ProjectRepo): - def commit(self, message: str | None = None, add_all=True, verbosity=1): + def commit(self, message: str | None = None, add_all=False, verbosity=1): """ Commit current state of the repository. diff --git a/docs/source/user_guide/command-line-interface.md b/docs/source/user_guide/command-line-interface.md index 1b645ee..b0a5b4d 100644 --- a/docs/source/user_guide/command-line-interface.md +++ b/docs/source/user_guide/command-line-interface.md @@ -52,16 +52,22 @@ The command must be enclosed in quotes. ### Staging, committing, and pushing changes -Check repository consistency and stage changes: +Check repository consistency: ```bash rdm check ``` -Commit staged changes: +Stage changes: ```bash -rdm commit -m +rdm add -f +``` + +Commit staged changes (option: setting `-a` will stage all changes and commit them): + +```bash +rdm commit -m [-a] ``` Push both project and output repositories: diff --git a/docs/source/user_guide/python-interface.md b/docs/source/user_guide/python-interface.md index f3e47ee..9526fed 100644 --- a/docs/source/user_guide/python-interface.md +++ b/docs/source/user_guide/python-interface.md @@ -45,8 +45,12 @@ Results are tracked using the `ProjectRepo` interface. All files written inside from cadetrdm import ProjectRepo repo = ProjectRepo() +repo.add(path_to_changed_file) repo.commit("Commit code changes") +``` +Optionally, the argument `add_all=True` can be given to `repo.commit()` to stage all changed files and commit them instead of using the preceding `repo.add()`. +```python with repo.track_results(results_commit_message="Generate results"): data = generate_data() write_data_to_file(data, output_directory=repo.output_directory)