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`.
This commit is contained in:
Paul Gauthier 2023-05-10 19:39:52 -07:00
parent 42d48bcf35
commit c6d388595d

View file

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