Scan the git index using entries, which does not rely on a prior commit

This commit is contained in:
Paul Gauthier 2023-07-24 14:00:35 -03:00
parent 96f15c4533
commit 745b3c320b

View file

@ -1007,16 +1007,18 @@ class Coder:
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
staged_files = [item.a_path for item in index.diff("HEAD")] staged_files = [path for path, _ in index.entries.keys()]
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 /