Skip to content

Commit fa5e0fb

Browse files
committed
Preserve non-ASCII characters in commit messages
We weren't converting the commit message to UTF-8 before asking libgit2 to prettify it.
1 parent 3627335 commit fa5e0fb

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

LibGit2Sharp.Tests/ObjectDatabaseFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ public void CanCreateACommit()
264264

265265
Tree tree = repo.ObjectDatabase.CreateTree(td);
266266

267-
Commit commit = repo.ObjectDatabase.CreateCommit("message", DummySignature, DummySignature, tree, new[] { repo.Head.Tip });
267+
Commit commit = repo.ObjectDatabase.CreateCommit("Ü message", DummySignature, DummySignature, tree, new[] { repo.Head.Tip });
268268

269269
Branch newHead = repo.Head;
270270

271271
Assert.Equal(head, newHead);
272272
Assert.Equal(commit, repo.Lookup<Commit>(commit.Sha));
273+
Assert.Equal("Ü message\n", commit.Message);
273274
}
274275
}
275276
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ public static extern int git_merge_base(
373373
[DllImport(libgit2)]
374374
public static extern int git_message_prettify(
375375
byte[] message_out, // NB: This is more properly a StringBuilder, but it's UTF8
376-
int buffer_size,
377-
string message,
376+
int buffer_size,
377+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string message,
378378
bool strip_comments);
379379

380380
[DllImport(libgit2)]

0 commit comments

Comments
 (0)