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:
Paul Gauthier 2023-05-13 09:51:57 -07:00
parent 84b3a1756d
commit 83c47eef62

View file

@ -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 (