2

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

  • Duplicate: http://stackoverflow.com/questions/163/how-do-i-sync-the-svn-revision-number-with-my-asp-net-web-site – Stobor Oct 19 '09 at 01:42
  • Duplicate: http://stackoverflow.com/questions/110175/how-to-access-the-current-subversion-build-number – Stobor Oct 19 '09 at 01:43

5 Answers5

3

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
  • 854,459
  • 170
  • 1,222
  • 1,395
  • 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 Oct 19 '09 at 02:04
  • 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 Oct 19 '09 at 02:15
  • I just often see this problem as a "Frequently Encountered Unexpected Result", so perhaps stating it in black and white *is* necessary. – Greg Hewgill Oct 19 '09 at 02:25
3

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
  • 305,152
  • 44
  • 369
  • 561
2

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

Bostone
  • 36,858
  • 39
  • 167
  • 227
0

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
  • 61,857
  • 6
  • 82
  • 92
0

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
  • 6,853
  • 2
  • 26
  • 25