Subversion Post-Commit Hooks

I came across this and I find it in order to share with my readers.

The “Hello World!” of Subversion post-commit hooks is the use of SVNnotify to send e-mails out to a project team every time a new revision is committed to the repository.

This is easier than it sounds:

Make sure svnnotify is installed on your system. I’ll leave that as an exercise for the reader.

Navigate to your repository’s hooks directory. This is almost always a directory cleverly named “hooks” right inside the top level of your repository:

cd /Users/mwest/svn/my_repository/hooks/

Create a new file called post-commit, and make it executable by the www user.


touch ./post-commit

chmod 755 ./post-commit

Open up the file you just created, and add the following bit of code:


#!/bin/sh

REPOS="$1"

REV="$2"

/usr/local/bin/svnnotify \

--repos-path "$REPOS" \

--revision "$REV" \

--subject-cx \

--with-diff \

--handler HTML::ColorDiff \

--to \

--from

It’s all pretty straightforward, so let’s take it line by line:

The first line is the so-called shebang that tells the system that the file is a shell script that ought be executed.

Next, we set two variables based on the information that Subversion passes into the script when it’s called. The post-commit hook gets two bits of data: the path to the repository, and the new revision number that the commit created.

Finally, we call svnnotify to actually generate and send a nicely formatted e-mail using the repository path and revision number that we gathered earlier. Make sure to put your e-mail address (or list’s address) in the last two lines!

Do some work, and commit it. Go check your email

Happy coding 🙂

Advertisements

Tags: , , ,

About Piusn

Enthusiastic Software Developer

What's your thought on the subject?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: