aider: Added cmd_diff command to display the diff of the last aider commit.

# Context:
USER: add cmd_diff which displays the diff of the last aider commit
ASSISTANT: To add the `cmd_diff` command, we will update the `aider/coder.py` file. We will add a new method called `cmd_diff` to the `Coder` class and update the `Commands` instance to include the new command.

```python
aider/coder.py
<<<<<<< ORIGINAL
        self.commands = Commands(self.console, self)
=======
        self.commands = Commands(self.console, self)
        self.commands.add("diff", self.cmd_diff, "Display the diff of the last aider commit")
>>>>>>> UPDATED

aider/coder.py
<<<<<<< ORIGINAL
    def cmd_ls(self, args):
        "List files and show their chat status"

        self.console.print(f"* denotes files included in the chat\n")
        files = self.get_active_files()

        for file in files:
            abs_file_path = os.path.abspath(os.path.join(self.root, file))
            if abs_file_path in self.fnames:
                self.console.print(f"* {file}")
            else:
                self.console.print(f"  {file}")
=======
    def cmd_diff(self, args):
        "Display the diff of the last aider commit"
        if not self.repo:
            self.console.print("[red]No git repository found.")
            return

        if not self.last_aider_commit_hash:
            self.console.print("[red]No previous aider commit found.")
            return

        diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
        self.console.print(Text(diff))

    def cmd_ls(self, args):
        "List files and show their chat status"

        self.console.print(f"* denotes files included in the chat\n")
        files = self.get_active_files()

        for file in files:
            abs_file_path = os.path.abspath(os.path.join(self.root, file))
            if abs_file_path in self.fnames:
                self.console.print(f"* {file}")
            else:
                self.console.print(f"  {file}")
>>>>>>> UPDATED
```

This will add the `cmd_diff` command to display the diff of the last aider commit.
This commit is contained in:
Paul Gauthier 2023-05-10 12:46:44 -07:00
parent 540c12fafa
commit 8d6eafb1dc

View file

@ -42,7 +42,7 @@ class Coder:
self.console = Console(force_terminal=True, no_color=True)
self.commands = Commands(self.console, self)
self.commands.add("diff", self.cmd_diff, "Display the diff of the last aider commit")
self.main_model = main_model
if main_model == "gpt-3.5-turbo":
self.console.print(
@ -544,6 +544,19 @@ class Coder:
self.fnames.remove(matched_file)
self.console.print(f"[red]Removed {relative_fname} from the chat")
def cmd_diff(self, args):
"Display the diff of the last aider commit"
if not self.repo:
self.console.print("[red]No git repository found.")
return
if not self.last_aider_commit_hash:
self.console.print("[red]No previous aider commit found.")
return
diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
self.console.print(Text(diff))
def cmd_ls(self, args):
"List files and show their chat status"