Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle dirty local module repos by force checkout of commits and branches if needed #2734

Merged
merged 11 commits into from
Feb 13, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- update ruff to 0.2.0 and add it to pre-commit step ([#2725](https://github.com/nf-core/tools/pull/2725))
- Update codecov/codecov-action digest to e0b68c6 ([#2728](https://github.com/nf-core/tools/pull/2728))
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.2.1 ([#2730](https://github.com/nf-core/tools/pull/2730))
- Force checkout of commits and branches if needed ([#2734](https://github.com/nf-core/tools/pull/2734))

## [v2.12.1 - Aluminium Wolf - Patch](https://github.com/nf-core/tools/releases/tag/2.12.1) - [2024-02-01]

Expand Down
12 changes: 10 additions & 2 deletions nf_core/synced_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ def checkout_branch(self):
"""
Checks out the specified branch of the repository
"""
self.repo.git.checkout(self.branch)
try:
self.repo.git.checkout(self.branch)
except GitCommandError as e:
if "Your local changes to the following files would be overwritten by checkout" in str(e):
log.debug(f"Overwriting local changes in '{self.local_repo_dir}'")
self.repo.git.checkout(self.branch, force=True)

def checkout(self, commit):
"""
Expand All @@ -217,7 +222,10 @@ def checkout(self, commit):
Args:
commit (str): Git SHA of the commit
"""
self.repo.git.checkout(commit)
try:
self.repo.git.checkout(commit)
except GitCommandError:
self.repo.git.checkout(commit, force=True)

def component_exists(self, component_name, component_type, checkout=True, commit=None):
"""
Expand Down
Loading