I am using git describe
as the driver for versioning in my application at build time.
It looks roughly like: git describe --always --dirty --match version*
I tag my versions with a pattern like version.1.2.3
and the build figures out the version of the application based off what the last commit that was tagged with something like version.*
was.
If I haven't tagged a given commit, then the version number ends up something like version.1.14.3-24-ged66bf5
, which is based of the most recent tag, how many commits since that tag and the git commit id.
This works really well for me personally, but I'm having a problem with doing builds off of a shallow clone on my CI server.
When using the "shallow clone" option on my git build in jenkins (I'm guessing it's just doing "--depth=1"), my git describe
command is no longer doing what I want it to do.
My version number just ends up being the commit id - I guess this is because there are no tagged versions in the shallow clone, so the --always
parameter for the describe command just ends up spitting out the commit id.
I can deal with this for the moment by not doing a shallow clone.
But I really like driving my versioning off of the git describe - how can I keep using it even with shallow clones?
I think what I need to be able to do is specify at the time of the shallow clone, that I want the depth to be "from the tip of the branch back to the latest version that has a tag matching version.*
".
Is that a thing I can do with Git?