@@ -405,3 +405,47 @@ def test_get_filenames_in_commit_error(mocker: MockFixture):
405
405
with pytest .raises (exceptions .GitCommandError ) as excinfo :
406
406
git .get_filenames_in_commit ()
407
407
assert str (excinfo .value ) == "fatal: bad object HEAD"
408
+
409
+
410
+ def test_git_commit_from_rev_and_commit ():
411
+ # Test data with all fields populated
412
+ rev_and_commit = (
413
+ "abc123\n " # rev
414
+ "def456 ghi789\n " # parents
415
+ "feat: add new feature\n " # title
416
+ "John Doe\n " # author
417
+ "john@example.com\n " # author_email
418
+ "This is a detailed description\n " # body
419
+ "of the new feature\n "
420
+ "with multiple lines"
421
+ )
422
+
423
+ commit = git .GitCommit .from_rev_and_commit (rev_and_commit )
424
+
425
+ assert commit .rev == "abc123"
426
+ assert commit .title == "feat: add new feature"
427
+ assert (
428
+ commit .body
429
+ == "This is a detailed description\n of the new feature\n with multiple lines"
430
+ )
431
+ assert commit .author == "John Doe"
432
+ assert commit .author_email == "john@example.com"
433
+ assert commit .parents == ["def456" , "ghi789" ]
434
+
435
+ # Test with minimal data
436
+ minimal_commit = (
437
+ "abc123\n " # rev
438
+ "\n " # no parents
439
+ "feat: minimal commit\n " # title
440
+ "John Doe\n " # author
441
+ "john@example.com\n " # author_email
442
+ )
443
+
444
+ commit = git .GitCommit .from_rev_and_commit (minimal_commit )
445
+
446
+ assert commit .rev == "abc123"
447
+ assert commit .title == "feat: minimal commit"
448
+ assert commit .body == ""
449
+ assert commit .author == "John Doe"
450
+ assert commit .author_email == "john@example.com"
451
+ assert commit .parents == []
0 commit comments