Skip to content

Commit b764f67

Browse files
committed
Use git_commit_message_raw to rewrite commits with leading newlines in commit message
1 parent 50d6978 commit b764f67

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

LibGit2Sharp/Commit.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Commit : GitObject
2121
private readonly ILazy<Signature> lazyAuthor;
2222
private readonly ILazy<Signature> lazyCommitter;
2323
private readonly ILazy<string> lazyMessage;
24+
private readonly ILazy<string> lazyMessageRaw;
2425
private readonly ILazy<string> lazyMessageShort;
2526
private readonly ILazy<string> lazyEncoding;
2627

@@ -43,6 +44,7 @@ internal Commit(Repository repo, ObjectId id)
4344
lazyCommitter = group1.AddLazy(Proxy.git_commit_committer);
4445
group2 = new GitObjectLazyGroup(this.repo, id);
4546
lazyMessage = group2.AddLazy(Proxy.git_commit_message);
47+
lazyMessageRaw = group2.AddLazy(Proxy.git_commit_message_raw);
4648
lazyMessageShort = group2.AddLazy(Proxy.git_commit_summary);
4749
lazyEncoding = group2.AddLazy(RetrieveEncodingOf);
4850

@@ -66,6 +68,11 @@ public virtual TreeEntry this[string relativePath]
6668
/// </summary>
6769
public virtual string Message { get { return lazyMessage.Value; } }
6870

71+
/// <summary>
72+
/// Gets the raw, unmodified commit message.
73+
/// </summary>
74+
public virtual string MessageRaw { get { return lazyMessageRaw.Value; } }
75+
6976
/// <summary>
7077
/// Gets the short commit message which is usually the first line of the commit.
7178
/// </summary>

LibGit2Sharp/CommitRewriteInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static CommitRewriteInfo From(Commit commit)
3131
{
3232
Author = commit.Author,
3333
Committer = commit.Committer,
34-
Message = commit.Message
34+
Message = commit.MessageRaw
3535
};
3636
}
3737

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ internal static extern unsafe int git_commit_create_with_signature(
422422
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
423423
internal static extern unsafe string git_commit_message(git_object* commit);
424424

425+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
426+
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
427+
internal static extern unsafe string git_commit_message_raw(git_object* commit);
428+
425429
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
426430
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))]
427431
internal static extern unsafe string git_commit_summary(git_object* commit);

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ public static unsafe string git_commit_message(ObjectHandle obj)
388388
return NativeMethods.git_commit_message(obj);
389389
}
390390

391+
public static unsafe string git_commit_message_raw(ObjectHandle obj)
392+
{
393+
return NativeMethods.git_commit_message_raw(obj);
394+
}
395+
391396
public static unsafe string git_commit_summary(ObjectHandle obj)
392397
{
393398
return NativeMethods.git_commit_summary(obj);

0 commit comments

Comments
 (0)