From 2b6ea21a0bf74f2aa83eb0c456cc8b176b691d14 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 13 May 2023 09:46:21 -0700 Subject: [PATCH] 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 ``` --- aider/commands.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aider/commands.py b/aider/commands.py index f5c73d55b..cde5dd93d 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -85,6 +85,10 @@ class Commands: 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 if ( not last_commit.message.startswith("aider:")