#!/bin/bash usage() { echo "Usage: git-request-pull-send-email [branch]" exit ${1:-0} } auto=false force=false eval set -- `getopt -- efh "$@"` while [[ -n $1 ]] ; do case $1 in -h|--help) usage;; -e) auto=true;; -f) force=true;; --) shift; break;; -*) usage 1;; *) break; esac shift done commit=${1:-mainline/master} url=$(git config --get remote.pullrequest.url || git config --get remote.origin.url) branch=${2:-master} if [[ ${branch} != master ]] ; then subject=" (${branch} branch)" else subject="" fi if [[ -z ${commit} ]] || [[ -n $3 ]] ; then usage 1 fi name=$(git config --get user.name) email=$(git config --get user.email) tmp=$(mktemp) if ! request=$(PAGER= git request-pull ${commit} ${url} ${branch}) ; then ${force} || exit 1 request=$(echo "${request}" | sed "s:..BRANCH.NOT.VERIFIED..:${branch}:") fi cat << EOF > ${tmp} From: ${name} <${email}> Date: $(date -R) Subject: Pull request ${url##*/}${subject} ${request} EOF cat ${tmp} to=$(git config --get sendemail.pullrequest) cc=$(git config --get sendemail.to || git config --get sendemail.pullrequestcc) if ${auto} ; then git send-email --to "${to}" --cc "${cc}" ${tmp} else echo git send-email --to \"${to}\" --cc \"${cc}\" ... 1>&2 fi rm -f ${tmp}