diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index 40da50a86b..15f651ca06 100755 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -466,13 +466,13 @@ module SyncDefaultGems if log and !log.empty? log.sub!(/(?<=\n)\n+\z/, '') # drop empty lines at the last conv[log] - log.sub!(/(?:(\A\s*)|\s*\n)(?=((?i:Co-authored-by:.*\n)+)?\Z)/) { + log.sub!(/(?:(\A\s*)|\s*\n)(?=((?i:^Co-authored-by:.*\n?)+)?\Z)/) { ($~.begin(1) ? "" : "\n\n") + commit_url + ($~.begin(2) ? "\n" : "") } else log = commit_url end - print subject, "\n\n", log + puts subject, "\n", log end # NOTE: This method is also used by GitHub ruby/git.ruby-lang.org's bin/update-default-gem.sh diff --git a/tool/test/test_sync_default_gems.rb b/tool/test/test_sync_default_gems.rb index 602598c3e3..3987b1bec5 100755 --- a/tool/test/test_sync_default_gems.rb +++ b/tool/test/test_sync_default_gems.rb @@ -62,5 +62,15 @@ module Test_SyncDefaultGems ] assert_message_filter(expected, trailers, [expected, "", trailers, ""].join("\n")) end + + def test_co_authored_by_no_newline + expected = [ + "commit something", + ] + trailers = [ + "Co-Authored-By: git ", + ] + assert_message_filter(expected, trailers, [expected, "", trailers].join("\n")) + end end end