Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

post commit hook to update a file under version

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

like image 262
Gabriel Solomon Avatar asked Mar 16 '09 12:03

Gabriel Solomon


People also ask

How do I update pre-commit hooks?

You can update your hooks to the latest version automatically by running pre-commit autoupdate . By default, this will bring the hooks to the latest tag on the default branch.

What is post-commit hook?

The post-commit hook is called immediately after the commit-msg hook. It can't change the outcome of the git commit operation, so it's used primarily for notification purposes. The script takes no parameters and its exit status does not affect the commit in any way.


2 Answers

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.

like image 134
Wim Coenen Avatar answered Sep 21 '22 00:09

Wim Coenen


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

like image 24
Aaron Digulla Avatar answered Sep 20 '22 00:09

Aaron Digulla