aider: Added condition to check if the last commit's hash matches last_aider_commit_hash before undoing the commit.

# Context:
USER: also double check the last commit against last_aider_commit_hash
ASSISTANT: To double-check the last commit against `last_aider_commit_hash` before undoing the commit, you can add a condition to the `cmd_undo` method in the `Coder` class in `aider/coder.py`.

```python
aider/coder.py
<<<<<<< ORIGINAL
        last_commit = self.repo.head.commit
        if not last_commit.message.startswith("aider:"):
            self.console.print("[red]The last commit was not made by Aider.")
            return
=======
        last_commit = self.repo.head.commit
        if not last_commit.message.startswith("aider:") or last_commit.hexsha[:7] != self.last_aider_commit_hash:
            self.console.print("[red]The last commit was not made by Aider or the commit hash does not match.")
            return
>>>>>>> UPDATED
```

This change adds a condition to check if the last commit's hash matches `last_aider_commit_hash` before undoing the commit. If it doesn't match, the method will print a message and return without undoing the commit.
This commit is contained in:
Paul Gauthier 2023-05-10 12:36:06 -07:00
parent 59ab516cbb
commit cfd27c84e9

View file

@ -493,10 +493,9 @@ class Coder:
return
last_commit = self.repo.head.commit
if not last_commit.message.startswith("aider:"):
self.console.print("[red]The last commit was not made by Aider.")
if not last_commit.message.startswith("aider:") or last_commit.hexsha[:7] != self.last_aider_commit_hash:
self.console.print("[red]The last commit was not made by Aider or the commit hash does not match.")
return
self.repo.git.reset("--hard", "HEAD~1")
self.console.print(f"[red]Undid the last commit: {last_commit.message.strip()}")
def cmd_add(self, args):