feat: Add refresh_aider_ignore method to GitRepo class

This commit is contained in:
Paul Gauthier 2024-08-01 17:19:26 -03:00 committed by Paul Gauthier (aider)
parent 97688b91ee
commit 33ff801f82

View file

@ -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):