Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b26f36

Browse files
shiftkeynulltoken
authored andcommitted
Drop optional parameters in Configuration.cs
1 parent 4277559 commit 9b26f36

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public void CanSetBooleanValue()
256256
[Fact]
257257
public void SettingLocalConfigurationOutsideAReposThrows()
258258
{
259-
using (var config = new Configuration())
259+
using (var config = new Configuration(null, null, null))
260260
{
261261
Assert.Throws<LibGit2SharpException>(() => config.Set("unittests.intsetting", 3));
262262
}

LibGit2Sharp/Configuration.cs

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,30 @@ private void Init()
7373
}
7474
}
7575

76+
/// <summary>
77+
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
78+
/// </summary>
79+
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
80+
public Configuration(string globalConfigurationFileLocation)
81+
: this(null, globalConfigurationFileLocation, null, null)
82+
{ }
83+
84+
/// <summary>
85+
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
86+
/// </summary>
87+
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
88+
/// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param>
89+
public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation)
90+
: this(null, globalConfigurationFileLocation, xdgConfigurationFileLocation, null)
91+
{ }
92+
7693
/// <summary>
7794
/// Access configuration values without a repository. Generally you want to access configuration via an instance of <see cref="Repository"/> instead.
7895
/// </summary>
7996
/// <param name="globalConfigurationFileLocation">Path to a Global configuration file. If null, the default path for a global configuration file will be probed.</param>
8097
/// <param name="xdgConfigurationFileLocation">Path to a XDG configuration file. If null, the default path for a XDG configuration file will be probed.</param>
8198
/// <param name="systemConfigurationFileLocation">Path to a System configuration file. If null, the default path for a system configuration file will be probed.</param>
82-
public Configuration(string globalConfigurationFileLocation = null, string xdgConfigurationFileLocation = null, string systemConfigurationFileLocation = null)
99+
public Configuration(string globalConfigurationFileLocation, string xdgConfigurationFileLocation, string systemConfigurationFileLocation)
83100
: this(null, globalConfigurationFileLocation, xdgConfigurationFileLocation, systemConfigurationFileLocation)
84101
{
85102
}
@@ -110,12 +127,21 @@ public void Dispose()
110127

111128
#endregion
112129

130+
/// <summary>
131+
/// Unset a configuration variable (key and value) in the local configuration.
132+
/// </summary>
133+
/// <param name="key">The key to unset.</param>
134+
public virtual void Unset(string key)
135+
{
136+
Unset(key, ConfigurationLevel.Local);
137+
}
138+
113139
/// <summary>
114140
/// Unset a configuration variable (key and value).
115141
/// </summary>
116142
/// <param name="key">The key to unset.</param>
117143
/// <param name="level">The configuration file which should be considered as the target of this operation</param>
118-
public virtual void Unset(string key, ConfigurationLevel level = ConfigurationLevel.Local)
144+
public virtual void Unset(string key, ConfigurationLevel level)
119145
{
120146
Ensure.ArgumentNotNullOrEmptyString(key, "key");
121147

@@ -209,6 +235,27 @@ public virtual ConfigurationEntry<T> Get<T>(string key, ConfigurationLevel level
209235
}
210236
}
211237

238+
/// <summary>
239+
/// Set a configuration value for a key in the local configuration. Keys are in the form 'section.name'.
240+
/// <para>
241+
/// For example in order to set the value for this in a .git\config file:
242+
///
243+
/// [test]
244+
/// boolsetting = true
245+
///
246+
/// You would call:
247+
///
248+
/// repo.Config.Set("test.boolsetting", true);
249+
/// </para>
250+
/// </summary>
251+
/// <typeparam name="T">The configuration value type</typeparam>
252+
/// <param name="key">The key parts</param>
253+
/// <param name="value">The value</param>
254+
public virtual void Set<T>(string key, T value)
255+
{
256+
Set(key, value, ConfigurationLevel.Local);
257+
}
258+
212259
/// <summary>
213260
/// Set a configuration value for a key. Keys are in the form 'section.name'.
214261
/// <para>
@@ -226,7 +273,7 @@ public virtual ConfigurationEntry<T> Get<T>(string key, ConfigurationLevel level
226273
/// <param name="key">The key parts</param>
227274
/// <param name="value">The value</param>
228275
/// <param name="level">The configuration file which should be considered as the target of this operation</param>
229-
public virtual void Set<T>(string key, T value, ConfigurationLevel level = ConfigurationLevel.Local)
276+
public virtual void Set<T>(string key, T value, ConfigurationLevel level)
230277
{
231278
Ensure.ArgumentNotNull(value, "value");
232279
Ensure.ArgumentNotNullOrEmptyString(key, "key");
@@ -242,14 +289,23 @@ public virtual void Set<T>(string key, T value, ConfigurationLevel level = Confi
242289
}
243290
}
244291

292+
/// <summary>
293+
/// Find configuration entries matching <paramref name="regexp"/>.
294+
/// </summary>
295+
/// <param name="regexp">A regular expression.</param>
296+
/// <returns>Matching entries.</returns>
297+
public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp)
298+
{
299+
return Find(regexp, ConfigurationLevel.Local);
300+
}
301+
245302
/// <summary>
246303
/// Find configuration entries matching <paramref name="regexp"/>.
247304
/// </summary>
248305
/// <param name="regexp">A regular expression.</param>
249306
/// <param name="level">The configuration file into which the key should be searched for.</param>
250307
/// <returns>Matching entries.</returns>
251-
public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp,
252-
ConfigurationLevel level = ConfigurationLevel.Local)
308+
public virtual IEnumerable<ConfigurationEntry<string>> Find(string regexp, ConfigurationLevel level)
253309
{
254310
Ensure.ArgumentNotNullOrEmptyString(regexp, "regexp");
255311

0 commit comments

Comments
 (0)