finishing support for which=repo_files

This commit is contained in:
Paul Gauthier 2023-05-11 09:22:51 -07:00
parent 6e68562cd0
commit 14b45f40f6
3 changed files with 8 additions and 24 deletions

View file

@ -18,7 +18,7 @@ from pathlib import Path
import git import git
import openai import openai
# from aider.dump import dump from aider.dump import dump
from aider.getinput import get_input from aider.getinput import get_input
from aider import utils from aider import utils
from aider import prompts from aider import prompts
@ -450,20 +450,16 @@ class Coder:
else: else:
raise ValueError(f"Invalid value for 'which': {which}") raise ValueError(f"Invalid value for 'which': {which}")
dump(dirty_fnames)
diffs = "" diffs = ""
dirty_fnames = [] for (abs_fname,relative_fname) in zip(dirty_fnames, relative_dirty_fnames):
relative_dirty_fnames = []
for fname in self.abs_fnames:
relative_fname = os.path.relpath(fname, repo.working_tree_dir)
if self.pretty: if self.pretty:
these_diffs = repo.git.diff("HEAD", "--color", relative_fname) these_diffs = repo.git.diff("HEAD", "--color", relative_fname)
else: else:
these_diffs = repo.git.diff("HEAD", relative_fname) these_diffs = repo.git.diff("HEAD", relative_fname)
if these_diffs: diffs += these_diffs + "\n"
dirty_fnames.append(fname)
relative_dirty_fnames.append(relative_fname)
diffs += these_diffs + "\n"
if not dirty_fnames: if not dirty_fnames:
self.last_modified = self.get_last_modified() self.last_modified = self.get_last_modified()

View file

@ -73,23 +73,11 @@ class Commands:
return return
if not self.coder.repo.is_dirty(): if not self.coder.repo.is_dirty():
self.console.print("[red]No changes to commit.") self.console.print("[red]No more changes to commit.")
return return
commit_message = args.strip() commit_message = args.strip()
if commit_message: self.coder.commit(message = commit_message, which="repo_files")
self.coder.repo.git.add(
*[
os.path.relpath(fname, self.coder.repo.working_tree_dir)
for fname in self.coder.abs_fnames
]
)
self.coder.repo.git.commit("-m", commit_message, "--no-verify")
commit_hash = self.coder.repo.head.commit.hexsha[:7]
self.console.print(f"[bright_black]{commit_hash} {commit_message}")
return
self.coder.commit()
def cmd_undo(self, args): def cmd_undo(self, args):
"Undo the last git commit if it was done by aider" "Undo the last git commit if it was done by aider"

View file

@ -59,7 +59,7 @@ def main():
pretty = args.pretty pretty = args.pretty
coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs) coder = Coder(args.model, fnames, pretty, args.history_file, args.show_diffs)
coder.commit(ask=True, prefix="wip: ") coder.commit(ask=True, prefix="wip: ", which="repo_files")
if args.apply: if args.apply:
with open(args.apply, "r") as f: with open(args.apply, "r") as f: