Пример #1
0
        public static string GitResult(EnvHelper envHelper, string workingDir, string commands)
        {
            var output = string.Empty;
            var error = string.Empty;
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    Arguments = $"/c cd /D \"{workingDir}\" && \"{envHelper.GetGit()}\" {commands}",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true,
                    CreateNoWindow = true
                }
            };
            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                output += proc.StandardOutput.ReadLine() + ",";
            }
            while (!proc.StandardError.EndOfStream)
            {
                error += proc.StandardError.ReadLine();
            }

            return string.IsNullOrEmpty(output) ? error : output.TrimEnd(',');
        }
Пример #2
0
        public static string GetSshSetup(EnvHelper envHelper)
        {
            var remoteOriginPuttyKeyfile = ProcessHelper.StartProcessGitResult(envHelper, "config --get remote.origin.puttykeyfile");

            if (string.IsNullOrEmpty(remoteOriginPuttyKeyfile))
            {
                return(string.Empty);
            }

            ProcessHelper.Start("pageant", remoteOriginPuttyKeyfile);
            return($"set GIT_SSH={FileHelper.GetTortoiseGitPlink()} && ");
        }
Пример #3
0
 public static void StartTortoiseGitProc(EnvHelper envHelper, string args)
 {
     var tortoiseGitProc = envHelper.GetTortoiseGitProc();
     try
     {
         Process.Start(tortoiseGitProc, args);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, $"{tortoiseGitProc} not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #4
0
        /// <summary>
        /// Execute a Git command and return true if output is non-empty
        /// </summary>
        /// <param name="commands">Git command to be executed</param>
        /// <param name="showAlert">Show an alert dialog when error output is non-empty</param>
        /// <returns>True if output is non-empty</returns>
        public static bool StartProcessGit(EnvHelper envHelper, string commands, bool showAlert = true)
        {
            if (string.IsNullOrEmpty(envHelper.GetSolutionDir()))
            {
                return(false);
            }

            var output = string.Empty;
            var error  = string.Empty;
            var proc   = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = "cmd.exe",
                    Arguments              = $"/c cd /D \"{envHelper.GetSolutionDir()}\" && \"{envHelper.GetGit()}\" {commands}",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                output = proc.StandardOutput.ReadLine();
            }
            while (!proc.StandardError.EndOfStream)
            {
                error += proc.StandardError.ReadLine();
            }
            if (!string.IsNullOrEmpty(output))
            {
                return(true);
            }
            if (!string.IsNullOrEmpty(error) && showAlert)
            {
                MessageBox.Show(error, "TGit error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(false);
        }
Пример #5
0
        public static string GetCommitMessage(string commitMessageTemplate, DTE dte, EnvHelper envHelper)
        {
            if (string.IsNullOrEmpty(commitMessageTemplate))
            {
                return(string.Empty);
            }

            var commitMessage = commitMessageTemplate;

            commitMessage = commitMessage.Replace("$(BranchName)", GetCurrentBranchName(false, envHelper));
            commitMessage = commitMessage.Replace("$(FeatureName)", GetCurrentBranchName(true, envHelper));
            commitMessage = commitMessage.Replace("$(Configuration)", dte.Solution.SolutionBuild.ActiveConfiguration?.Name);
            commitMessage = commitMessage.Replace("$(DevEnvDir)", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7\\", dte.Version, ""));
            commitMessage = commitMessage.Replace("$(SolutionDir)", Path.GetDirectoryName(dte.Solution.FullName));
            commitMessage = commitMessage.Replace("$(SolutionPath)", Path.GetFullPath(dte.Solution.FullName));
            commitMessage = commitMessage.Replace("$(SolutionName)", dte.Solution.FullName);
            commitMessage = commitMessage.Replace("$(SolutionFileName)", dte.Solution.FileName);
            commitMessage = commitMessage.Replace("$(SolutionExt)", Path.GetExtension(dte.Solution.FileName));
            commitMessage = commitMessage.Replace("$(VSInstallDir)", (string)Registry.GetValue($"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{dte.Version}", "InstallDir", ""));
            commitMessage = commitMessage.Replace("$(FxCopDir)", (string)Registry.GetValue($"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\{dte.Version}\\Edev", "FxCopDir", ""));
            return(commitMessage);
        }
Пример #6
0
 public static void GitHubFlow_BeforeQueryStatus(object sender, EventArgs e)
 {
     ((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && !EnvHelper.IsGitFlow;
 }
Пример #7
0
 public static void SolutionVisibility_BeforeQueryStatus(object sender, EventArgs e)
 {
     ((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir();
 }
Пример #8
0
 public static void Solution_BeforeQueryStatus(object sender, EventArgs e)
 {
     ((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir();
 }
Пример #9
0
 public static void Release_BeforeQueryStatus(object sender, EventArgs e)
 {
     ((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow;
     ((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.StartsWith(EnvHelper.GitConfig.ReleasePrefix);
 }
Пример #10
0
 public static void StartFeatureBranch_BeforeQueryStatus(object sender, EventArgs e)
 {
     ((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitFlow;
     ((OleMenuCommand)sender).Enabled = EnvHelper.HasSolutionDir() && EnvHelper.BranchName.Equals(EnvHelper.GitConfig.LastFeatureBranchFullName);
 }
Пример #11
0
 public static bool RemoteBranchExists(EnvHelper envHelper, string branch)
 {
     return(ProcessHelper.StartProcessGit(envHelper, $"show-ref refs/remotes/origin/{branch}"));
 }
Пример #12
0
 public static GitConfig GetGitConfig(EnvHelper envHelper)
 {
     return(new GitConfig(ProcessHelper.StartProcessGitResult(envHelper, "config --get-regexp \"gitflow|bugtraq|svn-remote\"")));
 }
Пример #13
0
        public static Process StartProcessGui(DTE dte, EnvHelper envHelper, string application, string args, string title, string branchName = "", 
            OutputBox outputBox = null, OptionPageGrid options = null, string pushCommand = "")
        {
            var dialogResult = DialogResult.OK;
            if (!StartProcessGit(envHelper, "config user.name") || !StartProcessGit(envHelper, "config user.email"))
            {
                dialogResult = new Credentials(envHelper).ShowDialog();
            }

            if (dialogResult == DialogResult.OK)
            {
                try
                {
                    var process = new Process
                    {
                        StartInfo =
                        {
                            WindowStyle = ProcessWindowStyle.Hidden,
                            RedirectStandardOutput = true,
                            RedirectStandardError = true,
                            UseShellExecute = false,
                            CreateNoWindow = true,
                            FileName = application,
                            Arguments = args,
                            WorkingDirectory = envHelper.GetSolutionDir()
                        },
                        EnableRaisingEvents = true
                    };
                    process.Exited += process_Exited;
                    process.OutputDataReceived += OutputDataHandler;
                    process.ErrorDataReceived += OutputDataHandler;

                    if (outputBox == null)
                    {
                        _outputBox = new OutputBox(branchName, options, pushCommand, dte, envHelper);
                        _outputBox.Show();
                    }
                    else
                    {
                        _outputBox = outputBox;
                    }                    

                    process.Start();
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();

                    if (!string.IsNullOrEmpty(title))
                    {
                        _outputBox.Text = title;
                    }
                    
                    _outputBox.Show();

                    return process;
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, $"'{application}' not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return null;
        }