diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index c0a16499a..7e569f85b 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -402,9 +402,13 @@ class Coder: return def should_dirty_commit(self, inp): - is_commit_command = inp and inp.startswith("/commit") - if is_commit_command: - return + cmds = self.commands.matching_commands(inp) + if cmds: + matching_commands, _, _ = cmds + if len(matching_commands) == 1: + cmd = matching_commands[0] + if cmd in ("/exit", "/commit"): + return if not self.dirty_commits: return @@ -436,6 +440,7 @@ class Coder: self.num_control_c = 0 if self.should_dirty_commit(inp): + self.io.tool_output("Git repo has uncommitted changes, preparing commit...") self.commit(ask=True, which="repo_files") # files changed, move cur messages back behind the files messages diff --git a/aider/commands.py b/aider/commands.py index 60e202203..eae6b8a89 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -46,7 +46,7 @@ class Commands: else: self.io.tool_output(f"Error: Command {cmd_name} not found.") - def run(self, inp): + def matching_commands(self, inp): words = inp.strip().split() if not words: return @@ -56,12 +56,19 @@ class Commands: all_commands = self.get_commands() matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)] + return matching_commands, first_word, rest_inp + + def run(self, inp): + res = self.matching_commands(inp) + if res is None: + return + matching_commands, first_word, rest_inp = res if len(matching_commands) == 1: return self.do_run(matching_commands[0][1:], rest_inp) elif len(matching_commands) > 1: self.io.tool_error(f"Ambiguous command: {', '.join(matching_commands)}") else: - self.io.tool_error(f"Error: {first_word} is not a valid command.") + self.io.tool_error(f"Invalid command: {first_word}") # any method called cmd_xxx becomes a command automatically. # each one must take an args param.