improved --no-auto-commits support

This commit is contained in:
Paul Gauthier 2023-05-14 07:37:04 -07:00
parent 78b1296e0e
commit 70ea500783
2 changed files with 21 additions and 13 deletions

View file

@ -15,7 +15,6 @@ import git
import openai import openai
# from aider.dump import dump # from aider.dump import dump
from aider import getinput
from aider import utils from aider import utils
from aider import prompts from aider import prompts
from aider.commands import Commands from aider.commands import Commands
@ -44,7 +43,9 @@ class Coder:
self.commands = Commands(self.io, self) self.commands = Commands(self.io, self)
self.main_model = main_model self.main_model = main_model
if main_model == "gpt-3.5-turbo": if main_model == "gpt-3.5-turbo":
self.io.tool_error(f"Aider doesn't work well with {main_model}, use gpt-4 for best results.") self.io.tool_error(
f"Aider doesn't work well with {main_model}, use gpt-4 for best results."
)
self.set_repo(fnames) self.set_repo(fnames)
@ -187,7 +188,11 @@ class Coder:
except EOFError: except EOFError:
return return
def should_commit(self, is_commit_command): def should_auto_commit(self, inp):
is_commit_command = inp and inp.startswith("/commit")
if not self.auto_commits:
return
if not self.repo: if not self.repo:
return return
if not self.repo.is_dirty(): if not self.repo.is_dirty():
@ -203,9 +208,7 @@ class Coder:
self.num_control_c = 0 self.num_control_c = 0
is_commit_command = inp and inp.startswith("/commit") if self.should_auto_commit(inp):
if self.should_commit(is_commit_command):
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
@ -299,10 +302,10 @@ class Coder:
words = set(word for word in content.split()) words = set(word for word in content.split())
# drop sentence punctuation from the end # drop sentence punctuation from the end
words = set(word.rstrip(',.!;') for word in words) words = set(word.rstrip(",.!;") for word in words)
# strip away all kinds of quotes # strip away all kinds of quotes
quotes = ''.join(['"', "'", "`"]) quotes = "".join(['"', "'", "`"])
words = set(word.strip(quotes) for word in words) words = set(word.strip(quotes) for word in words)
addable_rel_fnames = set(self.get_all_relative_files()) - set( addable_rel_fnames = set(self.get_all_relative_files()) - set(
@ -318,9 +321,9 @@ class Coder:
return return
for rel_fname in mentioned_rel_fnames: for rel_fname in mentioned_rel_fnames:
self.io.tool(f"{rel_fname}") self.io.tool(rel_fname)
if not self.io.confirm_ask(f"Add these files to the chat?"): if not self.io.confirm_ask("Add these files to the chat?"):
return return
for rel_fname in mentioned_rel_fnames: for rel_fname in mentioned_rel_fnames:
@ -419,7 +422,9 @@ class Coder:
if self.repo: if self.repo:
tracked_files = set(self.repo.git.ls_files().splitlines()) tracked_files = set(self.repo.git.ls_files().splitlines())
relative_fname = self.get_rel_fname(full_path) relative_fname = self.get_rel_fname(full_path)
if relative_fname not in tracked_files and self.io.confirm_ask(f"Add {path} to git?"): if relative_fname not in tracked_files and self.io.confirm_ask(
f"Add {path} to git?"
):
self.repo.git.add(full_path) self.repo.git.add(full_path)
edited.add(path) edited.add(path)
@ -455,7 +460,9 @@ class Coder:
commit_message = commit_message.strip().strip('"').strip() commit_message = commit_message.strip().strip('"').strip()
if interrupted: if interrupted:
self.io.tool_error("Unable to get commit message from gpt-3.5-turbo. Use /commit to try again.") self.io.tool_error(
"Unable to get commit message from gpt-3.5-turbo. Use /commit to try again."
)
return return
return commit_message return commit_message

View file

@ -102,6 +102,7 @@ def main(args=None, input=None, output=None):
args.auto_commits, args.auto_commits,
io, io,
) )
if args.auto_commits:
coder.commit(ask=True, prefix="wip: ", which="repo_files") coder.commit(ask=True, prefix="wip: ", which="repo_files")
if args.apply: if args.apply: