8000 Introduce Repository.Info.Message · mm201/libgit2sharp@9dfa8c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9dfa8c1

Browse files
ethomsonnulltoken
authored andcommitted
Introduce Repository.Info.Message
1 parent 735a133 commit 9dfa8c1

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,30 @@ public void QueryingTheRemoteForADetachedHeadBranchReturnsNull()
477477
Assert.Null(trackLocal.Remote);
478478
}
479479
}
480+
481+
[Fact]
482+
public void ReadingEmptyRepositoryMessageReturnsNull()
483+
{
484+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
485+
486+
using (var repo = Repository.Init(scd.DirectoryPath))
487+
{
488+
Assert.Null(repo.Info.Message);
489+
}
490+
}
491+
492+
[Fact]
493+
public void CanReadRepositoryMessage()
494+
{
495+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
496+
string testMessage = "This is a test message!";
497+
498+
using (var repo = Repository.Init(scd.DirectoryPath))
499+
{
500+
File.WriteAllText(Path.Combine(repo.Info.Path, "MERGE_MSG"), testMessage);
501+
502+
Assert.Equal(testMessage, repo.Info.Message);
503+
}
504+
}
480505
}
481506
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,12 @@ internal static extern int git_repository_mergehead_foreach(
818818
git_repository_mergehead_foreach_cb cb,
819819
IntPtr payload);
820820

821+
[DllImport(libgit2)]
822+
internal static extern int git_repository_message(
823+
byte[] message_out,
824+
UIntPtr buffer_size,
825+
RepositorySafeHandle repository);
826+
821827
[DllImport(libgit2)]
822828
internal static extern int git_repository_odb(out ObjectDatabaseSafeHandle odb, RepositorySafeHandle repo);
823829

LibGit2Sharp/Core/Proxy.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,31 @@ public static ICollection<TResult> git_repository_mergehead_foreach<TResult>(
15151515
GitErrorCode.NotFound);
15161516
}
15171517

1518+
public static string git_repository_message(RepositorySafeHandle repo)
1519+
{
1520+
using (ThreadAffinity())
1521+
{
1522+
int bufSize = NativeMethods.git_repository_message(null, (UIntPtr)0, repo);
1523+
1524+
if (bufSize == (int)GitErrorCode.NotFound)
1525+
{
1526+
return null;
1527+
}
1528+
1529+
Ensure.Int32Result(bufSize);
1530+
1531+
byte[] buf = new byte[bufSize];
1532+
int len = NativeMethods.git_repository_message(buf, (UIntPtr)bufSize, repo);
1533+
1534+
if (len != bufSize)
1535+
{
1536+
throw new LibGit2SharpException("Repository message file changed as we were reading it");
1537+
}
1538+
1539+
return Utf8Marshaler.Utf8FromBuffer(buf);
1540+
}
1541+
}
1542+
15181543
public static ObjectDatabaseSafeHandle git_repository_odb(RepositorySafeHandle repo)
15191544
{
15201545
using (ThreadAffinity())

LibGit2Sharp/RepositoryInformation.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,13 @@ public virtual CurrentOperation CurrentOperation
7979
{
8080
get { return Proxy.git_repository_state(repo.Handle); }
8181
}
82+
83+
/// <summary>
84+
/// The message for a pending interactive operation.
85+
/// </summary>
86+
public virtual string Message
87+
{
88+
get { return Proxy.git_repository_message(repo.Handle); }
89+
}
8290
}
8391
}

0 commit comments

Comments
 (0)
0