Skip to content

Commit 6c891b7

Browse files
author
Ryan Roden-Corrent
committed
Merge SetConfigSearchPath and SetConfigSearchPaths.
Replace SetConfigSearchPath(level, string) and SetConfigSearchPaths(level, IEnumerable<string>) with a single function SetConfigSearchPaths(level, params string[]). Using params allows this to take one or more string arguments as well as accepting null to reset the paths (overloading the call to take parameters of either string or IEnumerable would have made null an ambiguous argument).
1 parent dcf3453 commit 6c891b7

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,18 @@ public void CanSetAndGetSearchPath()
417417
string systemPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
418418
string xdgPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
419419

420-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, globalPath);
421-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.System, systemPath);
422-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Xdg, xdgPath);
420+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, globalPath);
421+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, systemPath);
422+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, xdgPath);
423423

424424
Assert.Equal(globalPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global).Single());
425425
Assert.Equal(systemPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.System).Single());
426426
Assert.Equal(xdgPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Xdg).Single());
427427

428428
// reset the search paths to their defaults
429-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, null);
430-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.System, null);
431-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Xdg, null);
429+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
430+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, null);
431+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, null);
432432
}
433433

434434
[Fact]
@@ -477,7 +477,7 @@ public void CanRedirectConfigAccess()
477477
Touch(scd2.RootedDirectoryPath, ".gitconfig");
478478

479479
// redirect global access to the first path
480-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, scd1.RootedDirectoryPath);
480+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, scd1.RootedDirectoryPath);
481481

482482
// set a value in the first config
483483
using (var config = Configuration.BuildFrom(null))
@@ -487,7 +487,7 @@ public void CanRedirectConfigAccess()
487487
}
488488

489489
// redirect global config access to path2
490-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, scd2.RootedDirectoryPath);
490+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, scd2.RootedDirectoryPath);
491491

492492
// if the redirect succeeds, the value set in the prior config should not be visible
493493
using (var config = Configuration.BuildFrom(null))
@@ -496,7 +496,7 @@ public void CanRedirectConfigAccess()
496496
}
497497

498498
// reset the search path to the default
499-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, null);
499+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
500500
}
501501
}
502502
}

LibGit2Sharp/GlobalSettings.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,22 +215,12 @@ public static IEnumerable<string> GetConfigSearchPaths(ConfigurationLevel level)
215215
return Proxy.git_libgit2_opts_get_search_path(level).Split(Path.PathSeparator);
216216
}
217217

218-
/// <summary>
219-
/// Set the path under which libgit2 searches for the configuration file of a given level.
220-
/// </summary>
221-
/// <param name="level">The level (global/system/XDG) of the config.</param>
222-
/// <param name="path">The new search path, or null to reset to default.</param>
223-
public static void SetConfigSearchPath(ConfigurationLevel level, string path)
224-
{
225-
Proxy.git_libgit2_opts_set_search_path(level, path);
226-
}
227-
228218
/// <summary>
229219
/// Set the paths under which libgit2 searches for the configuration file of a given level.
230220
/// </summary>
231221
/// <param name="level">The level (global/system/XDG) of the config.</param>
232222
/// <param name="paths">The new search paths, or null to reset to default.</param>
233-
public static void SetConfigSearchPaths(ConfigurationLevel level, IEnumerable<string> paths)
223+
public static void SetConfigSearchPaths(ConfigurationLevel level, params string[] paths)
234224
{
235225
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);
236226
Proxy.git_libgit2_opts_set_search_path(level, pathString);

0 commit comments

Comments
 (0)