Information Technology Dark Side

Struggles of a Self-Taught Coder

Information Technology Dark Side header image 2

Creating Post-Commit Subversion Hooks with Dreamhost

August 12th, 2008 · 3 Comments

Okay, so this is a little bit afield of what I normally write about, since I don’t normally delve into technical issues. Happily, my work life is becoming more technical and this blog is likely to follow suit, so you might expect more tech and less philosophizing in the future.

If you don’t know, subversion allows you to create “hooks”, actions that are executed when certain events occur in your subversion repository. Some of the events you can use as triggers for your hooks are commits, locks, unlocks, and revision properties changes. You can create pre- and post-hooks, which just means they run before or after the event occurs.

Some examples of how these are used: sending an email to the dev team whenever a commit occurs, kicking off a deployment after a commit, or running a bunch of tests.

I needed some of these hooks for one of my projects, but I couldn’t figure out how to do it at first. Google didn’t help much – most of the examples were really old and looked like really bad ideas. Eventually, I was able to figure it out on my own, but I thought it would be a good idea to post it.

Anyway, it’s pretty easy to set these up with Dreamhost, in spite of what the Google search results will tell you.

The problem with Dreamhost’s subversion install is that all the files are owned by the dhapache user and therefore you can’t make the .tmpl files executable (the .tmpl files are sample hooks provided with the svn install). Normally, you would edit the files you want to use, then use the mv command in ssh to remove the .tmpl files, which is what makes subversion start acting on them. Unfortunately, doing it this way leaves your “hook” with no permission to execute, and you can’t change it.

So, the easiest thing to do is to first copy the hook template you want to use to a new file with no extension (post-commit.tmpl copied to post-commit, for example) and edit it as you like. Then chmod it to 755 and it will work.

That’s all it took. Now, if I exposed some security flaw hopefully one of my readers will know and tell me what a moron I am. I’ll appreciate that.

If you enjoyed this post, make sure you subscribe to my RSS feed!
Stumble it!

Tags: Development

3 responses so far ↓

  • 1 Nilesh // Jan 22, 2009 at 6:53 am

    As mentioned on the wiki, you also need to put "–from" in the last line in the post-commit script (one which uses otherwise sending emails will fail.

  • 2 Mateo // Feb 17, 2009 at 9:30 pm

    Thanks for this simple solution!

  • 3 Dhruv // Jun 8, 2013 at 6:47 am

    I don’t think there is any security breach in changing file permission to 755. That was a quiet easy solution.

Leave a Comment