From cfd27c84e9e0c3f09d9a9dfd27034cbcbb3cd0fa Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:36:06 -0700 Subject: [PATCH] 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. --- aider/coder.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aider/coder.py b/aider/coder.py index 0bb8b4da6..8fe543f84 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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):