# how can use post-commit and pre-commit in subversion

## MHL

Hi,

I am trying to do the post-commit and pre-commit hook in my subversion. but I seems it it didn't call my post-commit script and pre-commit script.

I am use per directory repository.

is that a place that I need to change the configuration?

I use Fedora before and install subversion from source and user svnserve -d,

   then I was able to do the pre-directory repository, post-commit script and pre-commit script

thank you very much.

----------

## neilhwatson

You might want to refer to the Subversion book: http://svnbook.red-bean.com/en/1.1/svn-book.html#svn-ch-9-sect-1.2-re-commit

Also, it would be helpful if you could describe what you've done, what the results were and what results you expected.

----------

## MHL

thank you for responding.

I emerged the subversion and run the ebuild script.

I can start the subversion daemon.

I am making a per-directory repository, it is in my /home/projects/$project 

I want to make a pre-commit hook that will dump the database before the user commit

and in the post-commit script. I will commit the dump. 

the scripts can run in command line have no problem.

but they seems not executing when I place then in /home/projects/projectDir/svn/hooks/

----------

## neilhwatson

I've not used hook scripts before.  Are the permissions correct?  What about using the --verbose switch?

Also, from the Subersion book:

Tip

For security reasons, the Subversion repository executes hook scripts with an empty environmentthat is, no environment variables are set at all, not even $PATH or %PATH%. Because of this, a lot of administrators are baffled when their hook script runs fine by hand, but doesn't work when run by Subversion. Be sure to explicitly set environment variables in your hook and/or use absolute paths to programs.

http://svnbook.red-bean.com/en/1.1/svn-book.html#svn-ch-5-sect-2.1

----------

## MHL

I read that part too.

I use the absolute path for the command.

the permission are fine

I have test it with an echo "thest " > someplace have mod 777.

it seems not working

it works fine in the redhat machine. but not in gentoo. that is weir.

----------

## lefou

MHL, do you solved the problem. I'm running into the same issue with apache 2.0.55 and subversion 1.3.0, multi repositories and post-commit get not executed after a commit.

Could you post your (possible) solution here, please.

----------

## arantius

Same thing.

```
$ equery l apache

..

[I--] [  ] net-www/apache-2.0.58-r2 (2)

$ equery l subversion

..

[I--] [  ] dev-util/subversion-1.3.2-r4 (0)

$ ls -l hooks/

total 16

-rwxrwx--- 1 apache apache  564 Jun 21 21:46 post-commit

-rw-rw---- 1 apache apache 7650 Apr 22 11:48 trac-post-commit-hook

$ cat hooks/post-commit

#!/bin/sh

REPOS="$1"

REV="$2"

LOG=`/usr/bin/svnlook log -r $REV $REPOS`

AUTHOR=`/usr/bin/svnlook author -r $REV $REPOS`

TRAC_ENV='/home/t-bone/var/trac/'

TRAC_URL='http://trac.arantius.com/'

echo /usr/bin/python /var/svn/hooks/trac-post-commit-hook \

        -p "$TRAC_ENV"  \

        -r "$REV"       \

        -u "$AUTHOR"    \

        -m "$LOG"       \

        -s "$TRAC_URL" >> /tmp/post-commit.log

/usr/bin/python /var/svn/hooks/trac-post-commit-hook \

        -p "$TRAC_ENV"  \

        -r "$REV"       \

        -u "$AUTHOR"    \

        -m "$LOG"       \

        -s "$TRAC_URL" >> /tmp/post-commit.log

$ ls -l /tmp/post-commit.log

-rw-rw-rw- 1 t-bone apache 688 Jun 21 22:00 /tmp/post-commit.log
```

Post commit hooks are never called.  No output in the log, which is writable to all.  If I just replace it with a call to "mktemp" there is no temporary file created.  Nothing.  Running it manually, beautiful.

All permissions everywhere that I can find to look are fine.  The script works, it just doesn't seem to be called.  No errors in any logs that I can find.

----------

## deurk

Same trouble here...

Not using apache but svnserve but doesn't change the fact that my post-commit is not called at all.

*  dev-util/subversion

      Latest version available: 1.3.2-r4

      Latest version installed: 1.3.2-r4

----------

## deurk

Solved it by changing into /etc/conf.d/svnserve the user launching the server from apache to root.

Not really secure though...

----------

## deurk

A simple 

```
su apache ./post-commit
```

 doesn't even work...

----------

## Hu

Based on the descriptions, I think deurk's problem is different from the one arantius is seeing.

arantius: your script looks fine.  Emerge dev-util/strace, attach it to the process which handles the commit, and watch the system calls it makes.  Start with strace -o apache.strace -f -tt -p <pid-of-server>.  This will be noisy.  You may need to use a service such as http://pastebin.ca/ to hold the data, rather than pasting it directly into a post here.

deurk: if it works as root, that sounds like a permissions problem.  Perhaps you could post the output of ls -la /path/to/repos/hooks, the output of attempting to run the script as Apache, and the contents of your script.

----------

## deurk

I have been working a bit around and figured how to make it run with apache and use the pre-commit hook, but the post-commit hook won't work...

[EDIT] My bad, everything works fine now.

Thanks.

----------

