File tree Expand file tree Collapse file tree 3 files changed +55
-7
lines changed Expand file tree Collapse file tree 3 files changed +55
-7
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,13 @@ init() {
38
38
reconfigure () {
39
39
40
40
# Set the email address for notifications to go to
41
- git config hooks.mailinglist " $notification_emails "
41
+ [ -z " $notification_emails " ] && git config hooks.mailinglist " $notification_emails "
42
42
43
43
# Set the email subject prefix
44
- git config hooks.emailprefix " $notification_emails_prefix "
44
+ [ -z " $notification_emails_prefix " ] && git config hooks.emailprefix " $notification_emails_prefix "
45
+
46
+ # Set filter pattern option
47
+ [ -z " $notification_emails_filter " ] && git config git config hooks.emailfilefilter " $notification_emails_filter "
45
48
}
46
49
47
50
#
Original file line number Diff line number Diff line change 7
7
# Email prefix to aid filtering
8
8
notification_emails_prefix="[config tracker]"
9
9
10
+ # Optional bash regex pattern: any files that are committed and match this
11
+ # pattern will suppress notification emails from being sent.
12
+ notification_emails_filter="(shadow|htpasswd|.key)"
13
+
10
14
# Path to include/exclude files
11
15
include_file="${0%/*}/include.conf"
12
16
exclude_file="${0%/*}/exclude.conf"
Original file line number Diff line number Diff line change 3
3
# Post-commit email hook for git.
4
4
#
5
5
6
- # 2011-08-12
6
+ # 2011-08-16
7
7
#
8
8
9
- mailto=" $( git config hooks.mailinglist) "
10
- subject=" $( git config hooks.emailprefix) $( hostname) commit: $( git rev-parse --short HEAD) - $( git show --pretty=' format:' --name-only | tr -d ' \n' ) "
11
- message=" $( git log -1 -p) "
12
- echo " $message " | mail -s " $subject " " $mailto "
9
+ IFS=$' \n '
10
+
11
+
12
+ files=$( git diff --name-only HEAD^1)
13
+
14
+ #
15
+ # Generates the email to send
16
+ #
17
+ generate_email () {
18
+
19
+ email_header_to=" $( git config hooks.mailinglist) "
20
+ email_header_subject=" $( git config hooks.emailprefix) $( hostname) commit: $( git rev-parse --short HEAD) - $files "
21
+ email_body=" $( git log -1 -p) "
22
+
23
+ cat << -EOF
24
+ To: $email_header_to
25
+ Subject: $email_header_subject
26
+
27
+ $email_body
28
+ EOF
29
+ }
30
+
31
+ #
32
+ # Checks if any of the committed files matched the file filter pattern
33
+ #
34
+ check_file_filter () {
35
+
36
+ filterpattern=" $( git config hooks.emailfilefilter) "
37
+ [ -z " $filterpattern " ] && return 0
38
+
39
+ for file in $files ; do
40
+
41
+ # Abort if file matches filter pattern
42
+ [[ " $file " =~ " $filterpattern " ]] && return 1
43
+
44
+ done
45
+
46
+ return 0
47
+ }
48
+
49
+ # Silently exit if a filename matched the filter pattern
50
+ check_file_filter || exit
51
+
52
+ # Send email
53
+ generate_email | /usr/sbin/sendmail -t
You can’t perform that action at this time.
0 commit comments