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