How to access the current Subversion build number?

Have your build process call the svnversion command, and embed its output into generated {source|binaries}. This will not only give the current revision (as many other examples here do), but its output string will also tell whether a build is being done in a mixed tree or a tree which doesn’t exactly match the revision number in question (ie. a tree with local changes).

With a standard tree:

$ svnversion
3846

With a modified tree:

$ echo 'foo' >> project-ext.dtd
$ svnversion                   
3846M

With a mixed-revision, modified tree:

$ (cd doc; svn up >/dev/null 2>/dev/null)
$ svnversion
3846:4182M

Leave a Comment