@@ -233,33 +233,47 @@ public void Dispose()
233
233
/// Unset a configuration variable (key and value) in the local configuration.
234
234
/// </summary>
235
235
/// <param name="key">The key to unset.</param>
236
- public virtual void Unset ( string key )
236
+ public virtual bool Unset ( string key )
237
237
{
238
- Unset ( key , ConfigurationLevel . Local ) ;
238
+ return Unset ( key , ConfigurationLevel . Local ) ;
239
239
}
240
240
241
241
/// <summary>
242
242
/// Unset a configuration variable (key and value).
243
243
/// </summary>
244
244
/// <param name="key">The key to unset.</param>
245
245
/// <param name="level">The configuration file which should be considered as the target of this operation</param>
246
- public virtual void Unset ( string key , ConfigurationLevel level )
246
+ public virtual bool Unset ( string key , ConfigurationLevel level )
247
247
{
248
248
Ensure . ArgumentNotNullOrEmptyString ( key , "key" ) ;
249
249
250
250
using ( ConfigurationHandle h = RetrieveConfigurationHandle ( level , true , configHandle ) )
251
251
{
252
- Proxy . git_config_delete ( h , key ) ;
252
+ return Proxy . git_config_delete ( h , key ) ;
253
253
}
254
254
}
255
255
256
- internal void UnsetMultivar ( string key , ConfigurationLevel level )
256
+ /// <summary>
257
+ /// Unset a configuration values in a multivar variable (key and value) in the local configuration.
258
+ /// </summary>
259
+ /// <param name="key">The key to unset.</param>
260
+ public virtual bool UnsetAll ( string key )
261
+ {
262
+ return UnsetAll ( key , ConfigurationLevel . Local ) ;
263
+ }
264
+
265
+ /// <summary>
266
+ /// Unset all configuration values in a multivar variable (key and value).
267
+ /// </summary>
268
+ /// <param name="key">The key to unset.</param>
269
+ /// <param name="level">The configuration file which should be considered as the target of this operation</param>
270
+ public virtual bool UnsetAll ( string key , ConfigurationLevel level )
257
271
{
258
272
Ensure . ArgumentNotNullOrEmptyString ( key , "key" ) ;
259
273
260
274
using ( ConfigurationHandle h = RetrieveConfigurationHandle ( level , true , configHandle ) )
261
275
{
262
- Proxy . git_config_delete_multivar ( h , key ) ;
276
+ return Proxy . git_config_delete_multivar ( h , key ) ;
263
277
}
264
278
}
265
279
@@ -634,6 +648,60 @@ public virtual void Set<T>(string key, T value, ConfigurationLevel level)
634
648
}
635
649
}
636
650
651
+ /// <summary>
652
+ /// Adds a configuration value for a multivalue key in the local configuration. Keys are in the form 'section.name'.
653
+ /// <para>
654
+ /// For example in order to add the value for this in a .git\config file:
655
+ ///
656
+ /// [test]
657
+ /// plugin = first
658
+ ///
659
+ /// You would call:
660
+ ///
661
+ /// repo.Config.Add("test.plugin", "first");
662
+ /// </para>
663
+ /// </summary>
664
+ /// <typeparam name="T">The configuration value type</typeparam>
665
+ /// <param name="key">The key parts</param>
666
+ /// <param name="value">The value</param>
667
+ public virtual void Add < T > ( string key , T value )
668
+ {
669
+ Add ( key , value , ConfigurationLevel . Local ) ;
670
+ }
671
+
672
+ /// <summary>
673
+ /// Adds a configuration value for a multivalue key. Keys are in the form 'section.name'.
674
+ /// <para>
675
+ /// For example in order to add the value for this in a .git\config file:
676
+ ///
677
+ /// [test]
678
+ /// plugin = first
679
+ ///
680
+ /// You would call:
681
+ ///
682
+ /// repo.Config.Add("test.plugin", "first");
683
+ /// </para>
684
+ /// </summary>
685
+ /// <typeparam name="T">The configuration value type</typeparam>
686
+ /// <param name="key">The key parts</param>
687
+ /// <param name="value">The value</param>
688
+ /// <param name="level">The configuration file which should be considered as the target of this operation</param>
689
+ public virtual void Add < T > ( string key , T value , ConfigurationLevel level )
690
+ {
691
+ Ensure . ArgumentNotNull ( value , "value" ) ;
692
+ Ensure . ArgumentNotNullOrEmptyString ( key , "key" ) ;
693
+
694
+ using ( ConfigurationHandle h = RetrieveConfigurationHandle ( level , true , configHandle ) )
695
+ {
696
+ if ( ! configurationTypedAdder . ContainsKey ( typeof ( T ) ) )
697
+ {
698
+ throw new ArgumentException ( string . Format ( CultureInfo . InvariantCulture , "Generic Argument of type '{0}' is not supported." , typeof ( T ) . FullName ) ) ;
699
+ }
700
+
701
+ configurationTypedAdder [ typeof ( T ) ] ( key , value , h ) ;
702
+ }
703
+ }
704
+
637
705
/// <summary>
638
706
/// Find configuration entries matching <paramref name="regexp"/>.
639
707
/// </summary>
@@ -691,6 +759,11 @@ private static Action<string, object, ConfigurationHandle> GetUpdater<T>(Action<
691
759
{ typeof ( string ) , GetUpdater < string > ( Proxy . git_config_set_string ) } ,
692
760
} ;
693
761
762
+ private readonly static IDictionary < Type , Action < string , object , ConfigurationHandle > > configurationTypedAdder = new Dictionary < Type , Action < string , object , ConfigurationHandle > >
763
+ {
764
+ { typeof ( string ) , GetUpdater < string > ( Proxy . git_config_add_string ) } ,
765
+ } ;
766
+
694
767
/// <summary>
695
768
/// Returns an enumerator that iterates through the configuration entries.
696
769
/// </summary>
0 commit comments