Example #1
0
        private static string FindFirstCommit(GitGetChangesOptions options)
        {
            using (var process = new Process())
            {
                var argumentBuilder = new StringBuilder();
                argumentBuilder.Append("describe --tags --long");
                process.StartInfo = new ProcessStartInfo
                {
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    FileName         = "git.exe",
                    WorkingDirectory = options.Repository,
                    Arguments        = argumentBuilder.ToString()
                };

                process.Start();

                var output = process.StandardOutput.ReadToEnd();
                var error  = process.StandardError.ReadToEnd();

                process.WaitForExit();
                var exitCode = process.ExitCode;
                if (exitCode != 0)
                {
                    throw new Exception($"git describe returned {exitCode}");
                }

                return(GetCommitAfterLastTag(output));
            }
        }
Example #2
0
        private static string GetGitLog(GitGetChangesOptions options, string startCommit)
        {
            using (var process = new Process())
            {
                var argumentBuilder = new StringBuilder();
                argumentBuilder.Append("log");
                if (!string.IsNullOrEmpty(startCommit))
                {
                    argumentBuilder.AppendFormat(" {0}..HEAD", startCommit);
                }
                argumentBuilder.Append(" --pretty=medium");

                process.StartInfo = new ProcessStartInfo
                {
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    FileName         = "git.exe",
                    WorkingDirectory = options.Repository,
                    Arguments        = argumentBuilder.ToString()
                };

                process.Start();

                var output = process.StandardOutput.ReadToEnd();
                var error  = process.StandardError.ReadToEnd();

                process.WaitForExit();
                var exitCode = process.ExitCode;
                if (exitCode != 0)
                {
                    throw new Exception($"git log returned {exitCode}");
                }

                return(output);
            }
        }
Example #3
0
        public ExitCode Run(GitGetChangesOptions options)
        {
            try
            {
                string start = null;
                if (options.SinceLastTag)
                {
                    start = FindFirstCommit(options);
                }

                var output   = GetGitLog(options, start);
                var changes  = Parse(output);
                var filtered = Filter(changes, options.Include, options.Exclude);
                WriteToDisk(options.Output, filtered);
            }
            catch (Exception e)
            {
                Log.ErrorFormat(e.Message);
                Log.Debug(e);
                return(ExitCode.GenericFailure);
            }

            return(ExitCode.Success);
        }