@@ -566,3 +566,77 @@ def test_commit_co_authors(self):
566566 Actor (
"test_user_2" ,
"[email protected] " ),
567567 Actor (
"test_user_3" ,
"[email protected] " ),
568568 ]
569+
570+ @with_rw_directory
571+ def test_create_from_tree_with_trailers_dict (self , rw_dir ):
572+ """Test that create_from_tree supports adding trailers via a dict."""
573+ rw_repo = Repo .init (osp .join (rw_dir , "test_trailers_dict" ))
574+ path = osp .join (str (rw_repo .working_tree_dir ), "hello.txt" )
575+ touch (path )
576+ rw_repo .index .add ([path ])
577+ tree = rw_repo .index .write_tree ()
578+
579+ trailers = {
"Issue" :
"123" ,
"Signed-off-by" :
"Test User <[email protected] >" }
580+ commit = Commit .create_from_tree (
581+ rw_repo ,
582+ tree ,
583+ "Test commit with trailers" ,
584+ head = True ,
585+ trailers = trailers ,
586+ )
587+
588+ assert "Issue: 123" in commit .message
589+ assert "Signed-off-by: Test User <[email protected] >" in commit .
message 590+ assert commit .trailers_dict == {
591+ "Issue" : ["123" ],
592+ "Signed-off-by" : [
"Test User <[email protected] >" ],
593+ }
594+
595+ @with_rw_directory
596+ def test_create_from_tree_with_trailers_list (self , rw_dir ):
597+ """Test that create_from_tree supports adding trailers via a list of tuples."""
598+ rw_repo = Repo .init (osp .join (rw_dir , "test_trailers_list" ))
599+ path = osp .join (str (rw_repo .working_tree_dir ), "hello.txt" )
600+ touch (path )
601+ rw_repo .index .add ([path ])
602+ tree = rw_repo .index .write_tree ()
603+
604+ trailers = [
605+ (
"Signed-off-by" ,
"Alice <[email protected] >" ),
606+ (
"Signed-off-by" ,
"Bob <[email protected] >" ),
607+ ("Issue" , "456" ),
608+ ]
609+ commit = Commit .create_from_tree (
610+ rw_repo ,
611+ tree ,
612+ "Test commit with multiple trailers" ,
613+ head = True ,
614+ trailers = trailers ,
615+ )
616+
617+ assert "Signed-off-by: Alice <[email protected] >" in commit .
message 618+ assert "Signed-off-by: Bob <[email protected] >" in commit .
message 619+ assert "Issue: 456" in commit .message
620+ assert commit .trailers_dict == {
621+ "Signed-off-by" : [
"Alice <[email protected] >" ,
"Bob <[email protected] >" ],
622+ "Issue" : ["456" ],
623+ }
624+
625+ @with_rw_directory
626+ def test_index_commit_with_trailers (self , rw_dir ):
627+ """Test that IndexFile.commit() supports adding trailers."""
628+ rw_repo = Repo .init (osp .join (rw_dir , "test_index_trailers" ))
629+ path = osp .join (str (rw_repo .working_tree_dir ), "hello.txt" )
630+ touch (path )
631+ rw_repo .index .add ([path ])
632+
633+ trailers = {
"Reviewed-by" :
"Reviewer <[email protected] >" }
634+ commit = rw_repo .index .commit (
635+ "Test index commit with trailers" ,
636+ trailers = trailers ,
637+ )
638+
639+ assert "Reviewed-by: Reviewer <[email protected] >" in commit .
message 640+ assert commit .trailers_dict == {
641+ "Reviewed-by" : [
"Reviewer <[email protected] >" ],
642+ }
0 commit comments