From c05efad2742abc59bf2d81a183cadc6ab327a3df Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 17 Jul 2023 15:51:14 -0300 Subject: [PATCH] aider: Add a new `/git` command to run git. # Aider chat conversation: USER: Add a new /git command to run git. so you could do `/git commit -a -m "message goes here"` or any other git command. It should work like `cmd_run` but prepends "git" to the `args`. Don't offer to send the output to gpt. ASSISTANT: To add a new `/git` command, we need to modify the `aider/commands.py` file. We will add a new method `cmd_git` that will prepend "git" to the `args` and run the command. This method will be similar to `cmd_run` but will not offer to send the output to gpt. Here is the change: python aider/commands.py <<<<<<< ORIGINAL def cmd_run(self, args): "Run a shell command and optionally add the output to the chat" combined_output = None try: parsed_args = shlex.split(args) result = subprocess.run( parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True ) combined_output = result.stdout except Exception as e: self.io.tool_error(f"Error running command: {e}") if combined_output is None: return self.io.tool_output(combined_output) if self.io.confirm_ask("Add the output to the chat?", default="y"): for line in combined_output.splitlines(): self.io.tool_output(line, log_only=True) msg = prompts.run_output.format( command=args, output=combined_output, ) return msg def cmd_exit(self, args): "Exit the application" sys.exit() ======= def cmd_git(self, args): "Run a git command" combined_output = None try: parsed_args = shlex.split("git " + args) result = subprocess.run( parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True ) combined_output = result.stdout except Exception as e: self.io.tool_error(f"Error running git command: {e}") if combined_output is None: return self.io.tool_output(combined_output) def cmd_run(self, args): "Run a shell command and optionally add the output to the chat" combined_output = None try: parsed_args = shlex.split(args) result = subprocess.run( parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True ) combined_output = result.stdout except Exception as e: self.io.tool_error(f"Error running command: {e}") if combined_output is None: return self.io.tool_output(combined_output) if self.io.confirm_ask("Add the output to the chat?", default="y"): for line in combined_output.splitlines(): self.io.tool_output(line, log_only=True) msg = prompts.run_output.format( command=args, output=combined_output, ) return msg def cmd_exit(self, args): "Exit the application" sys.exit() >>>>>>> UPDATED --- aider/commands.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aider/commands.py b/aider/commands.py index a17b57edb..10e9cd740 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -331,6 +331,23 @@ class Commands: self.coder.abs_fnames.remove(abs_fname) self.io.tool_output(f"Removed {matched_file} from the chat") + def cmd_git(self, args): + "Run a git command" + combined_output = None + try: + parsed_args = shlex.split("git " + args) + result = subprocess.run( + parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True + ) + combined_output = result.stdout + except Exception as e: + self.io.tool_error(f"Error running git command: {e}") + + if combined_output is None: + return + + self.io.tool_output(combined_output) + def cmd_run(self, args): "Run a shell command and optionally add the output to the chat" combined_output = None