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
newCommitOptions{AmendPreviousCommit=true}));
10461046
}
10471047
}
1048+
1049+
[Fact]
1050+
publicvoidCanPrettifyAMessage()
1051+
{
1052+
stringinput="# Comment\nA line that will remain\n# And another character\n\n\n";
1053+
stringexpected="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
returnencoding??"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+
publicstaticstringPrettifyMessage(stringmessage,charcommentChar)
126+
{
127+
returnProxy.git_message_prettify(message,commentChar);
128+
}
129+
116130
privatestringDebuggerDisplay
117131
{
118132
get

0 commit comments

Comments
(0)