Skip to content
Snippets Groups Projects
Commit f1ccdf27 authored by Rawel's avatar Rawel
Browse files

In case the commit is not found locally, try fetching from remote

parent 08d2db44
Branches
No related tags found
No related merge requests found
......@@ -43,7 +43,27 @@ class CommitFeatures:
if self.repo.bare:
raise Exception(f'Found bare repository under "{self.repo_path}"!')
self.commit = self.repo.commit(self.commit_sha)
self.commit = self.get_commit_by_sha()
def get_commit_by_sha(self):
if not self.commit_sha:
return None
try:
commit = self.repo.commit(self.commit_sha)
except ValueError:
try:
# Assume orphaned commit, try fetching from origin
self.repo.git.fetch("origin", self.commit_sha)
commit = self.repo.commit(self.commit_sha)
except Exception:
# Does not exist or is not reachable
commit = None
except Exception:
# In case of any error, return None
commit = None
return commit
def save_features_to_json(self, path):
if not os.path.exists(path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment