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 5
5
using LibGit2Sharp . Core ;
6
6
using LibGit2Sharp . Tests . TestHelpers ;
7
7
using Xunit ;
8
+ using Xunit . Extensions ;
8
9
9
10
namespace LibGit2Sharp . Tests
10
11
{
@@ -519,6 +520,27 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
519
520
}
520
521
}
521
522
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
+
522
544
[ Fact ]
523
545
public void CanCommitWithSignatureFromConfig ( )
524
546
{
Original file line number Diff line number Diff line change @@ -298,15 +298,27 @@ private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirector
298
298
/// <param name="signature">The signature to use for user.name and user.email</param>
299
299
/// <returns>The path to the configuration file</returns>
300
300
protected string CreateConfigurationWithDummyUser ( Signature signature )
301
+ {
302
+ return CreateConfigurationWithDummyUser ( signature . Name , signature . Email ) ;
303
+ }
304
+
305
+ protected string CreateConfigurationWithDummyUser ( string name , string email )
301
306
{
302
307
SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
303
308
Directory . CreateDirectory ( scd . DirectoryPath ) ;
304
309
string configFilePath = Path . Combine ( scd . DirectoryPath , "global-config" ) ;
305
310
306
311
using ( Configuration config = new Configuration ( configFilePath ) )
307
312
{
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
+ }
310
322
}
311
323
312
324
return configFilePath ;
You can’t perform that action at this time.
0 commit comments