Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit count in Cake build script?

Tags:

git

c#

cakebuild

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?


2 Answers

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
like image 140
devlead Avatar answered Jan 03 '26 12:01

devlead


Just wanted to point out an alternative as well...

I, and Cake itself, use a tool called GitVersion to assert a semantic version number, based on the git commit history. Just wanted to point it out, in case it might be a good fit for your pipeline.

like image 34
Gary Ewan Park Avatar answered Jan 03 '26 12:01

Gary Ewan Park



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!