@@ -872,6 +872,21 @@ def test_trailers(self):
872872 assert commit .trailers_list == [(KEY_2 , VALUE_2 )]
873873 assert commit .trailers_dict == {KEY_2 : [VALUE_2 ]}
874874
875+ def test_trailers_ignore_patch_divider (self ):
876+ """A ``---`` line does not end a commit message, as in Git's ``%(trailers)``."""
877+ commit = copy .copy (self .rorepo .commit ("HEAD" ))
878+ # Dependabot writes its metadata after a `---` line and signs off below it.
879+ commit .message = (
880+ "Bump x from 1 to 2\n \n Bumps x.\n \n ---\n updated-dependencies:\n - dependency-name: x\n ...\n \n "
881+ "Signed-off-by: dependabot[bot] <support@github.com>\n "
882+ )
883+ assert commit .trailers_list == [("Signed-off-by" , "dependabot[bot] <support@github.com>" )]
884+
885+ # A paragraph followed by `---` and more text is part of the body.
886+ commit .message = "Subject\n \n Reviewed-by: Maintainer <maintainer@example.com>\n ---\n Not a trailer\n "
887+ assert commit .trailers_list == []
888+ assert commit .trailers_dict == {}
889+
875890 def test_commit_co_authors (self ):
876891 commit = copy .copy (self .rorepo .commit ("dated" ))
877892 commit .message = """Commit message
@@ -950,6 +965,22 @@ def test_create_from_tree_with_trailers_list(self):
950965 "Issue" : ["456" ],
951966 }
952967
968+ def test_create_from_tree_appends_trailers_after_patch_divider (self ):
969+ """Trailers go at the end of a message containing ``---``, as with ``git commit --trailer``."""
970+ with fixture_repo ("commit.sh" , "tree" , write = True ) as rw_repo :
971+ tree = rw_repo .tree ((Path (rw_repo .working_tree_dir ).parent / "tree-id" ).read_text ().strip ())
972+
973+ commit = Commit .create_from_tree (
974+ rw_repo ,
975+ tree ,
976+ "Subject\n \n Body\n ---\n Notes\n " ,
977+ head = True ,
978+ trailers = {"Signed-off-by" : "Test User <test@test.com>" },
979+ )
980+
981+ assert commit .message == "Subject\n \n Body\n ---\n Notes\n \n Signed-off-by: Test User <test@test.com>\n "
982+ assert commit .trailers_dict == {"Signed-off-by" : ["Test User <test@test.com>" ]}
983+
953984 def test_create_from_tree_with_non_utf8_trailers (self ):
954985 """Test that trailer creation and parsing respect the configured commit encoding."""
955986 with fixture_repo ("commit.sh" , "latin1" , write = True ) as rw_repo :
0 commit comments