public void Unbind(string orgName, bool local)
        {
            EnsureArgument.NotNullOrWhiteSpace(orgName, nameof(orgName));

            IGitConfiguration config = _git.GetConfiguration();

            string key = GetOrgUserKey(orgName);

            if (local)
            {
                _trace.WriteLine($"Unbinding organization '{orgName}' in local repository...");
                if (_git.IsInsideRepository())
                {
                    config.Unset(GitConfigurationLevel.Local, key);
                }
                else
                {
                    _trace.WriteLine("Cannot set local configuration binding - not inside a repository!");
                }
            }
            else
            {
                _trace.WriteLine($"Unbinding organization '{orgName}' in global configuration...");
                config.Unset(GitConfigurationLevel.Global, key);
            }
        }
        public void GitConfiguration_Unset_Local_UnsetsLocalConfig()
        {
            string repoPath = CreateRepository(out string workDirPath);

            try
            {
                Git(repoPath, workDirPath, "config --global core.foobar alice").AssertSuccess();
                Git(repoPath, workDirPath, "config --local core.foobar bob").AssertSuccess();

                string            gitPath = GetGitPath();
                var               trace   = new NullTrace();
                var               git     = new GitProcess(trace, gitPath, repoPath);
                IGitConfiguration config  = git.GetConfiguration(GitConfigurationLevel.Local);

                config.Unset("core.foobar");

                GitResult globalResult = Git(repoPath, workDirPath, "config --global core.foobar");
                GitResult localResult  = Git(repoPath, workDirPath, "config --local core.foobar");

                Assert.Equal("alice", globalResult.StandardOutput.Trim());
                Assert.Equal(string.Empty, localResult.StandardOutput.Trim());
            }
            finally
            {
                // Cleanup global config changes
                Git(repoPath, workDirPath, "config --global --unset core.foobar");
            }
        }
        public void EraseAuthority(string orgName)
        {
            EnsureArgument.NotNullOrWhiteSpace(orgName, nameof(orgName));

            _trace.WriteLine($"Removing cached authority for '{orgName}'...");
            IGitConfiguration config = _git.GetConfiguration();

            config.Unset(GitConfigurationLevel.Global, GetAuthorityKey(orgName));
        }
        public void GitConfiguration_Unset_All_ThrowsException()
        {
            string repoPath = CreateRepository(out _);

            string            gitPath = GetGitPath();
            var               trace   = new NullTrace();
            var               git     = new GitProcess(trace, gitPath, repoPath);
            IGitConfiguration config  = git.GetConfiguration(GitConfigurationLevel.All);

            Assert.Throws <InvalidOperationException>(() => config.Unset("core.foobar"));
        }
        public Task UnconfigureAsync(
            IEnvironment environment, EnvironmentVariableTarget environmentTarget,
            IGit git, GitConfigurationLevel configurationLevel)
        {
            string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}";

            Context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com...");

            IGitConfiguration targetConfig = git.GetConfiguration(configurationLevel);

            targetConfig.Unset(useHttpPathKey);

            return(Task.CompletedTask);
        }
        public Task UnconfigureAsync(ConfigurationTarget target)
        {
            string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}";

            _context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com...");

            GitConfigurationLevel configurationLevel = target == ConfigurationTarget.System
                ? GitConfigurationLevel.System
                : GitConfigurationLevel.Global;

            IGitConfiguration targetConfig = _context.Git.GetConfiguration(configurationLevel);

            targetConfig.Unset(useHttpPathKey);

            return(Task.CompletedTask);
        }
        public Task UnconfigureAsync(ConfigurationTarget target)
        {
            string helperKey      = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
            string useHttpPathKey = $"{KnownGitCfg.Credential.SectionName}.https://dev.azure.com.{KnownGitCfg.Credential.UseHttpPath}";

            _context.Trace.WriteLine("Clearing Git configuration 'credential.useHttpPath' for https://dev.azure.com...");

            GitConfigurationLevel configurationLevel = target == ConfigurationTarget.System
                ? GitConfigurationLevel.System
                : GitConfigurationLevel.Global;

            IGitConfiguration targetConfig = _context.Git.GetConfiguration();

            // On Windows, if there is a "manager-core" entry remaining in the system config then we must not clear
            // the useHttpPath option otherwise this would break the bundled version of GCM in Git for Windows.
            if (!PlatformUtils.IsWindows() || target != ConfigurationTarget.System ||
                targetConfig.GetAll(helperKey).All(x => !string.Equals(x, "manager-core")))
            {
                targetConfig.Unset(configurationLevel, useHttpPathKey);
            }

            return(Task.CompletedTask);
        }