On CI server we git clone --depth 1 <repo>
and I would like to create a version string for the artifact that is being built. I want my version string to look like this:
0.1.0-15-0bef345-master
Where:
0.1.0
is the version obtained from the latest tag, this is easy, usinggit ls-remote
.15
is the number of commits after the0.1.0
tag0bef345
is the short hash of the git commitmaster
is the branch
Now the question is, how can I get the 15 (amount of commits between a tag and the HEAD
).
Normally this is easy git rev-list --count v0.1.0 HEAD
, when you have the full history.
How can I do this without having to clone the entire history?