Notify someone with hook when you update a git working copy

Some projects have production code that runs off of a git cloned repository. There may be a case in which you want to notify others when that clone pulls. It is a pretty easy feat with gits post-merge hook. The post-merge hook will run after a merge (think git pull). All you have to do it create a project/.git/hooks/post-merge shell script and chmod +x it. Next time you pull successfully that script will run. Here is an example.

#!/bin/bash
TEMPLOG=$(mktemp)
echo "Sending email notification of update"
git log --reverse --no-merges --stat @{1}.. > $TEMPLOG
sendEmail -u "Production code update notification" -t [email protected] < $TEMPLOG
rm $TEMPLOG

2 Comments

  • awesselius Ubuntu Firefox 22.0 wrote:

    I’m confused. On row 4 there’s a < and on row 9 there’s another one. How’s that suppose to work?

    On row 4, $TEMPLOG is inserted into the ‘git log…’ statement?

    And again on row 9, $TEMPLOG is inserted also to the sendEmail program? Am I missing something?

  • The first one should have been output redirection.

    Thanks 🙂

Leave a Reply

Your email is never shared.Required fields are marked *

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha