Exemplo n.º 1
0
        /// <summary>
        /// silently does not save some settings if Git is not configured correctly
        /// (user notification is done elsewhere)
        /// </summary>
        public override void SaveSettings()
        {
            _gitModule.SetFilesEncoding(false, _commonLogic.ComboToEncoding(Global_FilesEncoding));

            if (_checkSettingsLogic.CanFindGitCmd())
            {
                ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();

                if (string.IsNullOrEmpty(GlobalUserName.Text) ||
                    !GlobalUserName.Text.Equals(globalConfig.GetValue("user.name")))
                {
                    globalConfig.SetValue("user.name", GlobalUserName.Text);
                }
                if (string.IsNullOrEmpty(GlobalUserEmail.Text) ||
                    !GlobalUserEmail.Text.Equals(globalConfig.GetValue("user.email")))
                {
                    globalConfig.SetValue("user.email", GlobalUserEmail.Text);
                }
                if (string.IsNullOrEmpty(CommitTemplatePath.Text) ||
                    !CommitTemplatePath.Text.Equals(globalConfig.GetValue("commit.template")))
                {
                    globalConfig.SetValue("commit.template", CommitTemplatePath.Text);
                }
                globalConfig.SetPathValue("core.editor", GlobalEditor.Text);

                CheckSettingsLogic.SetGlobalDiffToolToConfig(globalConfig, GlobalDiffTool.Text);

                if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
                {
                    globalConfig.SetPathValue(string.Format("difftool.{0}.path", GlobalDiffTool.Text), DifftoolPath.Text);
                }
                if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
                {
                    globalConfig.SetPathValue(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text), DifftoolCmd.Text);
                }

                globalConfig.SetValue("merge.tool", GlobalMergeTool.Text);

                if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
                {
                    globalConfig.SetPathValue(string.Format("mergetool.{0}.path", GlobalMergeTool.Text), MergetoolPath.Text);
                }
                if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
                {
                    globalConfig.SetPathValue(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text), MergeToolCmd.Text);
                }

                if (GlobalKeepMergeBackup.CheckState == CheckState.Checked)
                {
                    globalConfig.SetValue("mergetool.keepBackup", "true");
                }
                else if (GlobalKeepMergeBackup.CheckState == CheckState.Unchecked)
                {
                    globalConfig.SetValue("mergetool.keepBackup", "false");
                }

                if (globalAutoCrlfFalse.Checked)
                {
                    globalConfig.SetValue("core.autocrlf", "false");
                }
                if (globalAutoCrlfInput.Checked)
                {
                    globalConfig.SetValue("core.autocrlf", "input");
                }
                if (globalAutoCrlfTrue.Checked)
                {
                    globalConfig.SetValue("core.autocrlf", "true");
                }

                CommonLogic.SetEncoding(_gitModule.GetFilesEncoding(false), globalConfig, "i18n.filesEncoding");
                globalConfig.Save();
            }
        }