From 33ff801f82fd08eccf2032cc4c5fc9b76ab3a537 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 1 Aug 2024 17:19:26 -0300 Subject: [PATCH] feat: Add refresh_aider_ignore method to GitRepo class --- aider/repo.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/aider/repo.py b/aider/repo.py index 731e2111f..846ed0cc9 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -258,7 +258,29 @@ class GitRepo: def normalize_path(self, path): return str(Path(PurePosixPath((Path(self.root) / path).relative_to(self.root)))) + + def refresh_aider_ignore(self): + if not self.aider_ignore_file: + return + + # todo: only recheck this once / second + + if not self.aider_ignore_file.is_file(): + return + + mtime = self.aider_ignore_file.stat().st_mtime + if mtime != self.aider_ignore_ts: + self.aider_ignore_ts = mtime + self.ignore_file_cache = {} + lines = self.aider_ignore_file.read_text().splitlines() + self.aider_ignore_spec = pathspec.PathSpec.from_lines( + pathspec.patterns.GitWildMatchPattern, + lines, + ) + def ignored_file(self, fname): + self.refresh_aider_ignore() + if fname in self.ignore_file_cache: return self.ignore_file_cache[fname] @@ -282,16 +304,6 @@ class GitRepo: except ValueError: return True - mtime = self.aider_ignore_file.stat().st_mtime - if mtime != self.aider_ignore_ts: - self.aider_ignore_ts = mtime - self.ignore_file_cache = {} - lines = self.aider_ignore_file.read_text().splitlines() - self.aider_ignore_spec = pathspec.PathSpec.from_lines( - pathspec.patterns.GitWildMatchPattern, - lines, - ) - return self.aider_ignore_spec.match_file(fname) def path_in_repo(self, path):