Archive for the ‘hook’ tag
Adding Git Email Notifications via Post-receive hook
This was done on Fedora 10 in my case, but should be similar for all distributions. This is set up on a shared ‘central’ repository, where changes are pushed to. That’s why it’s done using the post-receive hook (the repository receives changes).
Step 1: Copy (or symlink) the post-receive script, or download it here. The script must be in the ‘hooks’ directory like this:
$GIT_DIR/hooks/post-receive
I’ve read that on Debian systems, for example, the hook is stored in /usr/share/doc/git-core/contrib/hooks/post-receive-email but i had no luck finding it here on my system.
Make sure it is named “post-receive” so that Git recognizes it.
Step 2: Make sure that the script is executable:
chmod a+x $GIT_DIR/hooks/post-receive
Step 3: Edit the first line of $GIT_DIR/description to be your repository name. This will be in the subject of the email.
Step 4: Edit $GIT_DIR/config with some email settings such as recipient / sender email and subject-line prefix. Here’s some basic settings (read the script for all possible settings).
[hooks]
mailinglist = "receiver1@receivers.com, receiver2@receivers.com"
envelopesender = sender@senders.com
emailprefix = "[GIT] "
Note: you can also set these by using git-config:
git-config hooks.mailinglist "receiver1@receivers.com, receiver2@receivers.com"
git-config hooks.envelopesender sender@senders.com
git-config hooks.emailprefix "[GIT] "
That’s it ! Try doing a git-push to your shared repository, and see if you get email notifications. If not, try tailing your mail log to see what’s wrong (/var/log/maillog).
