From d0267f0ecea3c7692b781b30dddbc05d46f53f5e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 5 Jul 2024 13:06:47 -0300 Subject: [PATCH] Improved the handling of last commit detection and diff generation in the aider commands. --- aider/commands.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index fd129dc3c..0a8a7c2b7 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -330,8 +330,8 @@ class Commands: ) return - last_commit = self.coder.repo.repo.head.commit - if last_commit.hexsha[:7] != self.coder.last_aider_commit_hash: + last_commit_hash = self.coder.repo.repo.head.commit.hexsha[:7] + if last_commit_hash not in self.coder.aider_commit_hashes: self.io.tool_error("The last commit was not made by aider in this chat session.") self.io.tool_error( "You could try `/git reset --hard HEAD^` but be aware that this is a destructive" @@ -346,7 +346,7 @@ class Commands: self.coder.repo.repo.git.reset("--soft", "HEAD~1") self.io.tool_output( - f"Commit `{self.coder.last_aider_commit_hash}` was reset and removed from git.\n" + f"Commit `{last_commit_hash}` was reset and removed from git.\n" ) if self.coder.main_model.send_undo_reply: @@ -358,16 +358,17 @@ class Commands: self.io.tool_error("No git repository found.") return - if not self.coder.last_aider_commit_hash: - self.io.tool_error("No previous aider commit found.") + last_commit_hash = self.coder.repo.repo.head.commit.hexsha[:7] + + if last_commit_hash not in self.coder.aider_commit_hashes: + self.io.tool_error(f"Last commit {last_commit_hash} was not an aider commit.") self.io.tool_error("You could try `/git diff` or `/git diff HEAD^`.") return - commits = f"{self.coder.last_aider_commit_hash}~1" diff = self.coder.repo.diff_commits( self.coder.pretty, - commits, - self.coder.last_aider_commit_hash, + 'HEAD^', + 'HEAD', ) # don't use io.tool_output() because we don't want to log or further colorize