views:

569

answers:

2

Hello

I have made a file called version.ini that is under version control (/trunk/version.ini) i now wanted to make a post commit hook to update that file with the latest version. But i dont know what command can do that. I know i have this params:

#!/bin/sh

REPOS = "$1"
REV = "$2"

But how can i replace the content of that file without making a new revision ? and still have those changes in my repo ?

UPDATE: Since maybe i havent been clear i will try a more detailed explination: Lets say i have this repo: /svn/repos/project/trunk/ and in it i have a file called version.ini that is under version control. What i want to do is that on every commit update that file to the new revision. Lets say that the current revision is 263 i want that file to have 263 writen in it. And to respond to an answer bellow you cant use keywords since they only work if i update that file and i dont want to do it.

Hope i made sense, and thanks for any help given. Cheers

+4  A: 

There is no way to change anything in the repo without modifying the revision number.

The solution is to put special keywords (search for svn:keywords) into the file and have SVN replace them during checkout. It will seem that these values come from the repository but the representation of the file in the repository will not change.

You're probably looking for $LastChangedRevision$ (or $Rev$ for short).

Another solution is to add a rule to your build tool/Makefile/whatever which uses svn info on the root directory of your project to determine the current revision and puts that into a temporary file (which is not added to your repo).

Aaron Digulla
not going to work ... since i have to modify that file to have the keywords replaced
solomongaby
SVN will do that for you when svn:keywords is set correctly.
Aaron Digulla
It's like a filter which lets you see things in the repository which aren't really there.
Aaron Digulla
how can you setup it so it updates the keyword to the global revision number not the files revision number ? and also do it regalement if the file was modified or not
solomongaby
If you need the global revision number, you must use a rule in your build tool. See the second part of my answer.
Aaron Digulla
+2  A: 

What you actually want is not a way to modify your commits, but something like svn:keywords. Unfortunately, as you can read in the box "Where's $GlobalRev$?" this doesn't really do what you want. Instead, you'll have to write a script to call and parse the output of svnversion and somehow put the result in your files as part of the build.

Now, to answer your literal question it's still fun to think about what you can and cannot do in svn hook scripts:

You can't change a commit from a post-commit hook

By the time post-commit hook runs, the commit has already been finalized (as the name implies) so changing files is out of the question. You can only inspect the changes at this point.

You can't modify pending commits from a pre-commit hook either

You can examine the content of a pending transaction from a pre-commit hook by using the svnlook tool with the --transaction switch, but you can't change it.

If arbitrary changes could be made in a pre-commit hook, then obviously the server would need to report back these changes to the svn client. Otherwise the client would think his files are at the committed revision, while they are actually different. If the svn client would accept such reported changes it would lead to the possibility of your work being wiped out by a commit. That would be a surprising feature to have for a version control system, to put it mildly. Needless to say subversion does not allow this.

Wim Coenen