mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: Added check to ensure remote head is only fetched when there is a remote origin.
# Context: USER: the /undo command is throwing this error when the repo has no remote origin: Error: Unable to get the remote 'origin/scratch'. ASSISTANT: I see the issue. The code is trying to get the remote head even when there is no remote origin. I will add a check to ensure that the remote head is only fetched when there is a remote origin. Here's the change: ```python aider/commands.py <<<<<<< ORIGINAL if has_origin: current_branch = self.coder.repo.active_branch.name try: remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}") except git.exc.GitCommandError: self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.") return 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: current_branch = self.coder.repo.active_branch.name try: remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}") if local_head == remote_head: self.io.tool_error( "The last commit has already been pushed to the origin. Undoing is not" " possible." ) return except git.exc.GitCommandError ^C KeyboardInterrupt USER: no, has_origin needs to check if the *current branch* has an origin. ASSISTANT: I understand now. I will modify the `has_origin` check to verify if the current branch has an origin. Here's the updated change: ```python aider/commands.py <<<<<<< ORIGINAL has_origin = any(remote.name == "origin" for remote in self.coder.repo.remotes) if has_origin: current_branch = self.coder.repo.active_branch.name try: remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}") except git.exc.GitCommandError: self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.") return if local_head == remote_head: self.io.tool_error( "The last commit has already been pushed to the origin. Undoing is not" " possible." ) return ======= current_branch = self.coder.repo.active_branch.name try: remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}") has_origin = True except git.exc.GitCommandError: has_origin = False if has_origin: if local_head == remote_head: self.io.tool_error( "The last commit has already been pushed to the origin. Undoing is not" " possible." ) return >>>>>>> UPDATED ``` This change will set `has_origin` to `True` only if the current branch has an origin, and it will handle the error accordingly.
This commit is contained in:
parent
c9e35ebf83
commit
e8b041af96
1 changed files with 6 additions and 7 deletions
|
@ -99,15 +99,14 @@ class Commands:
|
|||
return
|
||||
|
||||
local_head = self.coder.repo.git.rev_parse("HEAD")
|
||||
has_origin = any(remote.name == "origin" for remote in self.coder.repo.remotes)
|
||||
current_branch = self.coder.repo.active_branch.name
|
||||
try:
|
||||
remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
|
||||
has_origin = True
|
||||
except git.exc.GitCommandError:
|
||||
has_origin = False
|
||||
|
||||
if has_origin:
|
||||
current_branch = self.coder.repo.active_branch.name
|
||||
try:
|
||||
remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
|
||||
except git.exc.GitCommandError:
|
||||
self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
|
||||
return
|
||||
if local_head == remote_head:
|
||||
self.io.tool_error(
|
||||
"The last commit has already been pushed to the origin. Undoing is not"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue