How can I set up a Subversion post-commit checkout email?

You can configure your site to automatically check out the current sources from your repository by using Subversion's "hook scripts". In short, the script called 'post-commit' is executed by the web server each time new sources are checked into your repository.

Be advised that when the web server executes this script, it is running in the security context of the dhapache user. This user does not and should not (for security reasons) have the necessary permissions to modify the files in your web site's directory. As such, you must arrange for the post-commit script to run the update in the security context of a user with the privileges necessary to update your site.

Using post-commit.tmpl

  1. Log into your server via SSH.
  2. Navigate to the following file:
    [server]$ cd $HOME/svn/<repository_name>/hooks/post-commit.tmpl
  3. Open the post-commit.tmpl file in a text editor. The following contents are set by default:
    #!/bin/sh
    
    REPOS="$1"
    REV="$2"
    
    "$REPOS"/hooks/mailer.py commit "$REPOS" $REV "$REPOS"/mailer.conf
    
  4. Change it to the following making sure to update the two email addresses to yours:
    #!/bin/sh
    
    REPOS="$1"
    REV="$2"
    
    /usr/share/subversion/hook-scripts/commit-email.pl --from svnaddress@example.com "$REPOS" "$REV" youremail@example.com
    

    The --from section is crucial because the script will fail if it does not have a "from" address. Any email address will do. You can also change the second address to send to any email you like.

  5. Save the file as post-commit (removing the 'tmpl' file extension).

    When you save this as the new file name in your text editor, the permissions change from dhapache to your user, which is what you want. Confirm that the new post-commit file is now owned by your user before continuing.

  6. As the new file should now be owned by your user (NOT dhapache), run the following command:
    [server]$ chmod a+x post-commit
  7. Try a commit with your svn repository. You should now receive a commit notification to your email address.

See also

Did this article answer your questions?

Article last updated .