Create post-commit triggers for Subversion commit messages
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A simple DSL for defining callbacks to be fired as Subversion hooks with built-in support for inspecting the repository and sending out e-mails.

Example Usage

This library is intended for use as a Subversion post-commit hook. It allows you to define callbacks that fire when certain conditions on a revision are met. Simply require Subtrigger and define your rules:

require 'subtrigger'

on /deploy to (\w+)/ do |revision, matches|
  puts "Should deploy to #{matches[:message].first}"

Save this as a file in your Subversion repository, like /path/to/repo/hooks/deploy.rb. Then in your Subversion commit hook file (/path/to/repo/hooks/post-commit) simply call the file using Ruby:

/usr/bin/ruby -rubygems /path/to/repo/hooks/deploy.rb "$1" "$2"

You could define triggers to...

  • Send out confirmation e-mails to specific developers
  • Auto-update a working copy on a production server
  • Create a back-up archive
  • Whatever else you can do with Ruby…

Detailed usage


The default usage in the example above uses a regular expression which by default will be matched against the log message of the revision that triggers the hook. But you can test both other attributes and with other objects (basically anything that responds to #===).

# Test on author name
# You can use `:author`, `:message`, `:date`,
# `:number`
on :author => /john|graham|michael|terry/ do
  puts 'Always look on the bright side of life!'

# Test using a matcher object
class EvenNumberMatcher
  def ===(revision)
    revision.number % 2 == 0
on :number => do
  puts 'The revision number is an even number'

Sending e-mails

Subtrigger uses Pony to enable the sending of e-mails straigt from your triggers. This means you can send an e-mail when a branch is created, just to name an example.

on /confirm via email/ do
  mail :to      => '',
       :from    => '',
       :subject => 'E-mail confirmation of commit',
       :body    => 'Your commit has been saved.'

Inline templates

To remove long strings from your templates you can define templates right in your rules file.

on /confirm via email/ do |r|
  mail :to      => '',
       :from    => '',
       :subject => 'E-mail confirmation of commit',
       :body    => template('E-mail confirmation', r.number)
@@ E-mail confirmation
Your commit (%s) has been saved
@@ Other template

This will result in an e-mail like Your commit (5299) has been saved.

Running the triggers

Note that all triggers are run when your rules file ends (using the global at_exit callback). There's no need to explicitly start this process yourself.


Note that subversion calls its hooks in an empty environment, so there's no $PATH or anything. Always use full absolute paths. Also, hooks are notoriously hard to debug, so make sure to write some debugging information somewhere so you know what is going on.


Note that Subtrigger is still in early stages of development. Until it hits 1.0 there are bound to be major changes.

See for a detailed changelog.


Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.