Reputation: 75869
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.
Upvotes: 10
Views: 4434
Reputation: 391276
Committing 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.
Upvotes: 1
Reputation: 7486
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.
Upvotes: 1
Reputation: 26029
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.
Upvotes: 6
Reputation: 43575
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.
create a template file which contains your defines, maybe something like
const long WC_REV = $WCREV$;
in a file named version.h.tmpl
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.
Upvotes: 9
Reputation: 169535
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)
Upvotes: 2
Reputation: 113280
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.
Upvotes: 13
Reputation: 1745
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.
Upvotes: 2
Reputation: 72748
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.
Upvotes: 1
Reputation: 15456
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.
Upvotes: 3
Reputation: 24643
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.
Upvotes: 1
Reputation: 5866
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.
Upvotes: 1