Improved the handling of last commit detection and diff generation in the aider commands.

This commit is contained in:
Paul Gauthier 2024-07-05 13:06:47 -03:00 committed by Paul Gauthier (aider)
parent 44e6fefc23
commit d0267f0ece

View file

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