refactor: improve file path handling with glob and rglob

This commit is contained in:
Paul Gauthier 2024-10-25 07:49:19 -07:00 committed by Paul Gauthier (aider)
parent f70a82791b
commit a080581329
2 changed files with 9 additions and 12 deletions

View file

@ -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):

View file

@ -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: