mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
fix: improve path handling in file watcher filter function
This commit is contained in:
parent
24e66337ff
commit
a625426a28
1 changed files with 7 additions and 2 deletions
|
@ -4,7 +4,7 @@ from typing import Optional, Set
|
||||||
from pathspec import PathSpec
|
from pathspec import PathSpec
|
||||||
from pathspec.patterns import GitWildMatchPattern
|
from pathspec.patterns import GitWildMatchPattern
|
||||||
from watchfiles import watch
|
from watchfiles import watch
|
||||||
|
from aider.dump import dump
|
||||||
|
|
||||||
def is_source_file(path: Path) -> bool:
|
def is_source_file(path: Path) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -73,7 +73,10 @@ def watch_source_files(directory: str, gitignores: list[str] = None, ignore_func
|
||||||
|
|
||||||
# Create a filter function that only accepts source files and respects gitignore
|
# Create a filter function that only accepts source files and respects gitignore
|
||||||
def filter_func(change_type, path):
|
def filter_func(change_type, path):
|
||||||
|
dump(path, root)
|
||||||
|
|
||||||
path_obj = Path(path)
|
path_obj = Path(path)
|
||||||
|
# ai: don't try/except, make the root an abs path so we can properly use relative_to
|
||||||
try:
|
try:
|
||||||
rel_path = path_obj.relative_to(root)
|
rel_path = path_obj.relative_to(root)
|
||||||
if gitignore_spec and gitignore_spec.match_file(str(rel_path)):
|
if gitignore_spec and gitignore_spec.match_file(str(rel_path)):
|
||||||
|
@ -81,7 +84,9 @@ def watch_source_files(directory: str, gitignores: list[str] = None, ignore_func
|
||||||
if ignore_func and ignore_func(rel_path):
|
if ignore_func and ignore_func(rel_path):
|
||||||
return False
|
return False
|
||||||
return is_source_file(path_obj)
|
return is_source_file(path_obj)
|
||||||
except ValueError:
|
except ValueError as err:
|
||||||
|
dump(err)
|
||||||
|
raise err
|
||||||
# Path is not relative to root directory
|
# Path is not relative to root directory
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue