mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
Improved the handling of last commit detection and diff generation in the aider commands.
This commit is contained in:
parent
44e6fefc23
commit
d0267f0ece
1 changed files with 9 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue