tags:

views:

1106

answers:

14

In my web application I have a file which hold the current revision number via $Rev$. This work fine except, if I don't make any changes to that file, it doesn't get committed.

Is there anyway I can force a single file to always get committed to the SVN server?

I'm using TortoiseSVN for Windows so any code or step-by-step instructions would be helpful.

+1  A: 

Depending on your client, some of them offer a pre-commit hook that you can implement something that simply "touches" the file and flags it as changed. If your using something like Visual Studio you could create a post build task that would "touch" the file but you would have to make sure that you do a build before committing changes.

Tanerax
+2  A: 

This work fine except, if I don't make any changes to that file, it doesn't get committed.

If the file never changes, why would you need it to commmit every single time?

[EDIT] @Sean = I understand what he's trying to do, but if the file is never getting updated via a hook or some other process and therefore never changing then SVN will never pick it up.

dragonmantank
+1  A: 

@gradonmantank: Because he wants that file to be updated with the latest revision number. Did you read his question completely?

The pre-commit hook might work.

EndangeredMassa
+1  A: 

I used to have a manual way of doing that. I'd run a script that would use sed to replace a comment with the current timestamp in my $Rev$ file. That way, the file contents would change and Subversion would commit it.

What I didn't do was to take that to the next step: using Subversion's repository hooks to automate the process. Trouble is, I'm not sure if you're allowed to change file contents in hooks. The documentation seems to suggest that you can't.

Instead, I guess you'd need a little script that you'd execute in place of the svn commit command that first updates the timestamp and then runs the normal commit.

yukondude
I never did get this to work...
GateKiller
+1  A: 

@Yukondude, I am talking about client software not the server. Some client software allow for hooks.

Tanerax
+3  A: 

@gatekiller: It seems TortoiseSVN does support Client Side Hooks.

Tanerax
+1  A: 

Comitting the file wouldn't do you any good. The file isn't committed with the full version inside, it is replaced with just the keyword. If you look at the file inside the repository you will see this.

As such, you need to force the file to be updated in some way instead.

If you're on the Windows platform, you can use the SubWCRev tool, distributed with TortoiseSVN. Documentation here.

Lasse V. Karlsen
+1  A: 

You can use svn pre-commit-hooks to do it.
The general idea I have in mind is create one that before the commit will put the new revision number in the file (get it using svnlook) or maybe change a bogus property on the file (it has to change or SVN will ignore it).

For more information about pre-commit-hooks I found this page useful.

abyx
+2  A: 

I suggest changing the approach, commiting a file every time means implicitly keeping the global revision number in that file. There user may need another keyword, GlobalKey, whose inexistance is explained here I actually have not used mentioned svnversion however, it may lead you to a solution.

kokeksibir
+1  A: 

Could the revision-number file be changed by a script that deploys your website from SVN to the web-server?

Not sure about on Windows, but using a bash-script, I would do something like..

$ version=$(svnversion)
$ svn export . /tmp/staging/
Export complete.
$ echo "Revision: ${version}" > /tmp/staging/version.txt

Then /tmp/staging/version.txt would contain "Revision: 1" (or whatever the highest revision number is).

You could of course replace some identifier in a file, like $Rev$ (instead of creating version.txt as per the example above)

dbr
This doesn't work; try $(svn ...) instead of ${version}.
Aaron Digulla
Opps, I forgot to copy the "set version=" line.. Thanks!
dbr
+11  A: 

Basically, you want the output of the svnversion command in a file.

Such files are usually kept out of the repository, and automatically created by a build script. I suggest you do the same. If you don't build, but just to a svn up on the server side, just call svnversion after svn up or create a shell script to do both actions.

If you have to keep it in the repository on the other hand, calling svnversion in a pre-commit hook would be your best bet.

Can Berk Güder
+1 to this idea. I'd like to add though that in large repositories, svnversion can take a long time to run (over a minute). For this reason, I parse 'svn info' output instead.
Joshua McKinnon
+2  A: 

If you have TortoiseSVN installed, you also have the SubWCRev tool available. Use that tool to get the revision instead of misusing the $REV$ keyword.

  1. create a template file which contains your defines, maybe something like

    const long WC_REV = $WCREV$;

    in a file named version.h.tmpl

  2. on every build, call SubWCRev to create the 'real' file you can use in your application:

    SubWCRev path\to\workingcopy path\to\version.h.tmpl path\to\version.h

This will create the file version.h from version.h.tmpl, with the text $WCREV$ replaced with the revision your working copy is currently at.

The docs for SubWCRev might help too.

Stefan
+2  A: 

I think you may be not understanding how the $Rev$ flag works. The goal of the Rev flag is not to have this revision always committed into the subversion repository. The goal is that on an update, the Rev flag will always be what the revision is. You should not need to put code into subversion that contains the revision. Subversion is very good at keeping track of that information for you.

What you probably missed is that, you need to set a property on the file so that the Revision keyword will be properly processed.

svn propset svn:keywords "Revision" file.txt

This will ensure that whenever you do an update, the $Rev: xxx$ flag will be updated with the current revision. You don't need to worry about how it is committed to the repository.

Chris Dail
+1  A: 

I think the best approach to ensuring that there is a file in your web application that has the SVN revision number is to not have a file you commit, but rather to extract it as part of your build script.

If you use maven, you can do this with the maven-buildnumber-plugin.

James Kingsbery