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.
This commit is contained in:
Paul Gauthier 2023-10-18 10:24:54 -07:00
parent 10f2e114c5
commit f8e30ad7a0

View file

@ -1,4 +1,5 @@
import os import os
import pathspec
from pathlib import Path, PurePosixPath from pathlib import Path, PurePosixPath
import git import git
@ -199,9 +200,12 @@ class GitRepo:
def filter_ignored_files(self, fnames): def filter_ignored_files(self, fnames):
if not self.aider_ignore_file: 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): def path_in_repo(self, path):
if not self.repo: if not self.repo: