Skip to content

Commit 0bb8d38

Browse files
committed
Expose message prettification
This is useful outside of our command-emulating methods, so let a user prettify as much as they want.
1 parent ef6a472 commit 0bb8d38

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,5 +1045,15 @@ public void CanNotAmendACommitInAWayThatWouldLeadTheNewCommitToBecomeEmpty()
10451045
new CommitOptions { AmendPreviousCommit = true }));
10461046
}
10471047
}
1048+
1049+
[Fact]
1050+
public void CanPrettifyAMessage()
1051+
{
1052+
string input = "# Comment\nA line that will remain\n# And another character\n\n\n";
1053+
string expected = "A line that will remain\n";
1054+
1055+
Assert.Equal(expected, Commit.PrettifyMessage(input, '#'));
1056+
Assert.Equal(expected, Commit.PrettifyMessage(input.Replace('#', ';'), ';'));
1057+
}
10481058
}
10491059
}

LibGit2Sharp/Commit.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ private static string RetrieveEncodingOf(ObjectHandle obj)
113113
return encoding ?? "UTF-8";
114114
}
115115

116+
/// <summary>
117+
/// Prettify a commit message
118+
/// <para>
119+
/// Remove comment lines and trailing lines
120+
/// </para>
121+
/// </summary>
122+
/// <returns>The prettified message</returns>
123+
/// <param name="message">The message to prettify.</param>
124+
/// <param name="commentChar">Comment character. Lines starting with it will be removed</param>
125+
public static string PrettifyMessage(string message, char commentChar)
126+
{
127+
return Proxy.git_message_prettify(message, commentChar);
128+
}
129+
116130
private string DebuggerDisplay
117131
{
118132
get

0 commit comments

Comments
 (0)