tags:

views:

202

answers:

6

How do I get my SVN revision number to appear on my website each time I commit?

+2  A: 

Basically you will need to execute svn info on command line and then parse the output (so given this happens on the server). See this blog entry for example

The output from svn info looks like this:

Path: .
URL: http://continuum.td.foo.com/svn/EngTools/Atom/trunk/aimv-test-daemon
Repository Root: http://continuum.td.foo.com/svn
Repository UUID: 69079f5b-ed1a-0410-902f-f9949c1bbd36
Revision: 107090
Node Kind: directory
Schedule: normal
Last Changed Author: johndoe
Last Changed Rev: 107006
Last Changed Date: 2009-07-09 15:21:17 -0700 (Thu, 09 Jul 2009)

Say you don't want to run daemon or exec you can simply dump the content to some known file after you update your build svn info > svnbuild.info and parse that

DroidIn.net
+3  A: 

You must have something like $Revision$ in the file whose revision you want to track (say foo.html), and tell Svn to track and substitute that keyword in the file, i.e.:

svn propset svn:keywords "Revision" foo.html

Svn will then, when the file's changed, change that expression into $Revision: 23 or whatever the revision number may be. (You can do that in other files too, of course, but then -- depending how you compose your site -- you'll have to get the info from each file of interest and add it to the page you're displaying, e.g. via templating or whatever).

Alex Martelli
It is worth emphasising that using `$Revision$` in a single file will *not* automatically update its value when changes are made to other files.
Greg Hewgill
Think it's not emphasized enough in my answer? I have it in the very first line and again in the parentheses at the end...
Alex Martelli
I just often see this problem as a "Frequently Encountered Unexpected Result", so perhaps stating it in black and white *is* necessary.
Greg Hewgill
A: 

Assuming PHP here, but you could easily do this in any server-side language.

<?PHP
$revString = '$Revision$'; // Subversion will substitute something like $Revision: <number> $
$revNum = magic($revString); // magic parses the integer number out of the string.
echo "Subversion revision: $revNum";
timdev
That `magic()` function must be new in PHP. :)
Greg Hewgill
+2  A: 

Looks like they embed it in the page ("view source" on this page):

<div id="svnrev">svn revision: 4999</div>

I can get it using Tortoise on Windows by looking at the log for a repository. You don't say what OS you're using or if it's command shell access for you.

Check the SVN Red Bean book for the command you need.

duffymo
A: 

Assuming Java and Ant, you can use a task to query the repository and store the infos into some Ant properties. This could be handy to get not only the revision number but also the tag/branch name.

You can see a sample task in my sandbox

Vladimir
A: 

Look at this answer.

Xavier Nodet