]>
Commit | Line | Data |
---|---|---|
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 | force=false | |
10 | eval set -- `getopt -- efh "$@"` | |
11 | while [[ -n $1 ]] ; do | |
12 | case $1 in | |
13 | -h|--help) usage;; | |
14 | -e) auto=true;; | |
15 | -f) force=true;; | |
16 | --) shift; break;; | |
17 | -*) usage 1;; | |
18 | *) break; | |
19 | esac | |
20 | shift | |
21 | done | |
22 | ||
23 | commit=${1:-mainline/master} | |
24 | url=$(git config --get remote.pullrequest.url || git config --get remote.origin.url) | |
25 | branch=${2:-master} | |
26 | if [[ ${branch} != master ]] ; then | |
27 | subject=" (${branch} branch)" | |
28 | else | |
29 | subject="" | |
30 | fi | |
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) | |
38 | tmp=$(mktemp) | |
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 | |
43 | cat << EOF > ${tmp} | |
44 | From: ${name} <${email}> | |
45 | Date: $(date -R) | |
46 | Subject: Pull request ${url##*/}${subject} | |
47 | ||
48 | ${request} | |
49 | EOF | |
50 | cat ${tmp} | |
51 | ||
52 | to=$(git config --get sendemail.pullrequest) | |
53 | cc=$(git config --get sendemail.to || git config --get sendemail.pullrequestcc) | |
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} |