mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
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: <source>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 </source>
This commit is contained in:
parent
f89119696b
commit
c05efad274
1 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue