From f8e30ad7a03f5157e5638cc073c3342abdbb6944 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 18 Oct 2023 10:24:54 -0700 Subject: [PATCH] aider: Added import for `pathspec` library and implemented `filter_ignored_files` method to filter filenames according to gitignore type specifications in `self.aider_ignore_file`. # Aider chat conversation: ASSISTANT: To implement the `filter_ignored_files` method, we need to use the `pathspec` library to filter the filenames according to the gitignore type specifications in `self.aider_ignore_file`. The `pathspec` library is not currently imported in the `repo.py` file, so we need to add that import. We also need to read the `aider_ignore_file` and use its contents to create a `pathspec` that we can use to filter the filenames. Here are the changes: ```python aider/repo.py <<<<<<< HEAD import os from pathlib import Path, PurePosixPath import git from aider import models, prompts, utils from aider.sendchat import simple_send_with_retries from .dump import dump # noqa: F401 ======= import os import pathspec from pathlib import Path, PurePosixPath import git from aider import models, prompts, utils from aider.sendchat import simple_send_with_retries from .dump import dump # noqa: F401 >>>>>>> updated ``` ```python aider/repo.py <<<<<<< HEAD def filter_ignored_files(self, fnames): if not self.aider_ignore_file: return # todo: use pathspec to filter fnames according to the gitignore type specs in self.aider_ignore_file ======= def filter_ignored_files(self, fnames): if not self.aider_ignore_file: return fnames with open(self.aider_ignore_file, 'r') as f: ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f) return [fname for fname in fnames if not ignore_spec.match_file(fname)] >>>>>>> updated ``` Please note that these changes assume that `self.aider_ignore_file` is a path to a file containing gitignore-style patterns, one per line. If `self.aider_ignore_file` is not in this format, the code may need to be adjusted. --- aider/repo.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aider/repo.py b/aider/repo.py index 5a472b9c4..bc1c338ec 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -1,4 +1,5 @@ import os +import pathspec from pathlib import Path, PurePosixPath import git @@ -199,9 +200,12 @@ class GitRepo: def filter_ignored_files(self, fnames): if not self.aider_ignore_file: - return + return fnames - # todo: use pathspec to filter fnames according to the gitignore type specs in self.aider_ignore_file + with open(self.aider_ignore_file, 'r') as f: + ignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', f) + + return [fname for fname in fnames if not ignore_spec.match_file(fname)] def path_in_repo(self, path): if not self.repo: