@@ -1057,10 +1057,7 @@ public void CanPrettifyAMessage()
10571057 Assert . Equal ( expected , Commit . PrettifyMessage ( input . Replace ( '#' , ';' ) , ';' ) ) ;
10581058 }
10591059
1060- [ Fact ]
1061- public void CanExtractSignatureFromCommit ( )
1062- {
1063- string commitData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1060+ private readonly string signedCommit = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
10641061parent 34734e478d6cf50c27c9d69026d93974d052c454
10651062author Ben Burkert <ben@benburkert.com> 1358451456 -0800
10661063committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
@@ -1085,7 +1082,7 @@ committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
10851082a simple commit which works
10861083" ;
10871084
1088- string signatureData = @"-----BEGIN PGP SIGNATURE-----
1085+ private readonly string signatureData = @"-----BEGIN PGP SIGNATURE-----
10891086Version: GnuPG v1.4.12 (Darwin)
10901087
10911088iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
@@ -1103,19 +1100,23 @@ a simple commit which works
11031100=ozeK
11041101-----END PGP SIGNATURE-----" ;
11051102
1106- string signedData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
1103+ private readonly string signedData = @"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6
11071104parent 34734e478d6cf50c27c9d69026d93974d052c454
11081105author Ben Burkert <ben@benburkert.com> 1358451456 -0800
11091106committer Ben Burkert <ben@benburkert.com> 1358451456 -0800
11101107
11111108a simple commit which works
11121109" ;
11131110
1111+
1112+ [ Fact ]
1113+ public void CanExtractSignatureFromCommit ( )
1114+ {
11141115 string repoPath = InitNewRepository ( ) ;
11151116 using ( var repo = new Repository ( repoPath ) )
11161117 {
11171118 var odb = repo . ObjectDatabase ;
1118- var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( commitData ) ) ;
1119+ var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( signedCommit ) ) ;
11191120
11201121 // Look up the commit to make sure we wrote something valid
11211122 var commit = repo . Lookup < Commit > ( signedId ) ;
@@ -1124,6 +1125,48 @@ a simple commit which works
11241125 var signatureInfo = Commit . ExtractSignature ( repo , signedId , "gpgsig" ) ;
11251126 Assert . Equal ( signedData , signatureInfo . SignedData ) ;
11261127 Assert . Equal ( signatureData , signatureInfo . Signature ) ;
1128+
1129+ signatureInfo = Commit . ExtractSignature ( repo , signedId ) ;
1130+ Assert . Equal ( signedData , signatureInfo . SignedData ) ;
1131+ Assert . Equal ( signatureData , signatureInfo . Signature ) ;
1132+ }
1133+ }
1134+
1135+ [ Fact ]
1136+ public void CanCreateACommitString ( )
1137+ {
1138+ string repoPath = SandboxStandardTestRepo ( ) ;
1139+ using ( var repo = new Repository ( repoPath ) )
1140+ {
1141+ var tipCommit = repo . Head . Tip ;
1142+ var recreatedCommit = Commit . CreateBuffer (
1143+ tipCommit . Author ,
1144+ tipCommit . Committer ,
1145+ tipCommit . Message ,
1146+ tipCommit . Tree ,
1147+ tipCommit . Parents ,
1148+ false , null ) ;
1149+
1150+ var recreatedId = repo . ObjectDatabase . Write < Commit > ( Encoding . UTF8 . GetBytes ( recreatedCommit ) ) ;
1151+ Assert . Equal ( tipCommit . Id , recreatedId ) ;
1152+ }
1153+ }
1154+
1155+ [ Fact ]
1156+ public void CanCreateASignedCommit ( )
1157+ {
1158+ string repoPath = InitNewRepository ( ) ;
1159+ using ( var repo = new Repository ( repoPath ) )
1160+ {
1161+ var odb = repo . ObjectDatabase ;
1162+ var signedId = odb . Write < Commit > ( Encoding . UTF8 . GetBytes ( signedCommit ) ) ;
1163+ var signedId2 = odb . CreateCommitWithSignature ( signedData , signatureData ) ;
1164+
1165+ Assert . Equal ( signedId , signedId2 ) ;
1166+
1167+ var signatureInfo = Commit . ExtractSignature ( repo , signedId2 ) ;
1168+ Assert . Equal ( signedData , signatureInfo . SignedData ) ;
1169+ Assert . Equal ( signatureData , signatureInfo . Signature ) ;
11271170 }
11281171 }
11291172 }
0 commit comments