Commit any linter edits

This commit is contained in:
Paul Gauthier 2024-08-01 12:29:01 -03:00
parent 59c51aa368
commit 3d1138b6c2

View file

@ -1033,11 +1033,20 @@ class Coder:
res = "" res = ""
for fname in fnames: for fname in fnames:
errors = self.linter.lint(self.abs_root_path(fname)) errors = self.linter.lint(self.abs_root_path(fname))
if errors: if errors:
res += "\n" res += "\n"
res += errors res += errors
res += "\n" res += "\n"
# Commit any formatting changes that happened
if self.repo and self.auto_commits and not self.dry_run:
commit_res = self.repo.commit(
fnames=fnames, context="The linter made edits to these files", aider_edits=True
)
if commit_res:
self.show_auto_commit_outcome(commit_res)
if res: if res:
self.io.tool_error(res) self.io.tool_error(res)
@ -1516,14 +1525,8 @@ class Coder:
context = self.get_context_from_history(self.cur_messages) context = self.get_context_from_history(self.cur_messages)
res = self.repo.commit(fnames=edited, context=context, aider_edits=True) res = self.repo.commit(fnames=edited, context=context, aider_edits=True)
if res: if res:
self.show_auto_commit_outcome(res)
commit_hash, commit_message = res commit_hash, commit_message = res
self.last_aider_commit_hash = commit_hash
self.aider_commit_hashes.add(commit_hash)
self.last_aider_commit_message = commit_message
if self.show_diffs:
self.commands.cmd_diff()
self.io.tool_output(f"You can use /undo to revert and discard commit {commit_hash}.")
return self.gpt_prompts.files_content_gpt_edits.format( return self.gpt_prompts.files_content_gpt_edits.format(
hash=commit_hash, hash=commit_hash,
message=commit_message, message=commit_message,
@ -1532,6 +1535,16 @@ class Coder:
self.io.tool_output("No changes made to git tracked files.") self.io.tool_output("No changes made to git tracked files.")
return self.gpt_prompts.files_content_gpt_no_edits return self.gpt_prompts.files_content_gpt_no_edits
def show_auto_commit_outcome(self, res):
commit_hash, commit_message = res
self.last_aider_commit_hash = commit_hash
self.aider_commit_hashes.add(commit_hash)
self.last_aider_commit_message = commit_message
if self.show_diffs:
self.commands.cmd_diff()
self.io.tool_output(f"You can use /undo to revert and discard commit {commit_hash}.")
def dirty_commit(self): def dirty_commit(self):
if not self.need_commit_before_edits: if not self.need_commit_before_edits:
return return