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