From e9097c3b293b35c6549eebbd8db1542774b496de Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 4 Feb 2025 13:03:29 -0800 Subject: [PATCH] feat: Filter top-level directories based on .gitignore in file watcher --- aider/watch.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aider/watch.py b/aider/watch.py index f1e24bcc5..0a657b846 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -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}