feat: Filter top-level directories based on .gitignore in file watcher

This commit is contained in:
Paul Gauthier (aider) 2025-02-04 13:03:29 -08:00
parent d53ee24741
commit e9097c3b29

View file

@ -115,9 +115,20 @@ class FileWatcher:
def watch_files():
try:
for changes in watch(
str(self.root), watch_filter=self.filter_func, stop_event=self.stop_event
):
# If a gitignore spec exists, filter out top-level entries that match it
if self.gitignore_spec:
roots_to_watch = [
str(path)
for path in self.root.iterdir()
if not self.gitignore_spec.match_file(path.name)
]
# Fallback to watching root if all top-level items are filtered out
if not roots_to_watch:
roots_to_watch = [str(self.root)]
else:
roots_to_watch = [str(self.root)]
for changes in watch(*roots_to_watch, watch_filter=self.filter_func, stop_event=self.stop_event):
if not changes:
continue
changed_files = {str(Path(change[1])) for change in changes}