mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
aider: Added conditional check to see if the repo has an origin before comparing local and remote commit hashes in cmd_undo.
# Context: USER: not all repos have an origin. only do that check if the repo does ASSISTANT: To check if the repo has an origin, we can use `self.coder.repo.remotes` to see if there is a remote named "origin". We will add a conditional check before comparing the local and remote commit hashes. ```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 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 ======= 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") has_origin = any(remote.name == "origin" for remote in self.coder.repo.remotes) if has_origin: 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
84b3a1756d
commit
83c47eef62
1 changed files with 6 additions and 4 deletions
|
@ -90,11 +90,13 @@ class Commands:
|
|||
return
|
||||
|
||||
local_head = self.coder.repo.git.rev_parse("HEAD")
|
||||
remote_head = self.coder.repo.git.rev_parse("origin/HEAD")
|
||||
has_origin = any(remote.name == "origin" for remote in self.coder.repo.remotes)
|
||||
|
||||
if local_head == remote_head:
|
||||
self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
|
||||
return
|
||||
if has_origin:
|
||||
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
|
||||
if (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue