mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: Added check to prevent undoing a commit that has already been pushed to origin.
# Context: USER: also check to make sure the commit hasn't already been pushed to origin ASSISTANT: To check if the commit has already been pushed to the origin, we can compare the local and remote commit hashes. We will add a check using `self.coder.repo.git.rev_parse("HEAD")` and `self.coder.repo.git.rev_parse("origin/HEAD")` 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 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 ======= 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 local_head = self.coder.repo.git.rev_parse("HEAD") remote_head = self.coder.repo.git.rev_parse("origin/HEAD") if local_head == remote_head: self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.") return last_commit = self.coder.repo.head.commit >>>>>>> UPDATED ```
This commit is contained in:
parent
e74c90037c
commit
84b3a1756d
1 changed files with 7 additions and 0 deletions
|
@ -89,6 +89,13 @@ class Commands:
|
||||||
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
|
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
local_head = self.coder.repo.git.rev_parse("HEAD")
|
||||||
|
remote_head = self.coder.repo.git.rev_parse("origin/HEAD")
|
||||||
|
|
||||||
|
if local_head == remote_head:
|
||||||
|
self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
|
||||||
|
return
|
||||||
|
|
||||||
last_commit = self.coder.repo.head.commit
|
last_commit = self.coder.repo.head.commit
|
||||||
if (
|
if (
|
||||||
not last_commit.message.startswith("aider:")
|
not last_commit.message.startswith("aider:")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue