tags:

views:

124

answers:

3

What is the best way (if any) to modify a particular file under our repository within a post_commit hook?

eg: I want to append a checksum line to a somefile.conf file

+1  A: 

You might want to read this chapter of the SVN book. At the end of it, there is the following warning in a nice red box:

While hook scripts can do almost anything, there is one dimension in which hook script authors should show restraint: do not modify a commit transaction using hook scripts. While it might be tempting to use hook scripts to automatically correct errors, shortcomings, or policy violations present in the files being committed, doing so can cause problems. Subversion keeps client-side caches of certain bits of repository data, and if you change a commit transaction in this way, those caches become indetectably stale. This inconsistency can lead to surprising and unexpected behavior. Instead of modifying the transaction, you should simply validate the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements. As a bonus, your users will learn the value of careful, compliance-minded work habits.

sbi
Thanks, I've read it.. But I'm asking (mainly myself) if I can implement some work-aronud.Example such a post_commit hook can invoke a script that: 1. issues an svn update on a working copy of the repo 2. apply its changes (checksum and so on) accordingly 3. issues an svn commit -m "checksum added bla bla..."Do you think it's feasible/appropriate?
Carlo Pecchia
Maybe, I wouldn't know. Frankly, I'd ask this at the SVN mailing list.
sbi
You can do what you say in a post commit hook, just be aware that it would be adding an addition revision to the repository, and the original committer would also need to do an update to get the changes.
Jim T
+1  A: 

Don't do this in a hook -- do it in a separate change, that other users of that branch can then pull down into their working copy. It doesn't need to be more complicated than this (in pseudocode):

  • script gets a working copy from the repository into local directory
  • script modifies file
  • script commits file with a good commit message "e.g. "script Foo: adding checksum"

It's not uncommon for build scripts (running under cron or triggered by a Makefile) to make periodic revisions to a repository, for example regenerating files based on other files. Sometimes these are checked into the repository and sometimes they aren't, depending on who consumes these files and how.

Ether
That is *exactly* what I am doing. THE question is on "when" is more appropriate. In a post_commit seems reasonable cause I'm not "deforming" the actual transaction, only adding sometinhg after :).And, yes, the script should act on its own working copy of the repo.TNX
Carlo Pecchia
+1  A: 

There's no problem with doing what you suggest in a post commit hook, but do be aware that it will add a new revision to the repository and that the original committer will need to do an update before they can see the changes the script made. It will also slow down the commit as the post commit runs before returning from the commit operation.

Jim T