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}