mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
refactor: improve file path handling with glob and rglob
This commit is contained in:
parent
f70a82791b
commit
a080581329
2 changed files with 9 additions and 12 deletions
|
@ -1171,19 +1171,16 @@ class Commands:
|
|||
for pattern in filenames:
|
||||
expanded_pattern = expanduser(pattern)
|
||||
if os.path.isabs(expanded_pattern):
|
||||
# For absolute paths, check if file exists directly
|
||||
path = Path(expanded_pattern)
|
||||
if path.exists():
|
||||
all_paths.append(path)
|
||||
else:
|
||||
self.io.tool_error(f"No matches found for: {pattern}")
|
||||
# For absolute paths, glob it
|
||||
matches = list(glob.glob(expanded_pattern))
|
||||
else:
|
||||
# For relative paths and globs, use glob from the root directory
|
||||
matches = list(Path(self.coder.root).glob("**/" + expanded_pattern))
|
||||
if not matches:
|
||||
self.io.tool_error(f"No matches found for: {pattern}")
|
||||
else:
|
||||
all_paths.extend(matches)
|
||||
matches = list(Path(self.coder.root).rglob(expanded_pattern))
|
||||
|
||||
if not matches:
|
||||
self.io.tool_error(f"No matches found for: {pattern}")
|
||||
else:
|
||||
all_paths.extend(matches)
|
||||
|
||||
# Then process them in sorted order
|
||||
for path in sorted(all_paths):
|
||||
|
|
|
@ -714,7 +714,7 @@ class InputOutput:
|
|||
return "\n".join(read_only_files + editable_files) + "\n"
|
||||
|
||||
|
||||
def get_rel_fname(self, fname, root):
|
||||
def get_rel_fname(fname, root):
|
||||
try:
|
||||
return os.path.relpath(fname, root)
|
||||
except ValueError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue