From c6d388595dd547acb3645e860fa537a6bf46b0c2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 19:39:52 -0700 Subject: [PATCH] aider: Added ability to create and add file to git if coder repo is not None. # Context: USER: say "do you want to create the file and add it to git?" if self.coder.repo is not none. and then add it to git. ASSISTANT: To implement this feature, we will modify the `cmd_add` method in the `aider/commands.py` file. We will check if `self.coder.repo` is not `None` and then ask the user if they want to create the file and add it to git. If the user confirms, we will create the file, add it to `matched_files`, and add it to the git repository. Here are the changes to the `aider/commands.py` file: ```python aider/commands.py <<<<<<< ORIGINAL create_file = 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') as new_file: pass matched_files = [word] ======= if self.coder.repo is not None: create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file and add it to git?") else: create_file = 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') as new_file: pass matched_files = [word] if self.coder.repo is not None: self.coder.repo.git.add(os.path.join(self.coder.root, word)) >>>>>>> UPDATED ``` These changes check if `self.coder.repo` is not `None` and modify the question asked to the user accordingly. If the user confirms, the new file is created, added to `matched_files`, and added to the git repository if `self.coder.repo` is not `None`. --- aider/commands.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 199986c87..5ea766a76 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -150,11 +150,17 @@ class Commands: for word in args.split(): matched_files = [file for file in files if word in file] if not matched_files: - create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file?") + if self.coder.repo is not None: + create_file = Confirm.ask(f"No files matched '{word}'. Do you want to create the file and add it to git?") + else: + create_file = 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') as new_file: pass matched_files = [word] + if self.coder.repo is not None: + self.coder.repo.git.add(os.path.join(self.coder.root, word)) else: self.console.print(f"[red]No files matched '{word}'") for matched_file in matched_files: