I have a C++ project in VS2013. In the past on similar projects I've used SubWCRev with Subversion to auto generate version numbers. I had a template file like this :
#define MAJOR_VERSION 2
#define MINOR_VERSION 2
#define MICRO_VERSION 0
#define BUILD_VERSION $WCMODS?$WCREV$+1:$WCREV$$
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
#define BUILD_VERSION_STRING QUOTE(MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION.BUILD_VERSION)
Then I ran SubWCRev as a pre-build step to generate the header file which I included in the project to define the version numbers.
I'm now using Git and want to do something similar. I know that Git doesn't have an equivalent of revision number but the HEAD SHA would be fine.
It doesn't seem like there's an equivalent way to do this with Git and I need to do some scripting which isn't my strong point. Could a Git Guru point me in the right direction to achieve this?
I've eventually found a really useful batch file which actually does way more than I need :
https://github.com/Thell/git-vs-versioninfo-gen
It basically does a very similar job to SubWCRev and generates a header file that I can include in my VS project to set all the version strings. After a bit of hacking around with the script I've got it to do exactly what I wanted.
There's a C# version here too :
https://github.com/jasperboot/git-vs-versioninfo
With the latest TortoiseGit 2.7.0, you can simply replace SubWCRev with GitWCRev and get the same results. Revision will use git's SHA1.
I'm using the output from git describe for the build string. I don't use windows.
This example works under Linux fine.
version.h
#ifndef GIT_VERSION_H
#define GIT_VERSION_H
extern const char* git_version;
#endif
The version.c is generated by awk
git describe | awk 'BEGIN { print "#include \"version.h\"" } { print "const char* git_version = \"" $$0 "\";"} END {}' > version.c
Dirk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With