aider/aider
Paul Gauthier e8b041af96 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.
2023-05-18 14:25:23 -07:00
..
__init__.py initial 2023-05-09 11:00:32 -07:00
coder.py moved Using git repo print to proper location 2023-05-18 12:26:26 -07:00
commands.py aider: Added check to ensure remote head is only fetched when there is a remote origin. 2023-05-18 14:25:23 -07:00
dump.py black formatting 2023-05-17 18:24:35 -07:00
io.py aider: Removed unused imports in aider/io.py. 2023-05-17 18:26:15 -07:00
main.py Added log_only parameter to io.tool function call. 2023-05-17 15:21:21 -07:00
prompts.py Ask to add /run output to the chat 2023-05-18 10:13:50 -07:00
utils.py make line numbers optional 2023-05-18 10:04:13 -07:00