Jeffrey Goldman Jeffrey Goldman - 1 month ago 13
Git Question

Commit count in Cake build script?

We’re migrating to using Cake build scripts for our CI pipeline and in our build process we identify builds with the commit count using the output from command

git rev-list --all –count
.

Is there a native way for this in Cake without shelling out to the git command line?

Answer

While there’s no built-in alias for this, there’s an addin to Cake called Cake.Git which enables you to achieve what you’re asking for.

Example usage:

#addin nuget:?package=Cake.Git

DirectoryPath repoPath = Directory("path to repo");

var commits = GitLog(repoPath, int.MaxValue);

Information("Number of commits: {0}", commits.Count);

Will out put something like

Number of commits: 1539
Comments