コード例 #1
0
        /// <summary>
        /// This method is a part of new functionality. To save backward compatibility previous implementation was left.
        /// </summary>
        /// <param name="gitCommand"></param>
        /// <returns></returns>
        private GitCommandResult ExecuteWithCmd(string gitCommand)
        {
            try
            {
                var activeRepository = _gitService.ActiveRepositories.FirstOrDefault();
                if (activeRepository == null)
                {
                    return new GitCommandResult {
                               ErrorMessage = Constants.UnknownRepositoryErrorMessage
                    }
                }
                ;

                var gitExePath = GitPathHelper.GetGitPath();
                var cmdCommand = "/C \"\"" + (gitExePath ?? "git.exe") + "\" " + gitCommand + "\"";

                var gitStartInfo = new ProcessStartInfo
                {
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    FileName         = "cmd.exe",
                    Arguments        = cmdCommand,
                    WorkingDirectory = activeRepository.RepositoryPath
                };

                using (var gitProcess = Process.Start(gitStartInfo))
                {
                    var errorMessage = Task.Run(() => gitProcess.StandardError.ReadToEndAsync());

                    var outputMessage = Task.Run(() => gitProcess.StandardOutput.ReadToEndAsync());

                    gitProcess.WaitForExit();

                    return(new GitCommandResult
                    {
                        OutputMessage = outputMessage.Result,
                        ErrorMessage = errorMessage.Result
                    });
                }
            }
            catch (Exception e)
            {
                Log.LogException(e);
                return(new GitCommandResult {
                    ErrorMessage = Constants.UnexpectedErrorMessage + Environment.NewLine + $"Find error info in {Log.GetLogFilePath()}"
                });
            }
        }
コード例 #2
0
        private GitCommandResult Execute(string gitCommand)
        {
            try
            {
                var activeRepository = _gitService.ActiveRepositories.FirstOrDefault();
                if (activeRepository == null)
                {
                    return new GitCommandResult {
                               ErrorMessage = "Select repository to find stashes."
                    }
                }
                ;

                var gitStartInfo = new ProcessStartInfo
                {
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false,
                    // TODO: refactor next statement. Create git helper for fetching git.exe path.
                    FileName         = GitPathHelper.GetGitPath(),
                    Arguments        = gitCommand,
                    WorkingDirectory = activeRepository.RepositoryPath
                };

                using (var gitProcess = Process.Start(gitStartInfo))
                {
                    var errorMessage = gitProcess.StandardError.ReadToEnd();

                    var outputMessage = gitProcess.StandardOutput.ReadToEnd();

                    gitProcess.WaitForExit();

                    return(new GitCommandResult
                    {
                        OutputMessage = outputMessage,
                        ErrorMessage = errorMessage
                    });
                }
            }
            catch (Exception ex)
            {
                return(new GitCommandResult {
                    ErrorMessage = $"Unexpected error. {ex.Message}"
                });
            }
        }