aider: Added check to ensure the repo isn't dirty before undoing.

# Context:
USER: in /undo make sure the repo isn't dirty before undoing
ASSISTANT: To ensure the repo isn't dirty before undoing, we will add a check using `self.coder.repo.is_dirty()` before performing the undo operation.

```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_undo(self, args):
        "Undo the last git commit if it was done by aider"
        if not self.coder.repo:
            self.io.tool_error("No git repository found.")
            return

        last_commit = self.coder.repo.head.commit
=======
    def cmd_undo(self, args):
        "Undo the last git commit if it was done by aider"
        if not self.coder.repo:
            self.io.tool_error("No git repository found.")
            return

        if self.coder.repo.is_dirty():
            self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
            return

        last_commit = self.coder.repo.head.commit
>>>>>>> UPDATED
```
This commit is contained in:
Paul Gauthier 2023-05-13 09:46:21 -07:00
parent 981710ca16
commit 2b6ea21a0b

View file

@ -85,6 +85,10 @@ class Commands:
self.io.tool_error("No git repository found.") self.io.tool_error("No git repository found.")
return return
if self.coder.repo.is_dirty():
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
return
last_commit = self.coder.repo.head.commit last_commit = self.coder.repo.head.commit
if ( if (
not last_commit.message.startswith("aider:") not last_commit.message.startswith("aider:")