mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: aider: Modified cmd_add to skip file creation if word contains glob characters.
# Context: USER: if word doesn't match anything, don't ask to add it if it contains glob characters ASSISTANT: To implement this change, we need to modify the `aider/commands.py` file. Here's the step-by-step process: 1. In the `cmd_add` method, before asking to create a file, check if the word contains any glob characters (`*`, `?`, `[`, `]`). 2. If it does, skip the creation process and print an error message. Here's the code change: ```python aider/commands.py <<<<<<< ORIGINAL if not matched_files: if self.coder.repo is not None: create_file = self.io.confirm_ask( ( f"No files matched '{word}'. Do you want to create the file and add it" " to git?" ), ) else: create_file = self.io.confirm_ask( f"No files matched '{word}'. Do you want to create the file?" ) if create_file: with open(os.path.join(self.coder.root, word), "w"): pass matched_files = [word] if self.coder.repo is not None: self.coder.repo.git.add(os.path.join(self.coder.root, word)) commit_message = f"aider: Created and added {word} to git." self.coder.repo.git.commit("-m", commit_message, "--no-verify") else: self.io.tool_error(f"No files matched '{word}'") ======= if not matched_files: if any(char in word for char in "*?[]"): self.io.tool_error(f"No files matched '{word}' and it contains glob characters") else: if self.coder.repo is not None: create_file = self.io.confirm_ask( ( f"No files matched '{word}'. Do you want to create the file and add it" " to git?" ), ) else: create_file = self.io.confirm_ask( f"No files matched '{word}'. Do you want to create the file?" ) if create_file: with open(os.path.join(self.coder.root, word), "w"): pass matched_files = [word] if self.coder.repo is not None: self.coder.repo.git.add(os.path.join(self.coder.root, word)) commit_message = f"aider: Created and added {word} to git." self.coder.repo.git.commit("-m", commit_message, "--no-verify") else: self.io.tool_error(f"No files matched '{word}'") >>>>>>> UPDATED ``` Please let me know if you need any further changes.
This commit is contained in:
parent
2b07e2de30
commit
5cd7d9d743
1 changed files with 23 additions and 20 deletions
|
@ -225,28 +225,31 @@ class Commands:
|
||||||
matched_files = glob.glob(word, recursive=True)
|
matched_files = glob.glob(word, recursive=True)
|
||||||
|
|
||||||
if not matched_files:
|
if not matched_files:
|
||||||
if self.coder.repo is not None:
|
if any(char in word for char in "*?[]"):
|
||||||
create_file = self.io.confirm_ask(
|
self.io.tool_error(f"No files matched '{word}' and it contains glob characters")
|
||||||
(
|
|
||||||
f"No files matched '{word}'. Do you want to create the file and add it"
|
|
||||||
" to git?"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
create_file = self.io.confirm_ask(
|
|
||||||
f"No files matched '{word}'. Do you want to create the file?"
|
|
||||||
)
|
|
||||||
|
|
||||||
if create_file:
|
|
||||||
with open(os.path.join(self.coder.root, word), "w"):
|
|
||||||
pass
|
|
||||||
matched_files = [word]
|
|
||||||
if self.coder.repo is not None:
|
if self.coder.repo is not None:
|
||||||
self.coder.repo.git.add(os.path.join(self.coder.root, word))
|
create_file = self.io.confirm_ask(
|
||||||
commit_message = f"aider: Created and added {word} to git."
|
(
|
||||||
self.coder.repo.git.commit("-m", commit_message, "--no-verify")
|
f"No files matched '{word}'. Do you want to create the file and add it"
|
||||||
else:
|
" to git?"
|
||||||
self.io.tool_error(f"No files matched '{word}'")
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
create_file = self.io.confirm_ask(
|
||||||
|
f"No files matched '{word}'. Do you want to create the file?"
|
||||||
|
)
|
||||||
|
|
||||||
|
if create_file:
|
||||||
|
with open(os.path.join(self.coder.root, word), "w"):
|
||||||
|
pass
|
||||||
|
matched_files = [word]
|
||||||
|
if self.coder.repo is not None:
|
||||||
|
self.coder.repo.git.add(os.path.join(self.coder.root, word))
|
||||||
|
commit_message = f"aider: Created and added {word} to git."
|
||||||
|
self.coder.repo.git.commit("-m", commit_message, "--no-verify")
|
||||||
|
else:
|
||||||
|
self.io.tool_error(f"No files matched '{word}'")
|
||||||
|
|
||||||
for matched_file in matched_files:
|
for matched_file in matched_files:
|
||||||
abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file))
|
abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue