Example #1
0
        public static int GitQueryRevisionNumber(
            this ICakeContext context,
            GitToolSettings toolSettings,
            GitQueryRevisionNumberConfig config = null
            )
        {
            var runner = new GitQueryRevisionNumberRunner(context, toolSettings);

            return(runner.Run(config));
        }
Example #2
0
        public static int GitQueryRevisionNumber(
            this ICakeContext context,
            DirectoryPath repoRoot,
            GitQueryRevisionNumberConfig config = null
            )
        {
            var toolSettings = new GitToolSettings
            {
                WorkingDirectory = repoRoot
            };

            return(GitQueryRevisionNumber(context, toolSettings, config));
        }
Example #3
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Runs git and gets the number of commits on the current branch.
        /// </summary>
        /// <param name="config">
        /// Configuration.  If null, it grabs the configuration
        /// from the passed in command-line arguments.
        /// </param>
        /// <returns>
        /// The number of commits that have happend on the current git branch.
        /// </returns>
        public int Run(GitQueryRevisionNumberConfig config = null)
        {
            if (config == null)
            {
                config = ArgumentBinder.FromArguments <GitQueryRevisionNumberConfig>(this.context);
            }

            int revNumber = -1;

            string onStdOut(string line)
            {
                if (string.IsNullOrWhiteSpace(line) == false)
                {
                    if (int.TryParse(line, out revNumber) == false)
                    {
                        revNumber = -1;
                    }
                }

                return(line);
            };

            ProcessSettings processSettings = new ProcessSettings
            {
                Arguments = ProcessArgumentBuilder.FromString("rev-list --count HEAD"),
                RedirectStandardOutput          = true,
                RedirectedStandardOutputHandler = onStdOut
            };

            this.Run(this.toolSettings, processSettings.Arguments, processSettings, null);

            if (revNumber < 0)
            {
                throw new InvalidOperationException(
                          "Could not get rev number from git"
                          );
            }

            if (config.NoPrint == false)
            {
                context.Information("Current Revision Number: " + revNumber);
            }

            if (string.IsNullOrWhiteSpace(config.OutputFile) == false)
            {
                System.IO.File.WriteAllText(config.OutputFile, revNumber.ToString());
            }

            return(revNumber);
        }