How to add svn hooks with SVNManager in Ubuntu
Recommended Ubuntu book
So, once we set up our svn and SVNManager in Ubuntu, it would probably be nice to get emails every time a user in the repository makes a commit.
Svnmanager supports the post create script, which will be fired every time a new repository gets created. Lets start:
sudo gedit /var/www/svnmanager/config.php
at the end of the config, uncomment and edit the line to:
$post_create_script = "/bin/bash /var/www/newrepo-script";
Now lets create the newrepo-script:
$post_create_script = "/bin/bash /var/www/newrepo-script";
And add these lines:
#!/bin/bash cp -R /var/www/repo-templates/* $1/hooks/
which pretty much just tells to copy the content of the templates folder to the newly created repository’s /hooks/ directory. /hooks directory will execute the hooks that we place there on each event that we create. We will add post-commit hook for this example.
cd /var/www
sudo mkdir repo-templates
now the hook
sudo gedit post-commit
Add these lines and save:
#!/bin/sh REPOS="$1" REV="$2" /usr/bin/svnnotify \ --repos-path "$REPOS" \ --revision "$REV" \ --subject-cx \ --with-diff \ --handler HTML::ColorDiff \ --to to_email@email.com \ --from root@localhost
Feel free to edit the email addresses. Now we need to make the script executable:
sudo chmod +x post-commit
Make sure that you have svnnotify package. Type:
which svnnotify
and if it shows the path, make sure it is the same as we made in post-commit file, if not, edit post-commit file. If path doesn’t show, chances are you don’t have the package installed. Install it by:
sudo apt-get install libsvn-notify-perl
This should do it. If you want to send the emails to every user in the repository, you may have to edit the hook. I found another good tutorial about it here.
Update: I created the hook the way I wanted it, for complete code visit this page – svn post-commit hook in Ubuntu.
August 27th, 2011 09:01
[…] How To Use Ubuntu, Starting From Lucid Lynx « How to add svn hooks with SVNManager in Ubuntu […]