Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cadetrdm/cli_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions cadetrdm/initialize_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions cadetrdm/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -584,15 +584,15 @@ 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)
project_repo.update_output_remotes_json()
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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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:
Expand All @@ -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."""
Expand Down Expand Up @@ -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.

Expand Down
12 changes: 9 additions & 3 deletions docs/source/user_guide/command-line-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <message>
rdm add -f <filepath>
```

Commit staged changes (option: setting `-a` will stage all changes and commit them):

```bash
rdm commit -m <message> [-a]
```

Push both project and output repositories:
Expand Down
4 changes: 4 additions & 0 deletions docs/source/user_guide/python-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down