mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
refactor: simplify error handling in get_tracked_files method
This commit is contained in:
parent
387df7f1db
commit
c8b2024f8b
2 changed files with 21 additions and 29 deletions
|
@ -10,11 +10,6 @@ from aider.sendchat import simple_send_with_retries
|
|||
|
||||
from .dump import dump # noqa: F401
|
||||
|
||||
|
||||
class UnableToCountRepoFiles(Exception):
|
||||
pass
|
||||
|
||||
|
||||
ANY_GIT_ERROR = (git.exc.ODBError, git.exc.GitError)
|
||||
|
||||
|
||||
|
@ -259,32 +254,29 @@ class GitRepo:
|
|||
return []
|
||||
|
||||
try:
|
||||
try:
|
||||
commit = self.repo.head.commit
|
||||
except ValueError:
|
||||
commit = None
|
||||
commit = self.repo.head.commit
|
||||
except ValueError:
|
||||
commit = None
|
||||
|
||||
files = set()
|
||||
if commit:
|
||||
if commit in self.tree_files:
|
||||
files = self.tree_files[commit]
|
||||
else:
|
||||
for blob in commit.tree.traverse():
|
||||
if blob.type == "blob": # blob is a file
|
||||
files.add(blob.path)
|
||||
files = set(self.normalize_path(path) for path in files)
|
||||
self.tree_files[commit] = set(files)
|
||||
files = set()
|
||||
if commit:
|
||||
if commit in self.tree_files:
|
||||
files = self.tree_files[commit]
|
||||
else:
|
||||
for blob in commit.tree.traverse():
|
||||
if blob.type == "blob": # blob is a file
|
||||
files.add(blob.path)
|
||||
files = set(self.normalize_path(path) for path in files)
|
||||
self.tree_files[commit] = set(files)
|
||||
|
||||
# Add staged files
|
||||
index = self.repo.index
|
||||
staged_files = [path for path, _ in index.entries.keys()]
|
||||
files.update(self.normalize_path(path) for path in staged_files)
|
||||
# Add staged files
|
||||
index = self.repo.index
|
||||
staged_files = [path for path, _ in index.entries.keys()]
|
||||
files.update(self.normalize_path(path) for path in staged_files)
|
||||
|
||||
res = [fname for fname in files if not self.ignored_file(fname)]
|
||||
res = [fname for fname in files if not self.ignored_file(fname)]
|
||||
|
||||
return res
|
||||
except Exception as e:
|
||||
raise UnableToCountRepoFiles(f"Error getting tracked files: {str(e)}")
|
||||
return res
|
||||
|
||||
def normalize_path(self, path):
|
||||
orig_path = path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue