Skip to content

Commit 142b0dd

Browse files
author
Ryan Roden-Corrent
committed
Document and test $PATH for SetConfigSearchPaths.
When setting the config search path, the magic string $PATH refers to the current search path (useful for appending/prepending). Document and test this behavior in libgit2#. See: https://libgit2.github.com/libgit2/#HEAD/group/libgit2/git_libgit2_opts
1 parent 14dfe73 commit 142b0dd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,22 @@ public void CanResetSearchPaths()
505505
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
506506
}
507507

508+
[Fact]
509+
public void CanAppendToSearchPaths()
510+
{
511+
string appendMe = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
512+
var prevPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
513+
514+
// append using the special name $PATH
515+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, "$PATH", appendMe);
516+
517+
var currentPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
518+
Assert.Equal(currentPaths, prevPaths.Concat(new[] { appendMe }));
519+
520+
// set it back to the default
521+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
522+
}
523+
508524
[Fact]
509525
public void CanRedirectConfigAccess()
510526
{

LibGit2Sharp/GlobalSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ public static IEnumerable<string> GetConfigSearchPaths(ConfigurationLevel level)
288288
/// Set the paths under which libgit2 searches for the configuration file of a given level.
289289
/// </summary>
290290
/// <param name="level">The level (global/system/XDG) of the config.</param>
291-
/// <param name="paths">The new search paths, or null to reset to default.</param>
291+
/// <param name="paths">
292+
/// The new search paths to set.
293+
/// Pass null to reset to the default.
294+
/// The special string "$PATH" will be substituted with the current search path.
295+
/// </param>
292296
public static void SetConfigSearchPaths(ConfigurationLevel level, params string[] paths)
293297
{
294298
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);

0 commit comments

Comments
 (0)