Normalize paths before checking aiderignore #479

This commit is contained in:
Paul Gauthier 2024-02-25 15:52:49 -08:00
parent 49c904eea5
commit 6dd5ae69e3
3 changed files with 16 additions and 13 deletions

View file

@ -165,13 +165,6 @@ class Coder:
except FileNotFoundError:
self.repo = None
if self.repo:
filtered_fnames = self.repo.filter_ignored_files(fnames)
for fname in fnames:
if fname not in filtered_fnames:
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
fnames = filtered_fnames
for fname in fnames:
fname = Path(fname)
if not fname.exists():
@ -182,7 +175,13 @@ class Coder:
if not fname.is_file():
raise ValueError(f"{fname} is not a file")
self.abs_fnames.add(str(fname.resolve()))
fname = str(fname.resolve())
if self.repo and self.repo.ignored_file(fname):
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
continue
self.abs_fnames.add(fname)
self.check_added_files()
if self.repo:

View file

@ -342,7 +342,7 @@ class Commands:
else:
fname = Path(self.coder.root) / word
if self.coder.repo and not self.coder.repo.filter_ignored_files([fname]):
if self.coder.repo and self.coder.repo.ignored_file(fname):
self.io.tool_error(f"Skipping {fname} that matches aiderignore spec.")
continue

View file

@ -198,14 +198,18 @@ class GitRepo:
# convert to appropriate os.sep, since git always normalizes to /
res = set(self.normalize_path(path) for path in files)
return self.filter_ignored_files(res)
res = [fname for fname in res if not self.ignored_file(fname)]
return res
def normalize_path(self, path):
return str(Path(PurePosixPath((Path(self.root) / path).relative_to(self.root))))
def filter_ignored_files(self, fnames):
def ignored_file(self, fname):
if not self.aider_ignore_file or not self.aider_ignore_file.is_file():
return fnames
return
fname = self.normalize_path(fname)
mtime = self.aider_ignore_file.stat().st_mtime
if mtime != self.aider_ignore_ts:
@ -216,7 +220,7 @@ class GitRepo:
lines,
)
return [fname for fname in fnames if not self.aider_ignore_spec.match_file(fname)]
return self.aider_ignore_spec.match_file(fname)
def path_in_repo(self, path):
if not self.repo: