Posts

Showing posts from January, 2010

Daily git commit emails

Git can send an email for each git push into the repository
using the post-receive hook. I wanted to have daily messages, as
opposed to one for each commit. The following script does that:

#!/bin/bash # duration of log (default: daily) as offset since now RELDATE="24 hours ago" # email recipient EMAIL=a@b # bare repository home GITROOT=/opt/git/nexus # branch BRANCH=refs/heads/master cd $GITROOT/hooks # the latest commit NEWREV=`git rev-list -n 1 HEAD` # the latest commit not to report OLDREV=`git rev-list -n 1 --date=relative --until="$RELDATE" HEAD` # only send an email if there are commits if [[ $NEWREV == $OLDREV ]] then exit 0 fi /usr/share/doc/git-core/contrib/hooks/post-receive-email \ $BRANCH $OLDREV $NEWREV | /usr/sbin/sendmail $EMAIL

Change the GITROOT variable to point to the root of your repository and create a daily cron job:

crontab -e

For instance

12 2 * * * /usr/sbin/git-dailylog.sh

Some assumptions:
This might only work for bare repositori…