Getting the last revision number in SVN?
If you want to analyse a local working copy, the best tool is svnversion
, which comes with Subversion and produces output like 968:1000M
. The documentation says:
The version number will be a single number if the working copy is single revision, unmodified, not switched and with an URL that matches the TRAIL_URL argument. If the working copy is unusual the version number will be more complex:
4123:4168 mixed revision working copy 4168M modified working copy 4123S switched working copy 4123:4168MS mixed revision, modified, switched working copy
<?php
$url = 'your repository here';
$output = `svn info $url`;
echo "<pre>$output</pre>";
?>
You can get the output in XML like so:
$output = `svn info $url --xml`;
If there is an error then the output will be directed to stderr. To capture stderr in your output use thusly:
$output = `svn info $url 2>&1`;
svn info -r HEAD
This will give you the latest revision number at the head of your repository.
There are some nice blog posts about integrating subversion numbers into your build script:
- Getting Subversion Revision in Ant
- Automatic Build Sub-Versioning in Xcode
This should work in Bash, from a working directory. I've used it in Windows with unixutils installed:
svn info |grep Revision: |cut -c11-
The following should work:
svnlook youngest <repo-path>
It returns a single revision number.