post commit hook to update a file under version
Asked Answered
F

2

8

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

Forebear answered 16/3, 2009 at 12:16 Comment(1)
You question is not clear. The hooks are ment to do something server side. Updating a file in the repository is action from client to server.Chindwin
A
9

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.

Apprehensible answered 17/3, 2009 at 0:2 Comment(0)
R
5

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).

Ra answered 16/3, 2009 at 12:36 Comment(4)
not going to work ... since i have to modify that file to have the keywords replacedForebear
It's like a filter which lets you see things in the repository which aren't really there.Ra
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 notForebear
If you need the global revision number, you must use a rule in your build tool. See the second part of my answer.Ra

© 2022 - 2024 — McMap. All rights reserved.