示例#1
0
        /// <inheritdoc/>
        public string GetTextFromProcess(GitArgument command)
        {
            string outText = null;
            string arg     = GetArg(command);

            try
            {
                using (Process process = new Process())
                {
                    process.StartInfo = new ProcessStartInfo(Command, arg)
                    {
                        UseShellExecute        = false,
                        WorkingDirectory       = this.WorkingDirectory,
                        RedirectStandardOutput = true
                    };
                    process.Start();
                    bool exited = process.WaitForExit(1000);
                    if (!exited || !process.HasExited)
                    {
                        Logger?.LogWarning($"Process '{command} {arg}' timed out, killing.");
                        process.Kill();
                    }
                    outText = process.StandardOutput.ReadToEnd()?.Trim();
                }
            }
            catch (Exception ex)
            {
                throw new GitRunnerException(ex.Message, ex);
            }
            return(outText);
        }
示例#2
0
        private static string GetArg(GitArgument command)
        {
            switch (command)
            {
            case GitArgument.None:
                return(string.Empty);

            case GitArgument.Status:
                return("status");

            case GitArgument.CommitHash:
                return("rev-parse HEAD");

            case GitArgument.OriginUrl:
                return("config --local --get remote.origin.url");

            default:
                break;
            }
            return(string.Empty);
        }