Question

I am looking for a way to do the following either on pre-commit or post-commit or any other way.

Here is what I need to be working

  1. User commits the file
  2. Something runs (hook or something else)
  3. That something else from #2 should append static text to the file being committed

Based on this http://subversion.open.collab.net/ds/viewMessage.do?dsForumId=3&dsMessageId=296576 I see that it is not recommended, but there is gotta be a way to append text to file on every commit.

Operating System: Sent Os

Reason why i need it: protect all code files by inserting legal notices

Was it helpful?

Solution 3

So far the only feasible solution is to use client-side hooks of tortoiseSVN:

Inserting comments automatically using TortoiseSVN?

Unfortunately, this limits developers to use only TortoiseSVN. Using Visual Studio plugins, for example, will not work:(

If someone finds any centralized way of how to do this, please, post here.

OTHER TIPS

Look at the red box at the end of this chapter of the SVN book:

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.

I subscribe to the POV that text in red boxes should be taken serious.

According to that thread, you could do that in a pre-commit hook, but it would be a Bad Thing™ If you absolutely must have static text in the file, it would be better to have developers put the text in, and then use the pre-commit hook to verify that it was there. If the static text doesn't exist, or is incorrect, you reject the commit.

How about working on this another way - use a robot. It's a bit more work, but basically: accept the commit into the repository without the required legal section and trigger the robot to have a look (or have the robot look periodically).

The robot then does a checkout/update of the files it looks after, checks their policy and legal notices, automatically adds anything it needs and then checks the changes back in. This way, subversion's caches are happy and the legal notices are on all files. Developerse will pull the changes down on the next update/commit cycle just as they would any other change. You can even have the robot automatically keep the legal section up to date with the latest definition, depending how complex you want it to be.

Might even be able to make use of something like Hudson to host this in a useable framework.

You can install a hook on the SVN server that will execute a script and can append information to the file etc.

There's a tiny bit of information here: http://svnbook.red-bean.com/en/1.4/svn.ref.reposhooks.post-commit.html

That said, why on Earth would you want to do this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top