mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
finish removing aider: prefix
This commit is contained in:
parent
0cc00f2a1e
commit
5a3627de6e
4 changed files with 17 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import datetime
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -28,7 +27,7 @@ from aider.mdstream import MarkdownStream
|
||||||
from aider.repo import GitRepo
|
from aider.repo import GitRepo
|
||||||
from aider.repomap import RepoMap
|
from aider.repomap import RepoMap
|
||||||
from aider.sendchat import send_with_retries
|
from aider.sendchat import send_with_retries
|
||||||
from aider.utils import is_image_file, format_messages, format_content
|
from aider.utils import format_content, format_messages, is_image_file
|
||||||
|
|
||||||
from ..dump import dump # noqa: F401
|
from ..dump import dump # noqa: F401
|
||||||
|
|
||||||
|
@ -1385,7 +1384,7 @@ class Coder:
|
||||||
|
|
||||||
def auto_commit(self, edited):
|
def auto_commit(self, edited):
|
||||||
# context = self.get_context_from_history(self.cur_messages)
|
# context = self.get_context_from_history(self.cur_messages)
|
||||||
res = self.repo.commit(fnames=edited, prefix="aider: ")
|
res = self.repo.commit(fnames=edited, aider_edits=True)
|
||||||
if res:
|
if res:
|
||||||
commit_hash, commit_message = res
|
commit_hash, commit_message = res
|
||||||
self.last_aider_commit_hash = commit_hash
|
self.last_aider_commit_hash = commit_hash
|
||||||
|
|
|
@ -110,9 +110,6 @@ class GUI:
|
||||||
show_undo = False
|
show_undo = False
|
||||||
res = ""
|
res = ""
|
||||||
if commit_hash:
|
if commit_hash:
|
||||||
prefix = "aider: "
|
|
||||||
if commit_message.startswith(prefix):
|
|
||||||
commit_message = commit_message[len(prefix) :]
|
|
||||||
res += f"Commit `{commit_hash}`: {commit_message} \n"
|
res += f"Commit `{commit_hash}`: {commit_message} \n"
|
||||||
if commit_hash == self.coder.last_aider_commit_hash:
|
if commit_hash == self.coder.last_aider_commit_hash:
|
||||||
show_undo = True
|
show_undo = True
|
||||||
|
|
|
@ -59,7 +59,7 @@ class GitRepo:
|
||||||
if aider_ignore_file:
|
if aider_ignore_file:
|
||||||
self.aider_ignore_file = Path(aider_ignore_file)
|
self.aider_ignore_file = Path(aider_ignore_file)
|
||||||
|
|
||||||
def commit(self, fnames=None, context=None, prefix=None, message=None):
|
def commit(self, fnames=None, context=None, message=None, aider_edits=False):
|
||||||
if not fnames and not self.repo.is_dirty():
|
if not fnames and not self.repo.is_dirty():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -75,9 +75,6 @@ class GitRepo:
|
||||||
if not commit_message:
|
if not commit_message:
|
||||||
commit_message = "(no commit message provided)"
|
commit_message = "(no commit message provided)"
|
||||||
|
|
||||||
if prefix:
|
|
||||||
commit_message = prefix + commit_message
|
|
||||||
|
|
||||||
full_commit_message = commit_message
|
full_commit_message = commit_message
|
||||||
if context:
|
if context:
|
||||||
full_commit_message += "\n\n# Aider chat conversation:\n\n" + context
|
full_commit_message += "\n\n# Aider chat conversation:\n\n" + context
|
||||||
|
@ -91,20 +88,22 @@ class GitRepo:
|
||||||
else:
|
else:
|
||||||
cmd += ["-a"]
|
cmd += ["-a"]
|
||||||
|
|
||||||
user_name = self.repo.config_reader().get_value("user", "name")
|
if aider_edits:
|
||||||
committer_name = f"{user_name} (aider)"
|
user_name = self.repo.config_reader().get_value("user", "name")
|
||||||
original_committer_name = os.environ.get("GIT_COMMITTER_NAME")
|
committer_name = f"{user_name} (aider)"
|
||||||
os.environ["GIT_COMMITTER_NAME"] = committer_name
|
original_committer_name = os.environ.get("GIT_COMMITTER_NAME")
|
||||||
|
os.environ["GIT_COMMITTER_NAME"] = committer_name
|
||||||
|
|
||||||
self.repo.git.commit(cmd)
|
self.repo.git.commit(cmd)
|
||||||
commit_hash = self.repo.head.commit.hexsha[:7]
|
commit_hash = self.repo.head.commit.hexsha[:7]
|
||||||
self.io.tool_output(f"Commit {commit_hash} {commit_message}")
|
self.io.tool_output(f"Commit {commit_hash} {commit_message}")
|
||||||
|
|
||||||
# Restore the original GIT_COMMITTER_NAME
|
# Restore the original GIT_COMMITTER_NAME
|
||||||
if original_committer_name is not None:
|
if aider_edits:
|
||||||
os.environ["GIT_COMMITTER_NAME"] = original_committer_name
|
if original_committer_name is not None:
|
||||||
else:
|
os.environ["GIT_COMMITTER_NAME"] = original_committer_name
|
||||||
del os.environ["GIT_COMMITTER_NAME"]
|
else:
|
||||||
|
del os.environ["GIT_COMMITTER_NAME"]
|
||||||
|
|
||||||
return commit_hash, commit_message
|
return commit_hash, commit_message
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class TestRepo(unittest.TestCase):
|
||||||
# Assert that the returned message is the expected one
|
# Assert that the returned message is the expected one
|
||||||
self.assertEqual(result, 'a good "commit message"')
|
self.assertEqual(result, 'a good "commit message"')
|
||||||
|
|
||||||
@patch("aider.repo.simple_send_with_retries")
|
@patch("aider.repo.GitRepo.get_commit_message")
|
||||||
def test_commit_with_custom_committer_name(self, mock_send):
|
def test_commit_with_custom_committer_name(self, mock_send):
|
||||||
mock_send.return_value = '"a good commit message"'
|
mock_send.return_value = '"a good commit message"'
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class TestRepo(unittest.TestCase):
|
||||||
|
|
||||||
# commit a change
|
# commit a change
|
||||||
fname.write_text("new content")
|
fname.write_text("new content")
|
||||||
git_repo.commit(fnames=[str(fname)])
|
git_repo.commit(fnames=[str(fname)], aider_edits=True)
|
||||||
|
|
||||||
# check the committer name
|
# check the committer name
|
||||||
commit = raw_repo.head.commit
|
commit = raw_repo.head.commit
|
||||||
|
@ -165,6 +165,8 @@ class TestRepo(unittest.TestCase):
|
||||||
# check that the original committer name is restored
|
# check that the original committer name is restored
|
||||||
original_committer_name = os.environ.get("GIT_COMMITTER_NAME")
|
original_committer_name = os.environ.get("GIT_COMMITTER_NAME")
|
||||||
self.assertIsNone(original_committer_name)
|
self.assertIsNone(original_committer_name)
|
||||||
|
|
||||||
|
def test_get_tracked_files(self):
|
||||||
# Create a temporary directory
|
# Create a temporary directory
|
||||||
tempdir = Path(tempfile.mkdtemp())
|
tempdir = Path(tempfile.mkdtemp())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue