File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 55using LibGit2Sharp . Core ;
66using LibGit2Sharp . Tests . TestHelpers ;
77using Xunit ;
8+ using Xunit . Extensions ;
89
910namespace LibGit2Sharp . Tests
1011{
@@ -519,6 +520,27 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
519520 }
520521 }
521522
523+ [ Theory ]
524+ [ InlineData ( null , "x@example.com" ) ]
525+ [ InlineData ( "" , "x@example.com" ) ]
526+ [ InlineData ( "X" , null ) ]
527+ [ InlineData ( "X" , "" ) ]
528+ public void CommitWithInvalidSignatureConfigThrows ( string name , string email )
529+ {
530+ string repoPath = InitNewRepository ( ) ;
531+ string configPath = CreateConfigurationWithDummyUser ( name , email ) ;
532+ var options = new RepositoryOptions { GlobalConfigurationLocation = configPath } ;
533+
534+ using ( var repo = new Repository ( repoPath , options ) )
535+ {
536+ Assert . Equal ( name , repo . Config . GetValueOrDefault < string > ( "user.name" ) ) ;
537+ Assert . Equal ( email , repo . Config . GetValueOrDefault < string > ( "user.email" ) ) ;
538+
539+ Assert . Throws < LibGit2SharpException > (
540+ ( ) => repo . Commit ( "Initial egotistic commit" , new CommitOptions { AllowEmptyCommit = true } ) ) ;
541+ }
542+ }
543+
522544 [ Fact ]
523545 public void CanCommitWithSignatureFromConfig ( )
524546 {
Original file line number Diff line number Diff line change @@ -298,15 +298,27 @@ private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirector
298298 /// <param name="signature">The signature to use for user.name and user.email</param>
299299 /// <returns>The path to the configuration file</returns>
300300 protected string CreateConfigurationWithDummyUser ( Signature signature )
301+ {
302+ return CreateConfigurationWithDummyUser ( signature . Name , signature . Email ) ;
303+ }
304+
305+ protected string CreateConfigurationWithDummyUser ( string name , string email )
301306 {
302307 SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
303308 Directory . CreateDirectory ( scd . DirectoryPath ) ;
304309 string configFilePath = Path . Combine ( scd . DirectoryPath , "global-config" ) ;
305310
306311 using ( Configuration config = new Configuration ( configFilePath ) )
307312 {
308- config . Set ( "user.name" , signature . Name , ConfigurationLevel . Global ) ;
309- config . Set ( "user.email" , signature . Email , ConfigurationLevel . Global ) ;
313+ if ( name != null )
314+ {
315+ config . Set ( "user.name" , name , ConfigurationLevel . Global ) ;
316+ }
317+
318+ if ( email != null )
319+ {
320+ config . Set ( "user.email" , email , ConfigurationLevel . Global ) ;
321+ }
310322 }
311323
312324 return configFilePath ;
You can’t perform that action at this time.
0 commit comments