Tag Archive for 'pre-commit'

Intro to Pre-Commit Hook Scripts

Hook scripts are executable programs that Apache Subversion users can configure to be triggered by a specific repository event.

When you install Subversion, a ‘hook’ directory is created automatically that contains templates of all the available hook scripts. These .tmpl files contain info about that particular hook script, alongside details on the data that’s passed from Subversion when the hook script is executed.

One hook script is the pre-commit hook script, which executes when a commit transaction happens, but before any changes are applied to the repository. With pre-commit hook scripts, Subversion passes two pieces of information to the hook script: the name of the repository and a uniquely generated name or code for the transaction being committed.

A Basic Pre-Commit Hook Script

Hook scripts work by either exiting with a ‘0,’ which allows the transaction to happen, or by exiting with a ‘1’ which blocks all commits. In this basic example, we’ll show how the ‘exit 1’ command can be used to prevent all transactions.

Locate the pre-commit hook script in the hook directory.

Open the file and replace the text with:

exit 1

This will block all commits, from all users. When you try and commit, you should see a similar message to the one below:

Need more info?

A free replay of our ‘All About Hook Scripts’ webinar is available now. This webinar offers further examples of hook scripts, including start-commit, pre-revproper-change, and pre- and post-lock hook scripts.