Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors with 'git-credential-manager-core configure' with empty config #163

Merged
merged 3 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/shared/Microsoft.Git.CredentialManager.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ public void Settings_IsSecretTracingEnabled_EnvarFalsey_ReturnsFalse()
[Fact]
public void Settings_ProxyConfiguration_Unset_ReturnsNull()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -341,7 +340,6 @@ public void Settings_ProxyConfiguration_Unset_ReturnsNull()
[Fact]
public void Settings_ProxyConfiguration_GcmHttpConfig_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.HttpProxy;
Expand All @@ -366,7 +364,6 @@ public void Settings_ProxyConfiguration_GcmHttpConfig_ReturnsValue()
[Fact]
public void Settings_ProxyConfiguration_GcmHttpsConfig_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "https://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.HttpsProxy;
Expand All @@ -391,7 +388,6 @@ public void Settings_ProxyConfiguration_GcmHttpsConfig_ReturnsValue()
[Fact]
public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Http.SectionName;
const string property = Constants.GitConfiguration.Http.Proxy;
Expand All @@ -416,7 +412,6 @@ public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue()
[Fact]
public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -441,7 +436,6 @@ public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue()
[Fact]
public void Settings_ProxyConfiguration_CurlHttpsEnvar_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "https://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -466,7 +460,6 @@ public void Settings_ProxyConfiguration_CurlHttpsEnvar_ReturnsValue()
[Fact]
public void Settings_TryGetProxy_CurlAllEnvar_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "https://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -491,7 +484,6 @@ public void Settings_TryGetProxy_CurlAllEnvar_ReturnsValue()
[Fact]
public void Settings_ProxyConfiguration_LegacyGcmEnvar_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand Down Expand Up @@ -528,7 +520,6 @@ public void Settings_ProxyConfiguration_Precedence_ReturnsValue()
// 4. GCM proxy environment variable (deprecated)
// GCM_HTTP_PROXY

const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand Down Expand Up @@ -567,7 +558,6 @@ void RunTest(Uri expectedValue)
[Fact]
public void Settings_ProviderOverride_Unset_ReturnsNull()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -586,7 +576,6 @@ public void Settings_ProviderOverride_Unset_ReturnsNull()
[Fact]
public void Settings_ProviderOverride_EnvarSet_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -610,7 +599,6 @@ public void Settings_ProviderOverride_EnvarSet_ReturnsValue()
[Fact]
public void Settings_ProviderOverride_ConfigSet_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.Provider;
Expand All @@ -634,7 +622,6 @@ public void Settings_ProviderOverride_ConfigSet_ReturnsValue()
[Fact]
public void Settings_ProviderOverride_EnvarAndConfigSet_ReturnsEnvarValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.Provider;
Expand Down Expand Up @@ -662,7 +649,6 @@ public void Settings_ProviderOverride_EnvarAndConfigSet_ReturnsEnvarValue()
[Fact]
public void Settings_LegacyAuthorityOverride_Unset_ReturnsNull()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -681,7 +667,6 @@ public void Settings_LegacyAuthorityOverride_Unset_ReturnsNull()
[Fact]
public void Settings_LegacyAuthorityOverride_EnvarSet_ReturnsValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
var remoteUri = new Uri(remoteUrl);

