From: Jim Bauer <jfbauer@comcast.net>
To: git@vger.kernel.org
Cc: jfbauer@comcast.net
Subject: [PATCH] post-receive-email: Add diffattachment and replyto config options
Date: Sat, 18 Jul 2009 21:44:57 -0400 [thread overview]
Message-ID: <1247967897-14166-1-git-send-email-jfbauer@comcast.net> (raw)
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
reply other threads:[~2009-07-19 1:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1247967897-14166-1-git-send-email-jfbauer@comcast.net \
--to=jfbauer@comcast.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).