Skip to content

Instantly share code, notes, and snippets.

@ptitfred
Created August 28, 2010 20:28
Show Gist options
  • Save ptitfred/555537 to your computer and use it in GitHub Desktop.
Save ptitfred/555537 to your computer and use it in GitHub Desktop.
Hook for Git emailing content of a push
#!/bin/bash
refname="$1"
oldrev="$2"
newrev="$3"
PATH=~/bin:$PATH
if [ -z "$GIT_DIR" ]; then
echo "Don't run this script from the command line." >&2
echo " (if you want, you could supply GIT_DIR then run ">&2
echo " $0 <ref> <oldrev> <newrev>)" >&2
exit 1
fi
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
exit 1
fi
# --- Config
sender=$(git config push.mail.sender)
maildest=$(git config push.mail.tos)
if [ -z "$maildest" ]; then
exit 0
fi
oldshort=$(git short $oldrev)
newshort=$(git short $newrev)
branch=$(echo $refname | sed ':^/refs/heads/:!d' | wc -l )
tag=$(echo $refname | sed ':^/refs/tags/:!d' | wc -l)
if [ $branch == 1 ]; then
branchname=$(echo $refname | cut -b12-)
if [ "$oldrev" != "0000000000000000000000000000000000000000" ]; then
subject="push on $branchname"
content=$(git shortlog $oldrev..$newrev)
echo $branchname $oldrev..$newrev
else
subject="new branch $branchname"
echo $subject
fi
elif [ $tag == 1 ]; then
tagname=$(echo $refname | cut -b11-)
subject="new tag $tagname"
echo $subject
fi
cat <<EOF | sendmail -t
From: $sender
To: $maildest
Subject: $subject
Content-type: text/html
<html><body>
<h4>Contenu du push sur proto</h4>
<code>$oldshort..$newshort</code>
<pre>$content</pre>
</body></html>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment