From 5a3627de6e01f6f026a0685ce4f59c3a1057af74 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 18 Jun 2024 08:37:13 -0700 Subject: [PATCH] finish removing aider: prefix --- aider/coders/base_coder.py | 5 ++--- aider/gui.py | 3 --- aider/repo.py | 23 +++++++++++------------ aider/tests/test_repo.py | 6 ++++-- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 255451e28..b529636ca 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import datetime import hashlib import json import os @@ -28,7 +27,7 @@ from aider.mdstream import MarkdownStream from aider.repo import GitRepo from aider.repomap import RepoMap 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 @@ -1385,7 +1384,7 @@ class Coder: def auto_commit(self, edited): # 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: commit_hash, commit_message = res self.last_aider_commit_hash = commit_hash diff --git a/aider/gui.py b/aider/gui.py index 16a13a004..b2239b162 100755 --- a/aider/gui.py +++ b/aider/gui.py @@ -110,9 +110,6 @@ class GUI: show_undo = False res = "" if commit_hash: - prefix = "aider: " - if commit_message.startswith(prefix): - commit_message = commit_message[len(prefix) :] res += f"Commit `{commit_hash}`: {commit_message} \n" if commit_hash == self.coder.last_aider_commit_hash: show_undo = True diff --git a/aider/repo.py b/aider/repo.py index ba2ca4f3b..214d2c6d9 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -59,7 +59,7 @@ class GitRepo: if 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(): return @@ -75,9 +75,6 @@ class GitRepo: if not commit_message: commit_message = "(no commit message provided)" - if prefix: - commit_message = prefix + commit_message - full_commit_message = commit_message if context: full_commit_message += "\n\n# Aider chat conversation:\n\n" + context @@ -91,20 +88,22 @@ class GitRepo: else: cmd += ["-a"] - user_name = self.repo.config_reader().get_value("user", "name") - committer_name = f"{user_name} (aider)" - original_committer_name = os.environ.get("GIT_COMMITTER_NAME") - os.environ["GIT_COMMITTER_NAME"] = committer_name + if aider_edits: + user_name = self.repo.config_reader().get_value("user", "name") + committer_name = f"{user_name} (aider)" + original_committer_name = os.environ.get("GIT_COMMITTER_NAME") + os.environ["GIT_COMMITTER_NAME"] = committer_name self.repo.git.commit(cmd) commit_hash = self.repo.head.commit.hexsha[:7] self.io.tool_output(f"Commit {commit_hash} {commit_message}") # Restore the original GIT_COMMITTER_NAME - if original_committer_name is not None: - os.environ["GIT_COMMITTER_NAME"] = original_committer_name - else: - del os.environ["GIT_COMMITTER_NAME"] + if aider_edits: + if original_committer_name is not None: + os.environ["GIT_COMMITTER_NAME"] = original_committer_name + else: + del os.environ["GIT_COMMITTER_NAME"] return commit_hash, commit_message diff --git a/aider/tests/test_repo.py b/aider/tests/test_repo.py index 70f715fb4..961fe8ee9 100644 --- a/aider/tests/test_repo.py +++ b/aider/tests/test_repo.py @@ -137,7 +137,7 @@ class TestRepo(unittest.TestCase): # Assert that the returned message is the expected one 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): mock_send.return_value = '"a good commit message"' @@ -156,7 +156,7 @@ class TestRepo(unittest.TestCase): # commit a change fname.write_text("new content") - git_repo.commit(fnames=[str(fname)]) + git_repo.commit(fnames=[str(fname)], aider_edits=True) # check the committer name commit = raw_repo.head.commit @@ -165,6 +165,8 @@ class TestRepo(unittest.TestCase): # check that the original committer name is restored original_committer_name = os.environ.get("GIT_COMMITTER_NAME") self.assertIsNone(original_committer_name) + + def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp())