fix: handle absolute paths and globs in cmd_read_only

This commit is contained in:
Paul Gauthier (aider) 2024-10-25 07:43:31 -07:00
parent 5d3a60228c
commit f70a82791b

View file

@ -1170,12 +1170,20 @@ class Commands:
# First collect all expanded paths # First collect all expanded paths
for pattern in filenames: for pattern in filenames:
expanded_pattern = expanduser(pattern) expanded_pattern = expanduser(pattern)
expanded_paths = Path(self.coder.root).rglob(expanded_pattern) if os.path.isabs(expanded_pattern):
# For absolute paths, check if file exists directly
if not expanded_paths: path = Path(expanded_pattern)
self.io.tool_error(f"No matches found for: {pattern}") if path.exists():
all_paths.append(path)
else:
self.io.tool_error(f"No matches found for: {pattern}")
else: else:
all_paths.extend(expanded_paths) # 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)
# Then process them in sorted order # Then process them in sorted order
for path in sorted(all_paths): for path in sorted(all_paths):