File tree 4 files changed +64
-0
lines changed 4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -477,5 +477,30 @@ public void QueryingTheRemoteForADetachedHeadBranchReturnsNull()
477
477
Assert . Null ( trackLocal . Remote ) ;
478
478
}
479
479
}
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
+ [
10000
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
+ }
480
505
}
481
506
}
Original file line number Diff line number Diff line change @@ -818,6 +818,12 @@ internal static extern int git_repository_mergehead_foreach(
818
818
git_repository_mergehead_foreach_cb cb ,
819
819
IntPtr payload ) ;
820
820
821
+ [ DllImport ( libgit2 ) ]
822
+ internal static extern int git_repository_message (
823
+ byte [ ] message_out ,
824
+ UIntPtr buffer_size ,
825
+ RepositorySafeHandle repository ) ;
826
+
821
827
[ DllImport ( libgit2 ) ]
822
828
internal static extern int git_repository_odb ( out ObjectDatabaseSafeHandle odb , RepositorySafeHandle repo ) ;
823
829
Original file line number Diff line number Diff line change @@ -1515,6 +1515,31 @@ public static ICollection<TResult> git_repository_mergehead_foreach<TResult>(
1515
1515
GitErrorCode . NotFound ) ;
1516
1516
}
1517
1517
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
+
1518
1543
public static ObjectDatabaseSafeHandle git_repository_odb ( RepositorySafeHandle repo )
1519
1544
{
1520
1545
using ( ThreadAffinity ( ) )
Original file line number Diff line number Diff line change @@ -79,5 +79,13 @@ public virtual CurrentOperation CurrentOperation
79
79
{
80
80
get { return Proxy . git_repository_state ( repo . Handle ) ; }
81
81
}
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
+ }
82
90
}
83
91
}
You can’t perform that action at this time.
0 commit comments