diff --git a/aider/commands.py b/aider/commands.py index 58fa7d6c6..00189fecd 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -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.") diff --git a/aider/repo.py b/aider/repo.py index 214d2c6d9..38f5ef8f5 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -88,11 +88,15 @@ class GitRepo: else: cmd += ["-a"] + 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: - 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 + 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] @@ -100,10 +104,15 @@ class GitRepo: # 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_COMMITTER_NAME"] + 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"] return commit_hash, commit_message diff --git a/aider/tests/test_commands.py b/aider/tests/test_commands.py index 2fa84817b..f6629f481 100644 --- a/aider/tests/test_commands.py +++ b/aider/tests/test_commands.py @@ -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]