mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
Handle InvalidGitRepositoryError by replacing list comprehension with for loop and try-except.
# Context: USER: unroll the list comprehension so we can try/catch the exception below which is thrown for files not in any git repo File "/Users/gauthier/Projects/aider/aider/coder.py", line 68, in <genexpr> git.Repo(fname, search_parent_directories=True).git_dir ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gauthier/tmp/try-aider/.venv/lib/python3.11/site-packages/git/repo/base.py", line 265, in __init__ raise InvalidGitRepositoryError(epath) git.exc.InvalidGitRepositoryError: /Users/gauthier/tmp/try-aider/tmp.py ASSISTANT: To unroll the list comprehension and handle the exception, we can replace it with a for loop and use try-except to catch the `InvalidGitRepositoryError`. ```python aider/coder.py <<<<<<< ORIGINAL repo_paths = list( git.Repo(fname, search_parent_directories=True).git_dir for fname in self.fnames ) ======= repo_paths = [] for fname in self.fnames: try: repo_path = git.Repo(fname, search_parent_directories=True).git_dir repo_paths.append(repo_path) except git.exc.InvalidGitRepositoryError: pass >>>>>>> UPDATED ``` This change will catch the `InvalidGitRepositoryError` and continue processing the remaining files.
This commit is contained in:
parent
132e0a687f
commit
0cfbabb03b
1 changed files with 7 additions and 4 deletions
|
@ -64,10 +64,13 @@ class Coder:
|
|||
self.pretty = pretty
|
||||
|
||||
def set_repo(self):
|
||||
repo_paths = list(
|
||||
git.Repo(fname, search_parent_directories=True).git_dir
|
||||
for fname in self.fnames
|
||||
)
|
||||
repo_paths = []
|
||||
for fname in self.fnames:
|
||||
try:
|
||||
repo_path = git.Repo(fname, search_parent_directories=True).git_dir
|
||||
repo_paths.append(repo_path)
|
||||
except git.exc.InvalidGitRepositoryError:
|
||||
pass
|
||||
num_repos = len(set(repo_paths))
|
||||
|
||||
if num_repos == 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue