From 34aa1e8de09a547ea613ed773829106b820e8929 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 25 Oct 2024 09:46:59 -0700 Subject: [PATCH] fix: handle paths outside watched directory in file watcher --- aider/watch.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aider/watch.py b/aider/watch.py index 0fa5564e9..131cf28f9 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -71,9 +71,15 @@ def watch_source_files(directory: str, gitignore: str = None) -> Set[str]: # Create a filter function that only accepts source files and respects gitignore def filter_func(change_type, path): path_obj = Path(path) - if gitignore_spec and gitignore_spec.match_file(str(path_obj.relative_to(root))): + try: + if gitignore_spec: + rel_path = path_obj.relative_to(root) + if gitignore_spec.match_file(str(rel_path)): + return False + return is_source_file(path_obj) + except ValueError: + # Path is not relative to root directory return False - return is_source_file(path_obj) # Watch the directory for changes for changes in watch(root, watch_filter=filter_func):