예제 #1
0
        public bool SetGitConfig(List<GitInstallation> installations, GitConfigAction action, ConfigurationLevel type, out ConfigurationLevel updated)
        {
            Git.Trace.WriteLine($"action = '{action}'.");

            updated = ConfigurationLevel.None;

            if ((installations == null || installations.Count == 0) && !Where.FindGitInstallations(out installations))
            {
                Git.Trace.WriteLine("No Git installations detected to update.");
                return false;
            }

            if ((type & ConfigurationLevel.Global) == ConfigurationLevel.Global)
            {
                // the 0 entry in the installations list is the "preferred" instance of Git
                string gitCmdPath = installations[0].Git;
                string globalCmd = action == GitConfigAction.Set
                    ? "config --global credential.helper manager"
                    : "config --global --unset credential.helper";

                if (ExecuteGit(gitCmdPath, globalCmd, 0, 5))
                {
                    Git.Trace.WriteLine("updating ~/.gitconfig succeeded.");

                    updated |= ConfigurationLevel.Global;
                }
                else
                {
                    Git.Trace.WriteLine("updating ~/.gitconfig failed.");

                    Console.Out.WriteLine();
                    Console.Error.WriteLine("Fatal: Unable to update ~/.gitconfig.");
                    Pause();
                    return false;
                }
            }

            if ((type & ConfigurationLevel.System) == ConfigurationLevel.System)
            {
                string systemCmd = action == GitConfigAction.Set
                    ? "config --system credential.helper manager"
                    : "config --system --unset credential.helper";

                int successCount = 0;

                foreach (var installation in installations)
                {
                    if (ExecuteGit(installation.Git, systemCmd, 0, 5))
                    {
                        Git.Trace.WriteLine("updating /etc/gitconfig succeeded.");

                        successCount++;
                    }
                    else
                    {
                        Git.Trace.WriteLine("updating ~/.gitconfig failed.");
                    }
                }

                if (successCount == installations.Count)
                {
                    updated |= ConfigurationLevel.System;
                }
                else
                {
                    return false;
                }
            }

            return true;
        }
        public bool SetGitConfig(List<GitInstallation> installations, GitConfigAction action, Configuration.Type type, out Configuration.Type updated)
        {
            Trace.WriteLine("Installer::SetGitConfig");
            Trace.WriteLine("   action = " + action + ".");

            updated = Configuration.Type.None;

            if ((installations == null || installations.Count == 0) && !Where.FindGitInstallations(out installations))
            {
                Trace.WriteLine("   No Git installations detected to update.");
                return false;
            }

            if ((type & Configuration.Type.Global) == Configuration.Type.Global)
            {
                // the 0 entry in the installations list is the "preferred" instance of Git
                string gitCmdPath = installations[0].Git;
                string globalCmd = action == GitConfigAction.Set
                    ? "config --global credential.helper manager"
                    : "config --global --unset credential.helper";

                if (ExecuteGit(gitCmdPath, globalCmd, 0, 5))
                {
                    Trace.WriteLine("   updating ~/.gitconfig succeeded.");

                    updated |= Configuration.Type.Global;
                }
                else
                {
                    Trace.WriteLine("   updating ~/.gitconfig failed.");

                    Console.Out.WriteLine();
                    Console.Error.WriteLine("Fatal: Unable to update ~/.gitconfig.");
                    Pause();
                    return false;
                }
            }

            if ((type & Configuration.Type.System) == Configuration.Type.System)
            {
                string systemCmd = action == GitConfigAction.Set
                    ? "config --system credential.helper manager"
                    : "config --system --unset credential.helper";

                int successCount = 0;

                foreach (var installation in installations)
                {
                    if (ExecuteGit(installation.Git, systemCmd, 0, 5))
                    {
                        Trace.WriteLine("   updating /etc/gitconfig succeeded.");

                        successCount++;
                    }
                    else
                    {
                        Trace.WriteLine("   updating ~/.gitconfig failed.");
                    }
                }

                if (successCount == installations.Count)
                {
                    updated |= Configuration.Type.System;
                }
                else
                {
                    return false;
                }
            }

            return true;
        }