fix: Prevent UnboundLocalError in get_tracked_files on IndexError

This commit is contained in:
Paul Gauthier (aider) 2025-03-31 09:10:29 +13:00
parent a9c9877580
commit 8cd106fc8a

View file

@ -293,13 +293,19 @@ class GitRepo:
else: else:
try: try:
iterator = commit.tree.traverse() iterator = commit.tree.traverse()
blob = None # Initialize blob
while True: while True:
try: try:
blob = next(iterator) blob = next(iterator)
if blob.type == "blob": # blob is a file if blob.type == "blob": # blob is a file
files.add(blob.path) files.add(blob.path)
except IndexError: except IndexError:
self.io.tool_warning(f"GitRepo: read error skipping {blob.path}") # Handle potential index error during tree traversal
# without relying on potentially unassigned 'blob'
self.io.tool_warning(
"GitRepo: Index error encountered while reading git tree object."
" Skipping."
)
continue continue
except StopIteration: except StopIteration:
break break