2

Background
I'm trying to implement a number of commit hooks for Subversion. I have done a lot of research to try and get a simple test hook to work, however I have had no luck.

For reference I have looked through, followed and then tried to combine methods from the following links:
1. Subversion manual for directory configuration
2. Tortoisevn manual for server side hook scripts
3. An explanation on server side hooks that contains a link to the Subversion manual
4. The wordaligned tutorial for pre-commit hooks
5. A serverfault answer for problems with commit-hooks

There are also a number of other sites that I have referenced and used, but I still cannot get commit hooks to work.

My Environment
My machine is running RHEL6 (Cent OS).
The subversion is located on a remote machine that I cannot access directly without permission from my supervisor.
The remote machine is running Subversion 1.6.

This is the current structure for my repository:

test-for-svn-hooks
|-branches
|-hooks
| +-pre-commit
|-tags
+-trunk  

The file pre-commit temporarily has it permissions set to 777. All directories have their permissions set to 775.

This is the sample script that I created to test the commit hook:

#!/usr/bin/env bash

echo "THOU SHALL NOT PASS" 1>&2

exit 1

I have checked and tested about all that I can to make sure that my pre-commit hook is working appropriately. I don't know what else I need to check to make sure that it works. I'm able to commit whatever I like, and I get no messages output to my screen.

Questions
1. Is there anything that I have missed or overlooked in implementing hooks?
2. If I implement a hook in this fashion do I have to worry about implementing the same hook again in Tortoisesvn?

Any feedback and/or suggestions are greatly appreciated.

  • I am also looking at using Jenkins as a possible solution for this. It will output extra information as well. – Dodzi Dzakuma May 8 '14 at 2:48
  • 1
    If you run the hook script directly, it works, right? /path/to/test-for-svn-hooks/hooks/pre-commit – janos Dec 26 '14 at 17:37
  • Client that you commit from, is using this test-for-svn-hooks repository right? Confirm with svn info in the client. – janos Dec 26 '14 at 17:39
1
  1. Is there anything that I have missed or overlooked in implementing hooks?

Don't use permission 777. Sometimes this can actually be counterproductive. Some tools might not work with such suspicious permissions. In your case this is unlikely to be the problem, because it works for me with this setting. But just don't do it. Change it to 755.

Another sanity check to do is running the hook script directly on the server:

/path/to/test-for-svn-hooks/hooks/pre-commit

When you're script has more meaningful content, then you should test with proper parameters too, for example:

/path/to/test-for-svn-hooks/hooks/pre-commit /path/to/test-for-svn-hooks TXN

Next, test it using a checkout on the server itself, for example:

svn co /path/to/test-for-svn-hooks /tmp/test1
cd /tmp/test1
date > date.txt
svn add date.txt
svn ci -m 'added some junk'

Based on what you've written in your post, these steps should work. I don't know the details of the conditions under which your tests are failing. If you can reach to this point, then perhaps you will see the reason for your failed tests.

  1. If I implement a hook in this fashion do I have to worry about implementing the same hook again in Tortoisesvn?

No. Hooks are defined on the server side. No need to do anything at the client side. All clients will be subject to the rules your define in the pre-commit hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.