]> git.wh0rd.org - home.git/blob - .bin/git-format-request-pull
fall back to sendemail.pullrequestcc for git-format-request-pull
[home.git] / .bin / git-format-request-pull
1 #!/bin/bash
2
3 usage() {
4 echo "Usage: git-request-pull-send-email <commit> [branch]"
5 exit ${1:-0}
6 }
7
8 auto=false
9 eval set -- `getopt -- eh "$@"`
10 while [[ -n $1 ]] ; do
11 case $1 in
12 -h|--help) usage;;
13 -e) auto=true;;
14 --) shift; break;;
15 -*) usage 1;;
16 *) break;
17 esac
18 shift
19 done
20
21 commit=${1:-mainline/master}
22 url=$(git config --get remote.origin.url)
23 branch=${2:-master}
24 if [[ ${branch} != master ]] ; then
25 subject=" (${branch} branch)"
26 else
27 subject=""
28 fi
29
30 if [[ -z ${commit} ]] || [[ -n $3 ]] ; then
31 usage 1
32 fi
33
34 name=$(git config --get user.name)
35 email=$(git config --get user.email)
36 tmp=$(mktemp)
37 request=$(PAGER= git request-pull ${commit} ${url} ${branch}) || exit 1
38 cat << EOF > ${tmp}
39 From: ${name} <${email}>
40 Date: $(date -R)
41 Subject: Pull request ${url##*/}${subject}
42
43 ${request}
44 EOF
45 cat ${tmp}
46
47 to=$(git config --get sendemail.pullrequest)
48 cc=$(git config --get sendemail.to || git config --get sendemail.pullrequestcc)
49 if ${auto} ; then
50 git send-email --to "${to}" --cc "${cc}" ${tmp}
51 else
52 echo git send-email --to \"${to}\" --cc \"${cc}\" ... 1>&2
53 fi
54 rm -f ${tmp}