allow multiple undo

This commit is contained in:
Paul Gauthier 2024-07-05 13:09:05 -03:00
parent 9e90dbc20d
commit 5122121265
2 changed files with 13 additions and 8 deletions

View file

@ -48,6 +48,7 @@ class Coder:
abs_fnames = None abs_fnames = None
repo = None repo = None
last_aider_commit_hash = None last_aider_commit_hash = None
aider_commit_hashes = set()
aider_edited_files = None aider_edited_files = None
last_asked_for_commit_time = 0 last_asked_for_commit_time = 0
repo_map = None repo_map = None
@ -115,6 +116,7 @@ class Coder:
fnames=from_coder.get_inchat_relative_files(), fnames=from_coder.get_inchat_relative_files(),
done_messages=done_messages, done_messages=done_messages,
cur_messages=from_coder.cur_messages, cur_messages=from_coder.cur_messages,
aider_commit_hashes=from_coder.aider_commit_hashes,
) )
use_kwargs.update(update) # override to complete the switch use_kwargs.update(update) # override to complete the switch
@ -222,6 +224,7 @@ class Coder:
attribute_author=True, attribute_author=True,
attribute_committer=True, attribute_committer=True,
attribute_commit_message=False, attribute_commit_message=False,
aider_commit_hashes=None,
): ):
if not fnames: if not fnames:
fnames = [] fnames = []
@ -229,6 +232,11 @@ class Coder:
if io is None: if io is None:
io = InputOutput() io = InputOutput()
if aider_commit_hashes:
self.aider_commit_hashes = aider_commit_hashes
else:
self.aider_commit_hashes = set()
self.chat_completion_call_hashes = [] self.chat_completion_call_hashes = []
self.chat_completion_response_hashes = [] self.chat_completion_response_hashes = []
self.need_commit_before_edits = set() self.need_commit_before_edits = set()
@ -1451,6 +1459,7 @@ class Coder:
if res: if res:
commit_hash, commit_message = res commit_hash, commit_message = res
self.last_aider_commit_hash = commit_hash self.last_aider_commit_hash = commit_hash
self.aider_commit_hashes.add(commit_hash)
self.last_aider_commit_message = commit_message self.last_aider_commit_message = commit_message
if self.show_diffs: if self.show_diffs:
self.commands.cmd_diff() self.commands.cmd_diff()

View file

@ -346,16 +346,12 @@ class Commands:
# Move the HEAD back before the latest commit # Move the HEAD back before the latest commit
self.coder.repo.repo.git.reset("--soft", "HEAD~1") self.coder.repo.repo.git.reset("--soft", "HEAD~1")
self.io.tool_output( self.io.tool_output(f"Removed: {last_commit_hash} {last_commit_message}")
f"Commit `{last_commit_hash}` with message '{last_commit_message}' was reset and removed from git."
)
# Get the current HEAD after undo # Get the current HEAD after undo
current_head_hash = self.coder.repo.repo.head.commit.hexsha[:7] current_head_hash = self.coder.repo.repo.head.commit.hexsha[:7]
current_head_message = self.coder.repo.repo.head.commit.message.strip() current_head_message = self.coder.repo.repo.head.commit.message.strip()
self.io.tool_output( self.io.tool_output(f"HEAD is: {current_head_hash} {current_head_message}")
f"Current HEAD is now `{current_head_hash}` with message '{current_head_message}'."
)
if self.coder.main_model.send_undo_reply: if self.coder.main_model.send_undo_reply:
return prompts.undo_command_reply return prompts.undo_command_reply
@ -375,8 +371,8 @@ class Commands:
diff = self.coder.repo.diff_commits( diff = self.coder.repo.diff_commits(
self.coder.pretty, self.coder.pretty,
'HEAD^', "HEAD^",
'HEAD', "HEAD",
) )
# don't use io.tool_output() because we don't want to log or further colorize # don't use io.tool_output() because we don't want to log or further colorize