aider: Added check to prevent undoing a commit that has already been pushed to origin.

# Context:
USER: also check to make sure the commit hasn't already been pushed to origin
ASSISTANT: To check if the commit has already been pushed to the origin, we can compare the local and remote commit hashes. We will add a check using `self.coder.repo.git.rev_parse("HEAD")` and `self.coder.repo.git.rev_parse("origin/HEAD")` 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

        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
=======
    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

        local_head = self.coder.repo.git.rev_parse("HEAD")
        remote_head = self.coder.repo.git.rev_parse("origin/HEAD")

        if local_head == remote_head:
            self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
            return

        last_commit = self.coder.repo.head.commit
>>>>>>> UPDATED
```
This commit is contained in:
Paul Gauthier 2023-05-13 09:48:30 -07:00
parent e74c90037c
commit 84b3a1756d

View file

@ -89,6 +89,13 @@ class Commands:
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
return
local_head = self.coder.repo.git.rev_parse("HEAD")
remote_head = self.coder.repo.git.rev_parse("origin/HEAD")
if local_head == remote_head:
self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
return
last_commit = self.coder.repo.head.commit
if (
not last_commit.message.startswith("aider:")