notify when preparing dirty commit; skip if /exit or /commit is input

This commit is contained in:
Paul Gauthier 2023-07-11 13:21:36 -07:00
parent fde537cd7f
commit 967cb1bd8d
2 changed files with 17 additions and 5 deletions

View file

@ -402,9 +402,13 @@ class Coder:
return return
def should_dirty_commit(self, inp): def should_dirty_commit(self, inp):
is_commit_command = inp and inp.startswith("/commit") cmds = self.commands.matching_commands(inp)
if is_commit_command: if cmds:
return matching_commands, _, _ = cmds
if len(matching_commands) == 1:
cmd = matching_commands[0]
if cmd in ("/exit", "/commit"):
return
if not self.dirty_commits: if not self.dirty_commits:
return return
@ -436,6 +440,7 @@ class Coder:
self.num_control_c = 0 self.num_control_c = 0
if self.should_dirty_commit(inp): if self.should_dirty_commit(inp):
self.io.tool_output("Git repo has uncommitted changes, preparing commit...")
self.commit(ask=True, which="repo_files") self.commit(ask=True, which="repo_files")
# files changed, move cur messages back behind the files messages # files changed, move cur messages back behind the files messages

View file

@ -46,7 +46,7 @@ class Commands:
else: else:
self.io.tool_output(f"Error: Command {cmd_name} not found.") self.io.tool_output(f"Error: Command {cmd_name} not found.")
def run(self, inp): def matching_commands(self, inp):
words = inp.strip().split() words = inp.strip().split()
if not words: if not words:
return return
@ -56,12 +56,19 @@ class Commands:
all_commands = self.get_commands() all_commands = self.get_commands()
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)] 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: if len(matching_commands) == 1:
return self.do_run(matching_commands[0][1:], rest_inp) return self.do_run(matching_commands[0][1:], rest_inp)
elif len(matching_commands) > 1: elif len(matching_commands) > 1:
self.io.tool_error(f"Ambiguous command: {', '.join(matching_commands)}") self.io.tool_error(f"Ambiguous command: {', '.join(matching_commands)}")
else: 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. # any method called cmd_xxx becomes a command automatically.
# each one must take an args param. # each one must take an args param.