mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
commit wip
This commit is contained in:
parent
c8ed567b66
commit
c02501d690
2 changed files with 12 additions and 22 deletions
32
coder.py
32
coder.py
|
@ -17,7 +17,7 @@ from tqdm import tqdm
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pygit2
|
import git
|
||||||
import openai
|
import openai
|
||||||
|
|
||||||
from dump import dump
|
from dump import dump
|
||||||
|
@ -405,38 +405,28 @@ class Coder:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def commit(self, message_history, prefix=None):
|
def commit(self, message_history, prefix=None):
|
||||||
repo_paths = set(pygit2.discover_repository(fname) for fname in self.fnames)
|
repo_paths = set(
|
||||||
|
git.Repo(fname, search_parent_directories=True).git_dir
|
||||||
|
for fname in self.fnames
|
||||||
|
)
|
||||||
|
|
||||||
if len(repo_paths) > 1:
|
if len(repo_paths) > 1:
|
||||||
repo_paths = " ".join(repo_paths)
|
repo_paths = " ".join(repo_paths)
|
||||||
raise ValueError(f"Files must all be in one git repo, not: {repo_paths}")
|
raise ValueError(f"Files must all be in one git repo, not: {repo_paths}")
|
||||||
|
|
||||||
repo = pygit2.Repository(repo_paths.pop())
|
repo = git.Repo(repo_paths.pop())
|
||||||
|
if not repo.is_dirty():
|
||||||
"""
|
|
||||||
index = repo.index
|
|
||||||
index.read()
|
|
||||||
for patch in index.diff_to_workdir():
|
|
||||||
print(patch.text)
|
|
||||||
"""
|
|
||||||
|
|
||||||
patches = repo.diff("HEAD")
|
|
||||||
if not len(patches):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
diffs = "# Diffs:\n"
|
||||||
|
diffs += repo.git.diff("HEAD")
|
||||||
|
|
||||||
context = ""
|
context = ""
|
||||||
if message_history:
|
if message_history:
|
||||||
context += "# Context:\n"
|
context += "# Context:\n"
|
||||||
for msg in message_history:
|
for msg in message_history:
|
||||||
context += msg["role"].upper() + ": " + msg["content"] + "\n"
|
context += msg["role"].upper() + ": " + msg["content"] + "\n"
|
||||||
|
|
||||||
diffs = "# Diffs:\n"
|
|
||||||
for diff in patches:
|
|
||||||
dump(dir(diff))
|
|
||||||
dump(diff.delta.new_file.path)
|
|
||||||
diffs += diff.text
|
|
||||||
diffs += "\n\n"
|
|
||||||
|
|
||||||
if not diffs:
|
if not diffs:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -453,7 +443,7 @@ class Coder:
|
||||||
silent=True,
|
silent=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
commit_message = commit_message.strip()
|
commit_message = commit_message.strip().strip('"').strip()
|
||||||
|
|
||||||
if interrupted:
|
if interrupted:
|
||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
|
|
|
@ -108,5 +108,5 @@ ONLY OUTPUT {fname} !!!
|
||||||
commit_system = """You are an expert software engineer.
|
commit_system = """You are an expert software engineer.
|
||||||
Review the provided context and diffs which are about to be committed to a git repo.
|
Review the provided context and diffs which are about to be committed to a git repo.
|
||||||
Generate a 1 line, 1-2 sentence commit message.
|
Generate a 1 line, 1-2 sentence commit message.
|
||||||
Reply with JUST the commit message, without comments, questions, etc.
|
Reply with JUST the commit message, without quotes, comments, questions, etc.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue