8000 Prevent ConfigurationFixture.CanSetGlobalStringValue test from failin… · Folcon/libgit2sharp@4cbb3c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4cbb3c3

Browse files
committed
Prevent ConfigurationFixture.CanSetGlobalStringValue test from failing when the location of the .gitconfig file should be retreived through the HOME environment variable
Should fix issue libgit2#82.
1 parent 5e5aaf8 commit 4cbb3c3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,32 @@ private static void AssertValueInConfigFile(string configFilePath, string regex)
2222
Assert.IsTrue(r.Success, text);
2323
}
2424

25+
private static string RetrieveGlobalConfigLocation()
26+
{
27+
string[] variables = { "HOME", "USERPROFILE", };
28+
29+
foreach (string variable in variables)
30+
{
31+
string potentialLocation = Environment.GetEnvironmentVariable(variable);
32+
if (string.IsNullOrEmpty(potentialLocation))
33+
{
34+
continue;
35+
}
36+
37+
string potentialPath = Path.Combine(potentialLocation, ".gitconfig");
38+
39+
if (File.Exists(potentialPath))
40+
{
41+
return potentialPath;
42+
}
43+
}
44+
45+
throw new InvalidOperationException("Unable to determine the location of '.gitconfig' file.");
46+
}
47+
2548
private static void AssertValueInGlobalConfigFile(string regex)
2649
{
27-
var configFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "../.gitconfig");
50+
string configFilePath = RetrieveGlobalConfigLocation();
2851
AssertValueInConfigFile(configFilePath, regex);
2952
}
3053

0 commit comments

Comments
 (0)
0