Skip to content

Expose message prettification #1306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,5 +1045,15 @@ public void CanNotAmendACommitInAWayThatWouldLeadTheNewCommitToBecomeEmpty()
new CommitOptions { AmendPreviousCommit = true }));
}
}

[Fact]
public void CanPrettifyAMessage()
{
string input = "# Comment\nA line that will remain\n# And another character\n\n\n";
string expected = "A line that will remain\n";

Assert.Equal(expected, Commit.PrettifyMessage(input, '#'));
Assert.Equal(expected, Commit.PrettifyMessage(input.Replace('#', ';'), ';'));
}
}
}
14 changes: 14 additions & 0 deletions LibGit2Sharp/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ private static string RetrieveEncodingOf(ObjectHandle obj)
return encoding ?? "UTF-8";
}

/// <summary>
/// Prettify a commit message
/// <para>
/// Remove comment lines and trailing lines
/// </para>
/// </summary>
/// <returns>The prettified message</returns>
/// <param name="message">The message to prettify.</param>
/// <param name="commentChar">Comment character. Lines starting with it will be removed</param>
public static string PrettifyMessage(string message, char commentChar)
{
return Proxy.git_message_prettify(message, commentChar);
}

private string DebuggerDisplay
{
get
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ public static string git_message_prettify(string message, char? commentChar)

using (var buf = new GitBuf())
{
int res = NativeMethods.git_message_prettify(buf, message, false, (sbyte)comment);
int res = NativeMethods.git_message_prettify(buf, message, true, (sbyte)comment);
Ensure.Int32Result(res);

return LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty;
Expand Down