Expand All @@ -705,7 +690,6 @@ public void Settings_LegacyAuthorityOverride_EnvarSet_ReturnsValue()
[Fact]
public void Settings_LegacyAuthorityOverride_ConfigSet_ReturnsTrueOutValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.Authority;
Expand All @@ -729,7 +713,6 @@ public void Settings_LegacyAuthorityOverride_ConfigSet_ReturnsTrueOutValue()
[Fact]
public void Settings_LegacyAuthorityOverride_EnvarAndConfigSet_ReturnsEnvarValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string section = Constants.GitConfiguration.Credential.SectionName;
const string property = Constants.GitConfiguration.Credential.Authority;
Expand Down Expand Up @@ -757,7 +740,6 @@ public void Settings_LegacyAuthorityOverride_EnvarAndConfigSet_ReturnsEnvarValue
[Fact]
public void Settings_TryGetSetting_EnvarSet_ReturnsTrueOutValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string envarName = "GCM_TESTVAR";
const string section = "gcmtest";
Expand Down Expand Up @@ -785,7 +767,6 @@ public void Settings_TryGetSetting_EnvarSet_ReturnsTrueOutValue()
[Fact]
public void Settings_TryGetSetting_EnvarUnset_ReturnsFalse()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string envarName = "GCM_TESTVAR";
const string section = "gcmtest";
Expand All @@ -808,7 +789,6 @@ public void Settings_TryGetSetting_EnvarUnset_ReturnsFalse()
[Fact]
public void Settings_TryGetSetting_GlobalConfig_ReturnsTrueAndValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string envarName = "GCM_TESTVAR";
const string section = "gcmtest";
Expand All @@ -834,7 +814,6 @@ public void Settings_TryGetSetting_GlobalConfig_ReturnsTrueAndValue()
[Fact]
public void Settings_TryGetSetting_RepoConfig_ReturnsTrueAndValue()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string envarName = "GCM_TESTVAR";
const string section = "gcmtest";
Expand All @@ -860,7 +839,6 @@ public void Settings_TryGetSetting_RepoConfig_ReturnsTrueAndValue()
[Fact]
public void Settings_TryGetSetting_ScopedConfig()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo/bar/bazz.git";
const string scope1 = "example.com";
const string scope2 = "example.com/foo/bar";
Expand Down Expand Up @@ -890,7 +868,6 @@ public void Settings_TryGetSetting_ScopedConfig()
[Fact]
public void Settings_TryGetSetting_EnvarAndConfig_EnvarTakesPrecedence()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string envarName = "GCM_TESTVAR";
const string section = "gcmtest";
Expand Down Expand Up @@ -920,7 +897,6 @@ public void Settings_TryGetSetting_EnvarAndConfig_EnvarTakesPrecedence()
[Fact]
public void Settings_GetSettingValues_EnvarAndMultipleConfig_ReturnsAllWithCorrectPrecedence()
{
const string repositoryPath = "/tmp/repos/foo/.git";
const string remoteUrl = "http://example.com/foo.git";
const string scope1 = "http://example.com";
const string scope2 = "example.com";
Expand Down
10 changes: 7 additions & 3 deletions src/shared/Microsoft.Git.CredentialManager/GitConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void Enumerate(GitConfigurationEnumerationCallback cb)
{
string[] kvp = entry.Split(new[]{'\n'}, count: 2);

if (!cb(kvp[0], kvp[1]))
if (kvp.Length == 2 && !cb(kvp[0], kvp[1]))
{
break;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public bool TryGetValue(string name, out string value)
public void SetValue(string name, string value)
{
string level = GetLevelFilterArg();
using (Process git = _git.CreateProcess($"config {level} {name} {value}"))
using (Process git = _git.CreateProcess($"config {level} {name} \"{value}\""))
{
git.Start();
git.WaitForExit();
Expand Down Expand Up @@ -212,6 +212,7 @@ public IEnumerable<string> GetRegex(string nameRegex, string valueRegex)
switch (git.ExitCode)
{
case 0: // OK
case 1: // No results
break;
default:
throw new Exception(
Expand All @@ -226,7 +227,9 @@ public IEnumerable<string> GetRegex(string nameRegex, string valueRegex)
{
string[] kvp = entry.Split(new[]{'\n'}, count: 2);

yield return kvp[1];
if (kvp.Length == 2) {
yield return kvp[1];
}
}
}
}
Expand Down Expand Up @@ -261,6 +264,7 @@ public void UnsetAll(string name, string valueRegex)
switch (git.ExitCode)
{
case 0: // OK
case 5: // Trying to unset a value that does not exist
break;
default:
throw new Exception(
Expand Down