Skip to content

Commit 633a021

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 146cccc commit 633a021

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
@@ -439,18 +439,18 @@ public void CanSetAndGetSearchPath()
439439
string systemPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
440440
string xdgPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
441441

442-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, globalPath);
443-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.System, systemPath);
444-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Xdg, xdgPath);
442+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, globalPath);
443+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, systemPath);
444+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, xdgPath);
445445

446446
Assert.Equal(globalPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global).Single());
447447
Assert.Equal(systemPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.System).Single());
448448
Assert.Equal(xdgPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Xdg).Single());
449449

450450
// reset the search paths to their defaults
451-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, null);
452-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.System, null);
453-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Xdg, null);
451+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
452+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, null);
453+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, null);
454454
}
455455

456456
[Fact]
@@ -499,7 +499,7 @@ public void CanRedirectConfigAccess()
499499
Touch(scd2.RootedDirectoryPath, ".gitconfig");
500500

501501
// redirect global access to the first path
502-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, scd1.RootedDirectoryPath);
502+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, scd1.RootedDirectoryPath);
503503

504504
// set a value in the first config
505505
using (var config = Configuration.BuildFrom(null))
@@ -509,7 +509,7 @@ public void CanRedirectConfigAccess()
509509
}
510510

511511
// redirect global config access to path2
512-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, scd2.RootedDirectoryPath);
512+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, scd2.RootedDirectoryPath);
513513

514514
// if the redirect succeeds, the value set in the prior config should not be visible
515515
using (var config = Configuration.BuildFrom(null))
@@ -518,7 +518,7 @@ public void CanRedirectConfigAccess()
518518
}
519519

520520
// reset the search path to the default
521-
GlobalSettings.SetConfigSearchPath(ConfigurationLevel.Global, null);
521+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
522522
}
523523
}
524524
}

LibGit2Sharp/GlobalSettings.cs

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

287-
/// <summary>
288-
/// Set the path under which libgit2 searches for the configuration file of a given level.
289-
/// </summary>
290-
/// <param name="level">The level (global/system/XDG) of the config.</param>
291-
/// <param name="path">The new search path, or null to reset to default.</param>
292-
public static void SetConfigSearchPath(ConfigurationLevel level, string path)
293-
{
294-
Proxy.git_libgit2_opts_set_search_path(level, path);
295-
}
296-
297287
/// <summary>
298288
/// Set the paths under which libgit2 searches for the configuration file of a given level.
299289
/// </summary>
300290
/// <param name="level">The level (global/system/XDG) of the config.</param>
301291
/// <param name="paths">The new search paths, or null to reset to default.</param>
302-
public static void SetConfigSearchPaths(ConfigurationLevel level, IEnumerable<string> paths)
292+
public static void SetConfigSearchPaths(ConfigurationLevel level, params string[] paths)
303293
{
304294
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);
305295
Proxy.git_libgit2_opts_set_search_path(level, pathString);

0 commit comments

Comments
 (0)