* [PATCH] post-receive-email: Add diffattachment and replyto config options
@ 2009-07-19 1:44 Jim Bauer
0 siblings, 0 replies; only message in thread
From: Jim Bauer @ 2009-07-19 1:44 UTC (permalink / raw
To: git; +Cc: jfbauer
This is for those who need or want to have the patches
(from post-receive-email) sent as attachments.
Setting hooks.diffattachment (to anything) will cause a 'git diff'
to be included in the email as an attachment. The email will be
sent via mutt which must be installed.
Setting hooks.replyto will add the Reply-To header to
the email messages.
---
contrib/hooks/post-receive-email | 72 ++++++++++++++++++++++++++++++++++++-
1 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 2a66063..f113969 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -48,6 +48,14 @@
# "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo"
# Be careful if "..." contains things that will be expanded by shell "eval"
# or printf.
+# hooks.diffattachment
+# To include patches as an attachment set this to anything.
+# If you set this, you probably don't want to use the "git show..."
+# example above in hooks.showrev that also caused patches to be included
+# inline as that would duplicate the patch in emails.
+# This requires mutt to work. So it must be installed and in $PATH
+# hooks.replyto
+# If set then the Reply-To email header is set to this value.
#
# Notes
# -----
@@ -173,7 +181,10 @@ generate_email()
describe=$rev
fi
+ subject="${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe"
+
generate_email_header
+ generate_email_announce
# Call the correct body generation function
fn_name=general
@@ -192,16 +203,31 @@ generate_email()
generate_email_header()
{
+ if [ -n "$diffattachment" ]; then
+ return;
+ fi
+
# --- Email (all stdout will be the email)
# Generate header
cat <<-EOF
To: $recipients
- Subject: ${emailprefix}$projectdesc $refname_type, $short_refname, ${change_type}d. $describe
+ Subject: $subject
X-Git-Refname: $refname
X-Git-Reftype: $refname_type
X-Git-Oldrev: $oldrev
X-Git-Newrev: $newrev
+ EOF
+
+ if [ -n "$replyto" ]; then
+ echo "Reply-To: $replyto"
+ fi
+
+ echo ""
+}
+generate_email_announce()
+{
+ cat <<-EOF
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "$projectdesc".
@@ -632,6 +658,12 @@ show_new_revisions()
eval $(printf "$custom_showrev" $onerev)
done
fi
+
+ # Put patch in attachment if desired
+ if [ -n "$diffattachment" ]; then
+ attachment=$temp_dir/diff.txt
+ git diff $revspec > $attachment
+ fi
}
@@ -644,12 +676,24 @@ send_mail()
fi
}
+
+cleanup()
+{
+ rm -rf $temp_dir
+}
+
+
# ---------------------------- main()
# --- Constants
LOGBEGIN="- Log -----------------------------------------------------------------"
LOGEND="-----------------------------------------------------------------------"
+# Create place for temp files and make sure we remove then on exit
+temp_dir=$(mktemp -d /tmp/post-receive.XXXXXXXXXX)
+trap cleanup 0 2 15
+
+
# --- Config
# Set GIT_DIR either from the working directory, or from the environment
# variable.
@@ -672,6 +716,9 @@ announcerecipients=$(git config hooks.announcelist)
envelopesender=$(git config hooks.envelopesender)
emailprefix=$(git config hooks.emailprefix || echo '[SCM] ')
custom_showrev=$(git config hooks.showrev)
+diffattachment=$(git config hooks.diffattach)
+replyto=$(git config hooks.replyto)
+
# --- Main loop
# Allow dual mode: run from the command line just like the update hook, or
@@ -684,6 +731,27 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
else
while read oldrev newrev refname
do
- generate_email $oldrev $newrev $refname | send_mail
+ if [ -z "$diffattachment" ]; then
+ generate_email $oldrev $newrev $refname | send_mail
+ else
+ body=$temp_dir/body
+ generate_email $oldrev $newrev $refname > $body
+ if [ -n "$attachment" ]; then
+ attach_args="-a $attachment"
+ fi
+
+ if [ -n "$replyto" ]; then
+ export REPLYTO="$replyto"
+ fi
+
+ mutt -f /dev/null -s "$subject" \
+ -e "my_hdr X-Git-Refname: $refname" \
+ -e "my_hdr X-Git-Reftype: $refname_type" \
+ -e "my_hdr X-Git-Oldrev: $oldrev" \
+ -e "my_hdr X-Git-Newrev: $newrev" \
+ $attach_args $recipients < $body
+ rm -f $body $attachment
+ unset attachment
+ fi
done
fi
--
1.6.3.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-07-19 1:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-19 1:44 [PATCH] post-receive-email: Add diffattachment and replyto config options Jim Bauer
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).