From 8d6eafb1dc663dfbd1ea358262b40de170012421 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:46:44 -0700 Subject: [PATCH] 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. --- aider/coder.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index 1b7e1cb67..9a4eb2aee 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -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"