mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
refactor: improve path handling in watch_source_files filter function
This commit is contained in:
parent
a625426a28
commit
f33cd4e419
1 changed files with 11 additions and 12 deletions
|
@ -76,19 +76,18 @@ def watch_source_files(directory: str, gitignores: list[str] = None, ignore_func
|
|||
dump(path, root)
|
||||
|
||||
path_obj = Path(path)
|
||||
# ai: don't try/except, make the root an abs path so we can properly use relative_to
|
||||
try:
|
||||
rel_path = path_obj.relative_to(root)
|
||||
root_abs = root.resolve()
|
||||
path_abs = path_obj.resolve()
|
||||
|
||||
if not path_abs.is_relative_to(root_abs):
|
||||
return False
|
||||
|
||||
rel_path = path_abs.relative_to(root_abs)
|
||||
if gitignore_spec and gitignore_spec.match_file(str(rel_path)):
|
||||
return False
|
||||
if ignore_func and ignore_func(rel_path):
|
||||
return False
|
||||
return is_source_file(path_obj)
|
||||
except ValueError as err:
|
||||
dump(err)
|
||||
raise err
|
||||
# Path is not relative to root directory
|
||||
return False
|
||||
|
||||
# Watch the directory for changes
|
||||
for changes in watch(root, watch_filter=filter_func):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue