feat: make /drop use substring matching for non-glob patterns

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 17:35:05 -08:00
parent d54fbd6592
commit ba17dceb4d

View file

@ -808,15 +808,22 @@ class Commands:
# Expand tilde in the path # Expand tilde in the path
expanded_word = os.path.expanduser(word) expanded_word = os.path.expanduser(word)
# Handle read-only files separately, without glob_filtered_to_repo # Handle read-only files with substring matching
read_only_matched = [f for f in self.coder.abs_read_only_fnames if expanded_word in f] read_only_matched = [f for f in self.coder.abs_read_only_fnames if expanded_word in f]
for matched_file in read_only_matched:
self.coder.abs_read_only_fnames.remove(matched_file)
self.io.tool_output(f"Removed read-only file {matched_file} from the chat")
if read_only_matched: # For editable files, use glob if word contains glob chars, otherwise use substring
for matched_file in read_only_matched: if any(c in expanded_word for c in "*?[]"):
self.coder.abs_read_only_fnames.remove(matched_file) matched_files = self.glob_filtered_to_repo(expanded_word)
self.io.tool_output(f"Removed read-only file {matched_file} from the chat") else:
# Use substring matching like we do for read-only files
matched_files = self.glob_filtered_to_repo(expanded_word) matched_files = [
self.coder.get_rel_fname(f)
for f in self.coder.abs_fnames
if expanded_word in f
]
if not matched_files: if not matched_files:
matched_files.append(expanded_word) matched_files.append(expanded_word)