MCPcopy
hub / github.com/Aider-AI/aider / test_commit_with_co_authored_by

Method test_commit_with_co_authored_by

tests/basic/test_repo.py:267–315  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

265
266 @unittest.skipIf(platform.system() == "Windows", "Git env var behavior differs on Windows")
267 def test_commit_with_co_authored_by(self):
268 with GitTemporaryDirectory():
269 # new repo
270 raw_repo = git.Repo()
271 raw_repo.config_writer().set_value("user", "name", "Test User").release()
272 raw_repo.config_writer().set_value("user", "email", "test@example.com").release()
273
274 # add a file and commit it
275 fname = Path("file.txt")
276 fname.touch()
277 raw_repo.git.add(str(fname))
278 raw_repo.git.commit("-m", "initial commit")
279
280 # Mock coder args: Co-authored-by enabled, author/committer use default (None)
281 mock_coder = MagicMock()
282 mock_coder.args.attribute_co_authored_by = True
283 mock_coder.args.attribute_author = None # Default
284 mock_coder.args.attribute_committer = None # Default
285 mock_coder.args.attribute_commit_message_author = False
286 mock_coder.args.attribute_commit_message_committer = False
287 # The code uses coder.main_model.name for the co-authored-by line
288 mock_coder.main_model = MagicMock()
289 mock_coder.main_model.name = "gpt-test"
290
291 io = InputOutput()
292 git_repo = GitRepo(io, None, None)
293
294 # commit a change with aider_edits=True and co-authored-by flag
295 fname.write_text("new content")
296 commit_result = git_repo.commit(
297 fnames=[str(fname)], aider_edits=True, coder=mock_coder, message="Aider edit"
298 )
299 self.assertIsNotNone(commit_result)
300
301 # check the commit message and author/committer
302 commit = raw_repo.head.commit
303 self.assertIn("Co-authored-by: aider (gpt-test) <aider@aider.chat>", commit.message)
304 self.assertEqual(commit.message.splitlines()[0], "Aider edit")
305 # With default (None), co-authored-by takes precedence
306 self.assertEqual(
307 commit.author.name,
308 "Test User",
309 msg="Author name should not be modified when co-authored-by takes precedence",
310 )
311 self.assertEqual(
312 commit.committer.name,
313 "Test User",
314 msg="Committer name should not be modified when co-authored-by takes precedence",
315 )
316
317 @unittest.skipIf(platform.system() == "Windows", "Git env var behavior differs on Windows")
318 def test_commit_co_authored_by_with_explicit_name_modification(self):

Callers

nothing calls this directly

Calls 5

commitMethod · 0.95
InputOutputClass · 0.90
GitRepoClass · 0.90
write_textMethod · 0.80

Tested by

no test coverage detected