@@ -324,6 +324,142 @@ public void GitConfiguration_GetString_SectionScopeProperty_DoesNotExists_Throws
324
324
Assert . Throws < KeyNotFoundException > ( ( ) => config . GetValue ( randomSection , randomScope , randomProperty ) ) ;
325
325
}
326
326
327
+ [ Fact ]
328
+ public void GitConfiguration_SetValue_Local_SetsLocalConfig ( )
329
+ {
330
+ string repoPath = CreateRepository ( out string workDirPath ) ;
331
+
332
+ string gitPath = GetGitPath ( ) ;
333
+ var trace = new NullTrace ( ) ;
334
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
335
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . Local ) ;
336
+
337
+ config . SetValue ( "core.foobar" , "foo123" ) ;
338
+
339
+ GitResult localResult = Git ( repoPath , workDirPath , "config --local core.foobar" ) ;
340
+
341
+ Assert . Equal ( "foo123" , localResult . StandardOutput . Trim ( ) ) ;
342
+ }
343
+
344
+ [ Fact ]
345
+ public void GitConfiguration_SetValue_All_ThrowsException ( )
346
+ {
347
+ string repoPath = CreateRepository ( out _ ) ;
348
+
349
+ string gitPath = GetGitPath ( ) ;
350
+ var trace = new NullTrace ( ) ;
351
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
352
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . All ) ;
353
+
354
+ Assert . Throws < InvalidOperationException > ( ( ) => config . SetValue ( "core.foobar" , "test123" ) ) ;
355
+ }
356
+
357
+ [ Fact ]
358
+ public void GitConfiguration_Unset_Global_UnsetsGlobalConfig ( )
359
+ {
360
+ string repoPath = CreateRepository ( out string workDirPath ) ;
361
+ try
362
+ {
363
+
364
+ Git ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
365
+ Git ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
366
+
367
+ string gitPath = GetGitPath ( ) ;
368
+ var trace = new NullTrace ( ) ;
369
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
370
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . Global ) ;
371
+
372
+ config . Unset ( "core.foobar" ) ;
373
+
374
+ GitResult globalResult = Git ( repoPath , workDirPath , "config --global core.foobar" ) ;
375
+ GitResult localResult = Git ( repoPath , workDirPath , "config --local core.foobar" ) ;
376
+
377
+ Assert . Equal ( string . Empty , globalResult . StandardOutput . Trim ( ) ) ;
378
+ Assert . Equal ( "bob" , localResult . StandardOutput . Trim ( ) ) ;
379
+ }
380
+ finally
381
+ {
382
+ // Cleanup global config changes
383
+ Git ( repoPath , workDirPath , "config --global --unset core.foobar" ) ;
384
+ }
385
+ }
386
+
387
+ [ Fact ]
388
+ public void GitConfiguration_Unset_Local_UnsetsLocalConfig ( )
389
+ {
390
+ string repoPath = CreateRepository ( out string workDirPath ) ;
391
+
392
+ try
393
+ {
394
+ Git ( repoPath , workDirPath , "config --global core.foobar alice" ) . AssertSuccess ( ) ;
395
+ Git ( repoPath , workDirPath , "config --local core.foobar bob" ) . AssertSuccess ( ) ;
396
+
397
+ string gitPath = GetGitPath ( ) ;
398
+ var trace = new NullTrace ( ) ;
399
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
400
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . Local ) ;
401
+
402
+ config . Unset ( "core.foobar" ) ;
403
+
404
+ GitResult globalResult = Git ( repoPath , workDirPath , "config --global core.foobar" ) ;
405
+ GitResult localResult = Git ( repoPath , workDirPath , "config --local core.foobar" ) ;
406
+
407
+ Assert . Equal ( "alice" , globalResult . StandardOutput . Trim ( ) ) ;
408
+ Assert . Equal ( string . Empty , localResult . StandardOutput . Trim ( ) ) ;
409
+ }
410
+ finally
411
+ {
412
+ // Cleanup global config changes
413
+ Git ( repoPath , workDirPath , "config --global --unset core.foobar" ) ;
414
+ }
415
+ }
416
+
417
+ [ Fact ]
418
+ public void GitConfiguration_Unset_All_ThrowsException ( )
419
+ {
420
+ string repoPath = CreateRepository ( out _ ) ;
421
+
422
+ string gitPath = GetGitPath ( ) ;
423
+ var trace = new NullTrace ( ) ;
424
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
425
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . All ) ;
426
+
427
+ Assert . Throws < InvalidOperationException > ( ( ) => config . Unset ( "core.foobar" ) ) ;
428
+ }
429
+
430
+ [ Fact ]
431
+ public void GitConfiguration_UnsetAll_UnsetsAllConfig ( )
432
+ {
433
+ string repoPath = CreateRepository ( out string workDirPath ) ;
434
+ Git ( repoPath , workDirPath , "config --local --add core.foobar foo1" ) . AssertSuccess ( ) ;
435
+ Git ( repoPath , workDirPath , "config --local --add core.foobar foo2" ) . AssertSuccess ( ) ;
436
+ Git ( repoPath , workDirPath , "config --local --add core.foobar bar1" ) . AssertSuccess ( ) ;
437
+
438
+ string gitPath = GetGitPath ( ) ;
439
+ var trace = new NullTrace ( ) ;
440
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
441
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . Local ) ;
442
+
443
+ config . UnsetAll ( "core.foobar" , "foo*" ) ;
444
+
445
+ GitResult result = Git ( repoPath , workDirPath , "config --local --get-all core.foobar" ) ;
446
+
447
+ Assert . Equal ( "bar1" , result . StandardOutput . Trim ( ) ) ;
448
+ }
449
+
450
+ [ Fact ]
451
+ public void GitConfiguration_UnsetAll_All_ThrowsException ( )
452
+ {
453
+ string repoPath = CreateRepository ( out _ ) ;
454
+
455
+ string gitPath = GetGitPath ( ) ;
456
+ var trace = new NullTrace ( ) ;
457
+ var git = new GitProcess ( trace , gitPath , repoPath ) ;
458
+ IGitConfiguration config = git . GetConfiguration ( GitConfigurationLevel . All ) ;
459
+
460
+ Assert . Throws < InvalidOperationException > ( ( ) => config . UnsetAll ( "core.foobar" , Constants . RegexPatterns . Any ) ) ;
461
+ }
462
+
327
463
#region Test helpers
328
464
329
465
private static string GetGitPath ( )
0 commit comments