send-pull-request: allow users to select git-send-email or sendmail
Some users find it easier to use their git sendmail setup over a local MTA to deliver mail with the send-pull-request script. If you would like to do this, please read the git-send-email man page and set the relevant entries in your git config. In particular, be sure to set sendemail.from to avoid being asked each time. Reported-by: Khem Raj <raj.khem@gmail.com> CC: Bruce Ashfield <bruce.ashfield@windriver.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
This commit is contained in:
parent
eca21e6359
commit
585c506cd8
|
@ -1,6 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
AUTO=0
|
AUTO=0
|
||||||
|
|
||||||
|
# Check env for any default settings, command line options will override these.
|
||||||
|
if [ -z "$PULL_MTA" ]; then
|
||||||
|
PULL_MTA="sendmail"
|
||||||
|
fi
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
cat <<EOM
|
cat <<EOM
|
||||||
|
@ -8,6 +13,7 @@ Usage: $(basename $0) [-h] [-a] [[-t email]...] -p pull-dir
|
||||||
-t email Explicitly add email to the recipients
|
-t email Explicitly add email to the recipients
|
||||||
-a Automatically harvest recipients from "*-by: email" lines
|
-a Automatically harvest recipients from "*-by: email" lines
|
||||||
in the patches in the pull-dir
|
in the patches in the pull-dir
|
||||||
|
-g Use git-send-email to send mail instead of sendmail
|
||||||
-p pull-dir Directory containing summary and patch files
|
-p pull-dir Directory containing summary and patch files
|
||||||
EOM
|
EOM
|
||||||
}
|
}
|
||||||
|
@ -35,11 +41,14 @@ harvest_recipients()
|
||||||
|
|
||||||
|
|
||||||
# Parse and verify arguments
|
# Parse and verify arguments
|
||||||
while getopts "ahp:t:" OPT; do
|
while getopts "aghp:t:" OPT; do
|
||||||
case $OPT in
|
case $OPT in
|
||||||
a)
|
a)
|
||||||
AUTO=1
|
AUTO=1
|
||||||
;;
|
;;
|
||||||
|
g)
|
||||||
|
PULL_MTA="git"
|
||||||
|
;;
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -111,25 +120,47 @@ read cont
|
||||||
|
|
||||||
if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then
|
if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then
|
||||||
ERROR=0
|
ERROR=0
|
||||||
for PATCH in $PDIR/*patch; do
|
case "$PULL_MTA" in
|
||||||
# Insert To and CC headers via formail to keep them separate and
|
git)
|
||||||
# appending them to the sendmail command as -- $TO $CC has proven
|
export IFS=$','
|
||||||
# to be an exercise in futility.
|
GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done)
|
||||||
#
|
GIT_CC=$(for R in $CC; do echo -n "--cc='$R' "; done)
|
||||||
# Use tail to remove the email envelope from git or formail as
|
unset IFS
|
||||||
# msmtp (sendmail) would choke on them.
|
for PATCH in $PDIR/*patch; do
|
||||||
#
|
# We harvest the emails manually, so force git not to.
|
||||||
# Modify the patch date for sequential delivery, but retain the
|
eval "git send-email $GIT_TO $GIT_CC --no-chain-reply-to --suppress-cc=all $PATCH"
|
||||||
# original date as "Old-Date".
|
if [ $? -eq 1 ]; then
|
||||||
DATE=$(date +"%a, %d %b %Y %k:%M:%S %z")
|
ERROR=1
|
||||||
cat $PATCH | formail -I "To: $TO" -I "CC: $CC" -i "Date: $DATE" | tail -n +2 | sendmail -t
|
fi
|
||||||
if [ $? -eq 1 ]; then
|
done
|
||||||
ERROR=1
|
;;
|
||||||
fi
|
sendmail)
|
||||||
done
|
for PATCH in $PDIR/*patch; do
|
||||||
|
# Insert To and CC headers via formail to keep them separate and
|
||||||
|
# appending them to the sendmail command as -- $TO $CC has
|
||||||
|
# proven to be an exercise in futility.
|
||||||
|
#
|
||||||
|
# Use tail to remove the email envelope from git or formail as
|
||||||
|
# msmtp (sendmail) would choke on them.
|
||||||
|
#
|
||||||
|
# Modify the patch date for sequential delivery, but retain the
|
||||||
|
# original date as "Old-Date".
|
||||||
|
DATE=$(date +"%a, %d %b %Y %k:%M:%S %z")
|
||||||
|
cat $PATCH | formail -I "To: $TO" -I "CC: $CC" -i "Date: $DATE" | tail -n +2 | sendmail -t
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
ERROR=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "ERROR: unknown MTA: $PULL_MTA"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [ $ERROR -eq 1 ]; then
|
if [ $ERROR -eq 1 ]; then
|
||||||
echo "ERROR: sendmail failed to send one or more messages. Check your"
|
echo "ERROR: Failed to send one or more messages. Check your MTA log for details."
|
||||||
echo " sendmail log for details."
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Send aborted."
|
echo "Send aborted."
|
||||||
|
|
Loading…
Reference in New Issue