Skip to content

Commit

Permalink
use git checkout as a backup if pygit2 checkout fails
Browse files Browse the repository at this point in the history
Sometimes it does, inexplicably.
libgit2/pygit2#1217

Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill committed Jun 1, 2023
1 parent 9332740 commit f6a52c5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions commitfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ def find_stable_branches(self):
return []

def checkout_spec(self, spec):
self.pyrepo.checkout(spec)
try:
self.pyrepo.checkout(spec)
return True
except pygit2.InvalidSpecError:
# https://github.com/libgit2/pygit2/issues/1217
ret = subprocess.run(["git", "checkout", spec], cwd=self.workdir, capture_output=True)
return ret.returncode == 0


def checkout_branch(self, branch):
branch = self.pyrepo.branches[f"origin/{branch}"]
self.checkout_spec(branch)
return self.checkout_spec(branch)

def is_cve_commit(self, commit, checkdiff=True):
msg = commit.message
Expand Down Expand Up @@ -101,9 +108,7 @@ def patch_modifies_one_file(self, rev, filename):
and - making an assumption that the file is a patch - check
whether it modifies exactly one file.
"""
try:
self.checkout_spec(rev)
except pygit2.InvalidSpecError:
if not self.checkout_spec(rev):
print(f"WARNING: could not checkout {self.source}: {self.name} {rev}!")
return False
try:
Expand Down

0 comments on commit f6a52c5

Please sign in to comment.