views:

183

answers:

4

I have a project who's structure in Subversion goes as follows,

branch
tags
trunk
-- Library
---- Library Code
-- Website
---- Website Code

The Library folder contains most of the project code and is a class library. The Website folder is a website project which uses the library. The website is what gets deployed to the live site.

I would like to automatically create a file in the root of the website directory that stores the latest revision number of the trunk directory. Is this possible and if so how would I go about it?

The subversion server is VisualSVN on Windows using TortoiseSVN with VisualSVN for the client.

+1  A: 

Well, the usual way of including a revision number is to put

$Revision$

somewhere into the source file which gets expanded on commit, provided the property svn:keywords property contains Revision.

That will only give you the revision number when that file was last committed, though, not the current HEAD revision number.

In a past project I used a little script that called the command line subversion program to extract the current revision number. You can call svn info and get all kinds of information back, including the revision number of the working copy. This gets updated for a directory when you perform an update on that directory or one of its parents and for files when they are actually updated so it might not be fully accurate. However it was enough for me at that time as I only ever updated the top-level folder anyway:

>svn info trunk | findstr /r /c:"^Revision"
Revision: 14466
Joey
A: 

Have a look at the svn info command. Running this as a pre/post build event in your project will get you the information you need (and some additional information). You then need to write the revision number to a file. (If you do this, make sure you SVN ignore this file otherwise it will enter an endless loop of the file changing, you checking it it, the file changing, etc...)

adrianbanks
A: 

There's a command line tool called svnversion that can be used to generate the value you need. However, you still need to execute it manually. And there's an additional issue:

  1. If you want to store the result into the repository, you'll have to execute it before you commit and the stored value will always be outdated.

  2. If you want to keep the result unversioned, you'll have to execute after you commit. But then it won't get exported.

So there's no simple answer to the question. A proposal:

  1. Have a version.txt file or whatever with the $Revision$ keyword.
  2. Write a pre-commit hook script that rejects the commit if version.txt has not been modified
  3. Optionally, write a TortoiseSVN client-side hook script to modify the file automatically on before commit.
Álvaro G. Vicario
+1  A: 

Since you're using TortoiseSVN, I suggest using SubWCRev for this task instead of svnversion.

Stefan