Skip to content

Commit edfb863

Browse files
authored
Merge pull request #215 from mjcheetham/config-empty-fix
Fix reading of empty string Git configuration values
2 parents df90676 + b1aeedb commit edfb863

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/shared/Microsoft.Git.CredentialManager/GitConfiguration.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void Enumerate(GitConfigurationEnumerationCallback cb)
146146
public bool TryGet(string name, out string value)
147147
{
148148
string level = GetLevelFilterArg();
149-
using (Process git = _git.CreateProcess($"config {level} {QuoteCmdArg(name)}"))
149+
using (Process git = _git.CreateProcess($"config --null {level} {QuoteCmdArg(name)}"))
150150
{
151151
git.Start();
152152
git.WaitForExit();
@@ -164,16 +164,16 @@ public bool TryGet(string name, out string value)
164164
return false;
165165
}
166166

167-
string data = git.StandardOutput.ReadToEnd().TrimEnd('\n');
168-
169-
if (string.IsNullOrWhiteSpace(data))
167+
string data = git.StandardOutput.ReadToEnd();
168+
string[] entries = data.Split('\0');
169+
if (entries.Length > 0)
170170
{
171-
value = null;
172-
return false;
171+
value = entries[0];
172+
return true;
173173
}
174174

175-
value = data;
176-
return true;
175+
value = null;
176+
return false;
177177
}
178178
}
179179

@@ -320,7 +320,8 @@ public IEnumerable<string> GetRegex(string nameRegex, string valueRegex)
320320
{
321321
string[] kvp = entry.Split(new[]{'\n'}, count: 2);
322322

323-
if (kvp.Length == 2) {
323+
if (kvp.Length == 2)
324+
{
324325
yield return kvp[1];
325326
}
326327
}

0 commit comments

Comments
 (0)