mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
![]() # 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. |
||
---|---|---|
.. | ||
__init__.py | ||
coder.py | ||
commands.py | ||
dump.py | ||
io.py | ||
main.py | ||
prompts.py | ||
utils.py |