示例#1
0
        public static bool TrySetGitConfigSettings(GitProcess git)
        {
            Dictionary <string, string> expectedConfigSettings = new Dictionary <string, string>
            {
                { "core.autocrlf", "false" },
                { "core.fscache", "true" },
                { "core.gvfs", "true" },
                { "core.preloadIndex", "true" },
                { "core.safecrlf", "false" },
                { "core.sparseCheckout", "true" },
                { GVFSConstants.VirtualizeObjectsGitConfigName, "true" },
                { "credential.validate", "false" },
                { "diff.autoRefreshIndex", "false" },
                { "gc.auto", "0" },
                { "merge.stat", "false" },
                { "receive.autogc", "false" },
            };

            GitProcess.Result getConfigResult = git.GetAllLocalConfig();
            if (getConfigResult.HasErrors)
            {
                return(false);
            }

            Dictionary <string, string> actualConfigSettings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string line in getConfigResult.Output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] fields = line.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                if (!actualConfigSettings.ContainsKey(fields[0]) && fields.Length == 2)
                {
                    actualConfigSettings.Add(fields[0], fields[1]);
                }
                else
                {
                    actualConfigSettings[fields[0]] = null;
                }
            }

            foreach (string key in expectedConfigSettings.Keys)
            {
                string actualValue;
                if (!actualConfigSettings.TryGetValue(key, out actualValue) ||
                    actualValue != expectedConfigSettings[key])
                {
                    GitProcess.Result setConfigResult = git.SetInLocalConfig(key, expectedConfigSettings[key]);
                    if (setConfigResult.HasErrors)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }