-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-hook-postcommit-coloremail
executable file
·88 lines (84 loc) · 2.52 KB
/
git-hook-postcommit-coloremail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# git-hook-postcommit-coloremail (part of ossobv/vcutil) // wdoekes/2014
# // Public Domain
#
# Sends out a nice colored e-mail with the committed changeset for
# each committed revision. It uses the awesome vim(1) syntax
# highlighting to colorize the patch files.
#
# Use this for git repositories that are local only.
#
# Installation:
#
# $ cd /path/to/local/git/checkout/.git
# $ ln -s /usr/local/bin/git-hook-postcommit-coloremail hooks/post-commit
#
# Usage:
#
# git-hook-postcommit-coloremail
#
# FAQ:
#
# * I don't want my passwords mailed.
#
# Use the #CENSORED\# tag on the same line, see censored-for-email.
#
# * Committing takes longer than before.
#
# Yes, the email is generated during commit time. That means that
# the submitter of a commit has to wait until the e-mail is
# generated and sent. We could disown this job and have it run in
# the background, if needed.
#
# * Does it cope with non-ASCII?
#
# It is encoding-agnostic. The mail however assumes everything is
# in UTF-8. (And also the subject gets sent verbatim. Any
# non-ASCII in the summary line will be technically invalid, but
# parsed by modern e-mail clients.)
#
# Settings:
MAIL_FROM="noreply@`hostname -d`"
MAIL_TO="commits@localhost" # space separated list of recipients
SUBJECT='[$PROJECT] r$REV: $SUMMARY' # these get expanded later
# Fetch data:
REV="`git log -1 HEAD --format=%h`"
PROJECT="`hostname -s`:`basename "\`pwd\`"`"
SUMMARY="`git log -1 HEAD --format=%s`"
CENSOR=`which censored-for-email 2>/dev/null || which cat`
colormail()
{
txt="`mktemp`" # no --suffix.. debian does not like
head -n1000 > "$txt" # limit mail to 1000 lines
html="$txt.html" # unsafe, but we don't care
yes | vim -n -T builtin_ansi \
-c 'syn on|set syn=diff|set bg=dark|runtime syntax/2html.vim|wqa' \
"$txt" 2>&1 >/dev/null | grep -v '^Vim: Warning: '
# mail the stuff
(
echo 'This is MIME mail.'
echo
echo '--e89a8f3ba551e83b0e04cdf77b8c'
echo 'Content-Type: text/plain; charset=utf-8'
echo
cat "$txt"
echo
echo '--e89a8f3ba551e83b0e04cdf77b8c'
echo 'Content-Type: text/html; charset=utf-8'
echo
cat "$txt.html"
echo
echo '--e89a8f3ba551e83b0e04cdf77b8c--'
) | mail -a 'MIME-Version: 1.0' \
-a 'Content-Type: multipart/alternative; '\
'boundary=e89a8f3ba551e83b0e04cdf77b8c' \
"$@"
# clean up
rm "$txt" "$html"
}
(
# Print log message and diff
git show -p -1 HEAD
echo
) | "$CENSOR" |
colormail -s "`eval echo "$SUBJECT"`" -a "From: $MAIL_FROM" $MAIL_TO