Refactor getting staged files to handle ValueError.

This commit is contained in:
Paul Gauthier 2023-07-24 13:44:22 -03:00
parent 89542d2139
commit f87ec8c38b

View file

@ -147,19 +147,18 @@ class GitRepo:
try: try:
commit = self.repo.head.commit commit = self.repo.head.commit
except ValueError: except ValueError:
return set() commit = None
files = [] files = []
for blob in commit.tree.traverse(): if commit:
if blob.type == "blob": # blob is a file for blob in commit.tree.traverse():
files.append(blob.path) if blob.type == "blob": # blob is a file
files.append(blob.path)
# Add staged files # Add staged files
index = self.repo.index index = self.repo.index
try: staged_files = [item.a_path for item in index.diff(None)]
staged_files = [item.a_path for item in index.diff("HEAD")] dump(staged_files)
except git.exc.BadName:
staged_files = [item.a_path for item in index.diff(None)]
files.extend(staged_files) files.extend(staged_files)
# convert to appropriate os.sep, since git always normalizes to / # convert to appropriate os.sep, since git always normalizes to /