git-commit: fix to lack of newline separation

There was an issue where the trailers were not properly separated from
the commit message itself. In fact, a new line is not added if there
are not trailers either.

Add a fix to add a newline after the commit message. Also adding test
cases to test 0, 1, or 2 trailers in a git commit.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-11-28 10:07:08 +00:00
parent 0d32904d27
commit 295b0d25e5
3 changed files with 41 additions and 2 deletions
+2 -1
View File
@@ -286,7 +286,8 @@ impl ToString for Commit {
writeln!(buf, "{} {}", name, value.replace('\n', "\n ")).ok();
}
writeln!(buf).ok();
write!(buf, "{}", self.message).ok();
write!(buf, "{}", self.message.trim()).ok();
writeln!(buf).ok();
if !self.trailers.is_empty() {
writeln!(buf).ok();