Skip to content

Commit 77639ea

Browse files
committed
fixup! Simplify Configuration.Get() usage
1 parent 61e9f3b commit 77639ea

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void CanReadStringValue()
151151
using (var repo = new Repository(StandardTestRepoPath))
152152
{
153153
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote.origin.fetch"));
154-
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote", "origin", "fetch"));
154+
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote", "origin", "fetch", null));
155155
}
156156
}
157157

LibGit2Sharp/Configuration.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,37 @@ protected virtual void Dispose(bool disposing)
205205
return (T)configurationTypedRetriever[typeof(T)](key, defaultValue, handle);
206206
}
207207

208+
/// <summary>
209+
/// Get a configuration value for a key. Keys are in the form 'section.name'.
210+
/// <para>
211+
/// For example in order to get the value for this in a .git\config file:
212+
///
213+
/// <code>
214+
/// [core]
215+
/// bare = true
216+
/// </code>
217+
///
218+
/// You would call:
219+
///
220+
/// <code>
221+
/// bool isBare = repo.Config.Get&lt;bool&gt;("core", "bare", false);
222+
/// </code>
223+
/// </para>
224+
/// </summary>
225+
/// <typeparam name = "T">The configuration value type</typeparam>
226+
/// <param name = "firstKeyPart">The first key part</param>
227+
/// <param name = "secondKeyPart">The second key part</param>
228+
/// <param name = "defaultValue">The default value</param>
229+
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
230+
[Obsolete]
231+
public virtual T Get<T>(string firstKeyPart, string secondKeyPart, T defaultValue)
232+
{
233+
Ensure.ArgumentNotNull(firstKeyPart, "firstKeyPart");
234+
Ensure.ArgumentNotNull(secondKeyPart, "secondKeyPart");
235+
236+
return Get(new[] { firstKeyPart, secondKeyPart }, defaultValue);
237+
}
238+
208239
/// <summary>
209240
/// Get a configuration value for the given key parts.
210241
/// <para>
@@ -228,7 +259,7 @@ protected virtual void Dispose(bool disposing)
228259
/// <param name = "thirdKeyPart">The third key part</param>
229260
/// <param name = "defaultValue">The default value</param>
230261
/// <returns>The configuration value, or <c>defaultValue</c> if not set</returns>
231-
public virtual T Get<T>(string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue = default(T))
262+
public virtual T Get<T>(string firstKeyPart, string secondKeyPart, string thirdKeyPart, T defaultValue)
232263
{
233264
Ensure.ArgumentNotNull(firstKeyPart, "firstKeyPart");
234265
Ensure.ArgumentNotNull(secondKeyPart, "secondKeyPart");

0 commit comments

Comments
 (0)