public static void AddCustomActions(string scriptPath)
        {
            string roamingPath    = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string configFilePath = Path.Combine(roamingPath, SettingsPath);

            if (!File.Exists(configFilePath))
            {
                throw new GitExtensionsIntegrationHelperException("Cannot find Git Extensions configuration file");
            }

            string gitbash = Path.Combine(GitTools.GetBinaryFolder(), Constants.BashFileName);

            if (!File.Exists(gitbash))
            {
                throw new GitExtensionsIntegrationHelperException("Cannot find git bash");
            }

            // load XML from disk
            XDocument document = XDocument.Load(configFilePath);

            // find a placeholder for scripts
            XElement ownScripts = document?
                                  .Descendants("item")
                                  .FirstOrDefault(x => x.Descendants("string").Any(y => y.Value == "ownScripts"));
            XElement ownScriptsValue = ownScripts?.Element("value")?.Element("string");

            if (ownScriptsValue == null)
            {
                throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file");
            }

            // deserialize XML
            XDocument scripts = XDocument.Parse(ownScriptsValue.Value);

            if (scripts == null)
            {
                throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file");
            }

            Debug.Assert(document != null);
            string name = Constants.CreateMergeRequestCustomActionName;

            // delete previously added element
            IntegrationHelper.DeleteElements(scripts, "ScriptInfo", "Name", new string[] { name });

            // add element
            int maxHotKeyNumber = getCurrentMaximumHotKeyNumber(scripts);

            XElement[] elements = new XElement[] { getCreateMergeRequestElement(name, scriptPath, maxHotKeyNumber, gitbash) };
            if (!IntegrationHelper.AddElements(scripts, "ArrayOfScriptInfo", elements))
            {
                throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file");
            }

            // serialize XML and save to disk
            ownScriptsValue.Value = scripts.ToString();
            document.Save(configFilePath);
        }
示例#2
0
        private static bool prepareGitEnvironment()
        {
            if (!GitTools.IsGit2Installed())
            {
                MessageBox.Show(
                    "Git for Windows (version 2) is not installed. "
                    + "It must be installed at least for the current user. Application cannot start.",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            string pathEV = System.Environment.GetEnvironmentVariable("PATH");

            System.Environment.SetEnvironmentVariable("PATH", pathEV + ";" + GitTools.GetBinaryFolder());
            Trace.TraceInformation(String.Format("Updated PATH variable: {0}",
                                                 System.Environment.GetEnvironmentVariable("PATH")));
            System.Environment.SetEnvironmentVariable("GIT_TERMINAL_PROMPT", "0");
            Trace.TraceInformation("Set GIT_TERMINAL_PROMPT=0");
            Trace.TraceInformation(String.Format("TEMP variable: {0}",
                                                 System.Environment.GetEnvironmentVariable("TEMP")));
            return(true);
        }
示例#3
0
        public static void AddCustomActions(string scriptPath)
        {
            string gitbash = Path.Combine(GitTools.GetBinaryFolder(), Constants.BashFileName);

            if (!File.Exists(gitbash))
            {
                throw new SourceTreeIntegrationHelperException("Cannot find git bash");
            }

            string roamingPath    = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string configFilePath = Path.Combine(roamingPath, SettingsPath);
            string configFolder   = Path.GetDirectoryName(configFilePath);

            if (!Directory.Exists(configFolder))
            {
                throw new SourceTreeIntegrationHelperException("Cannot find a folder for Source Tree settings");
            }

            // load XML from disk
            XDocument scripts = File.Exists(configFilePath)
            ? XDocument.Load(configFilePath) : new XDocument(new XElement("ArrayOfCustomAction"));

            Debug.Assert(scripts != null);
            string name = Constants.CreateMergeRequestCustomActionName;

            // delete previously added element
            IntegrationHelper.DeleteElements(scripts, "CustomAction", "Caption", new string[] { name });

            // add element
            XElement[] elements = new XElement[] { getCreateMergeRequestElement(scriptPath, gitbash) };
            if (!IntegrationHelper.AddElements(scripts, "ArrayOfCustomAction", elements))
            {
                throw new SourceTreeIntegrationHelperException("Unexpected format of Source Tree configuration file");
            }

            // save to disk
            scripts.Save(configFilePath);
        }