Skip to content

Commit 430ab69

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 165456f commit 430ab69

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
@@ -483,6 +483,22 @@ public void CanResetSearchPaths()
483483
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
484484
}
485485

486+
[Fact]
487+
public void CanAppendToSearchPaths()
488+
{
489+
string appendMe = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
490+
var prevPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
491+
492+
// append using the special name $PATH
493+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, "$PATH", appendMe);
494+
495+
var currentPaths = GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global);
496+
Assert.Equal(currentPaths, prevPaths.Concat(new[] { appendMe }));
497+
498+
// set it back to the default
499+
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
500+
}
501+
486502
[Fact]
487503
public void CanRedirectConfigAccess()
488504
{

LibGit2Sharp/GlobalSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ public static IEnumerable<string> GetConfigSearchPaths(ConfigurationLevel level)
219219
/// Set the paths under which libgit2 searches for the configuration file of a given level.
220220
/// </summary>
221221
/// <param name="level">The level (global/system/XDG) of the config.</param>
222-
/// <param name="paths">The new search paths, or null to reset to default.</param>
222+
/// <param name="paths">
223+
/// The new search paths to set.
224+
/// Pass null to reset to the default.
225+
/// The special string "$PATH" will be substituted with the current search path.
226+
/// </param>
223227
public static void SetConfigSearchPaths(ConfigurationLevel level, params string[] paths)
224228
{
225229
var pathString = (paths == null) ? null : string.Join(Path.PathSeparator.ToString(), paths);

0 commit comments

Comments
 (0)