Skip to content

Commit

Permalink
only check out as much of the repo as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mashehu committed Dec 13, 2023
1 parent 29c87cc commit 4624c64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def setup_local_repo(self, remote, branch, hide_progress=True, in_cache=False):
)
with pbar:
self.repo.remotes.origin.fetch(
progress=RemoteProgressbar(pbar, self.fullname, self.remote_url, "Pulling")
depth=1, progress=RemoteProgressbar(pbar, self.fullname, self.remote_url, "Pulling")
)
ModulesRepo.update_local_repo_status(self.fullname, True)

Expand Down
14 changes: 12 additions & 2 deletions nf_core/synced_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def checkout_branch(self):
"""
# only checkout if we're on a detached head or if we're not already on the branch
if self.repo.head.is_detached or self.repo.active_branch.name != self.branch:
self.repo.git.checkout(self.branch)
self.repo.git.switch(self.branch)

def checkout(self, commit):
"""
Expand Down Expand Up @@ -348,7 +348,17 @@ def sha_exists_on_branch(self, sha):
Verifies that a given commit sha exists on the branch
"""
self.checkout_branch()
return sha in (commit.hexsha for commit in self.repo.iter_commits())

# check if sha exist, if not try shallow fetch until sha
sha_exists = False
try:
self.repo.remotes.origin.fetch(sha, depth=1)
sha_exists = True
except GitCommandError:
log.debug(f"Could not fetch commit {sha} from {self.remote_url}")
sha_exists = False

return sha_exists

def get_commit_info(self, sha):
"""
Expand Down

0 comments on commit 4624c64

Please sign in to comment.