mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
append (aider) to author if aider wrote the code
This commit is contained in:
parent
39f10aefe0
commit
9e228670a2
3 changed files with 19 additions and 10 deletions
|
@ -332,7 +332,7 @@ class Commands:
|
|||
|
||||
last_commit = self.coder.repo.repo.head.commit
|
||||
if (
|
||||
"(aider)" not in last_commit.committer.name
|
||||
not last_commit.author.name.endswith(" (aider)")
|
||||
or last_commit.hexsha[:7] != self.coder.last_aider_commit_hash
|
||||
):
|
||||
self.io.tool_error("The last commit was not made by aider in this chat session.")
|
||||
|
|
|
@ -88,20 +88,29 @@ class GitRepo:
|
|||
else:
|
||||
cmd += ["-a"]
|
||||
|
||||
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")
|
||||
original_user_name = self.repo.config_reader().get_value("user", "name")
|
||||
original_committer_name_env = os.environ.get("GIT_COMMITTER_NAME")
|
||||
|
||||
committer_name = f"{original_user_name} (aider)"
|
||||
os.environ["GIT_COMMITTER_NAME"] = committer_name
|
||||
|
||||
if aider_edits:
|
||||
original_auther_name_env = os.environ.get("GIT_AUTHOR_NAME")
|
||||
os.environ["GIT_AUTHOR_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 aider_edits:
|
||||
if original_committer_name is not None:
|
||||
os.environ["GIT_COMMITTER_NAME"] = original_committer_name
|
||||
if original_auther_name_env is not None:
|
||||
os.environ["GIT_AUTHOR_NAME"] = original_auther_name_env
|
||||
else:
|
||||
del os.environ["GIT_AUTHOR_NAME"]
|
||||
|
||||
if original_committer_name_env is not None:
|
||||
os.environ["GIT_COMMITTER_NAME"] = original_committer_name_env
|
||||
else:
|
||||
del os.environ["GIT_COMMITTER_NAME"]
|
||||
|
||||
|
|
|
@ -523,7 +523,7 @@ class TestCommands(TestCase):
|
|||
other_path.write_text("other content")
|
||||
repo.git.add(str(other_path))
|
||||
|
||||
os.environ["GIT_COMMITTER_NAME"] = "Foo (aider)"
|
||||
os.environ["GIT_AUTHOR_NAME"] = "Foo (aider)"
|
||||
|
||||
# Create and commit a file
|
||||
filename = "test_file.txt"
|
||||
|
@ -536,7 +536,7 @@ class TestCommands(TestCase):
|
|||
repo.git.add(filename)
|
||||
repo.git.commit("-m", "second commit")
|
||||
|
||||
del os.environ["GIT_COMMITTER_NAME"]
|
||||
del os.environ["GIT_AUTHOR_NAME"]
|
||||
|
||||
# Store the commit hash
|
||||
last_commit_hash = repo.head.commit.hexsha[:7]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue