Subversion hooks are now exposed

January 15, 2007

We just deployed the ability to specify pre-commit and post-commit hooks. You can now hook into the commit process with your own web scripts, allowing you to handle commit events however you like!

The Admin now has a Hooks section where you can specify your own hook scripts. We currently support pre-commit, which happens before a commit happens, and post-commit, which happens after a commit. Post-commit is used most often for uses such as to drive an auto-build/deploy/package process or to notify a mailing list or IRC of the commit.

Pre-commit is used less often, but can be used to prevent commits when, for example, a log message isn’t provided. It could also be used to implement your own authorization scheme. Since we’re using HTTP for these hooks (hence they are web hooks), the way you tell us to prevent the commit with the pre-commit hook is to return 400 Bad Request, which we’re using here as a general error code to mimick the behavior of a shell script error code. Any output returned in the body will be displayed as the reason.

In both hooks, we pass useful information relevant to the commit, including the author, log message, project name, and depending on whether it’s pre-commit or post-commit, the transaction number or the revision number respectively. This information will be properly documented at some point, but since you’re all developers, I have no doubt you can easily figure it out with one or two lines of code to experiment with it. Hint: send yourself an email that displays all POST variables.

However, I put up a script that I used to debug and test the pre-commit hook’s ability to prevent commits. You can find this script here. If you put the URL of that script in your project’s pre-commit hook field right now, you will not be able to commit to your project. The script simply always returns 400 with a message letting you know you’re using a test script as your pre-commit hook. You can use this to try out hook functionality right now.

-Jeff

Leave a Reply

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: