summaryrefslogtreecommitdiffstats
path: root/scripts/create-pull-request
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/create-pull-request')
-rwxr-xr-xscripts/create-pull-request240
1 files changed, 240 insertions, 0 deletions
diff --git a/scripts/create-pull-request b/scripts/create-pull-request
new file mode 100755
index 0000000000..503248bbf0
--- /dev/null
+++ b/scripts/create-pull-request
@@ -0,0 +1,240 @@
1#!/bin/bash
2#
3# Copyright (c) 2010-2013, Intel Corporation.
4# All Rights Reserved
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14# the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20
21#
22# This script is intended to be used to prepare a series of patches
23# and a cover letter in an appropriate and consistent format for
24# submission to Open Embedded and The Yocto Project, as well as to
25# related projects and layers.
26#
27
28ODIR=pull-$$
29RELATIVE_TO="master"
30COMMIT_ID="HEAD"
31PREFIX="PATCH"
32RFC=0
33
34usage() {
35CMD=$(basename $0)
36cat <<EOM
37Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s subject] [-r relative_to] [-i commit_id] -u remote [-b branch]
38 -b branch Branch name in the specified remote (default: current branch)
39 -c Create an RFC (Request for Comment) patch series
40 -h Display this help message
41 -i commit_id Ending commit (default: HEAD)
42 -m msg_body_file The file containing a blurb to be inserted into the summary email
43 -o output_dir Specify the output directory for the messages (default: pull-PID)
44 -p prefix Use [prefix N/M] instead of [PATCH N/M] as the subject prefix
45 -r relative_to Starting commit (default: master)
46 -s subject The subject to be inserted into the summary email
47 -u remote The git remote where the branch is located
48
49 Examples:
50 $CMD -u contrib -b nitin/basic
51 $CMD -u contrib -r distro/master -i nitin/distro -b nitin/distro
52 $CMD -u contrib -r master -i misc -b nitin/misc -o pull-misc
53 $CMD -u contrib -p "RFC PATCH" -b nitin/experimental
54EOM
55}
56
57# Parse and validate arguments
58while getopts "b:chi:m:o:p:r:s:u:" OPT; do
59 case $OPT in
60 b)
61 BRANCH="$OPTARG"
62 ;;
63 c)
64 RFC=1
65 ;;
66 h)
67 usage
68 exit 0
69 ;;
70 i)
71 COMMIT_ID="$OPTARG"
72 ;;
73 m)
74 BODY="$OPTARG"
75 if [ ! -e "$BODY" ]; then
76 echo "ERROR: Body file does not exist"
77 exit 1
78 fi
79 ;;
80 o)
81 ODIR="$OPTARG"
82 ;;
83 p)
84 PREFIX="$OPTARG"
85 ;;
86 r)
87 RELATIVE_TO="$OPTARG"
88 ;;
89 s)
90 SUBJECT="$OPTARG"
91 ;;
92 u)
93 REMOTE="$OPTARG"
94 REMOTE_URL=$(git config remote.$REMOTE.url)
95 if [ $? -ne 0 ]; then
96 echo "ERROR: git config failed to find a url for '$REMOTE'"
97 echo
98 echo "To add a remote url for $REMOTE, use:"
99 echo " git config remote.$REMOTE.url <url>"
100 exit 1
101 fi
102
103 # Rewrite private URLs to public URLs
104 # Determine the repository name for use in the WEB_URL later
105 case "$REMOTE_URL" in
106 *@*)
107 USER_RE="[A-Za-z0-9_.@][A-Za-z0-9_.@-]*\$\?"
108 PROTO_RE="[a-z][a-z+]*://"
109 GIT_RE="\(^\($PROTO_RE\)\?$USER_RE@\)\([^:/]*\)[:/]\(.*\)"
110 REMOTE_URL=${REMOTE_URL%.git}
111 REMOTE_REPO=$(echo $REMOTE_URL | sed "s#$GIT_RE#\4#")
112 REMOTE_URL=$(echo $REMOTE_URL | sed "s#$GIT_RE#git://\3/\4#")
113 ;;
114 *)
115 echo "WARNING: Unrecognized remote URL: $REMOTE_URL"
116 echo " The pull and browse URLs will likely be incorrect"
117 ;;
118 esac
119 ;;
120 esac
121done
122
123if [ -z "$BRANCH" ]; then
124 BRANCH=$(git branch | grep -e "^\* " | cut -d' ' -f2)
125 echo "NOTE: Assuming remote branch '$BRANCH', use -b to override."
126fi
127
128if [ -z "$REMOTE_URL" ]; then
129 echo "ERROR: Missing parameter -u, no git remote!"
130 usage
131 exit 1
132fi
133
134if [ $RFC -eq 1 ]; then
135 PREFIX="RFC $PREFIX"
136fi
137
138
139# Set WEB_URL from known remotes
140WEB_URL=""
141case "$REMOTE_URL" in
142 *git.yoctoproject.org*)
143 WEB_URL="http://git.yoctoproject.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH"
144 ;;
145 *git.pokylinux.org*)
146 WEB_URL="http://git.pokylinux.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH"
147 ;;
148 *git.openembedded.org*)
149 WEB_URL="http://cgit.openembedded.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH"
150 ;;
151 *github.com*)
152 WEB_URL="https://github.com/$REMOTE_REPO/tree/$BRANCH"
153 ;;
154esac
155
156# Perform a sanity test on the web URL. Issue a warning if it is not
157# accessible, but do not abort as users may want to run offline.
158if [ -n "$WEB_URL" ]; then
159 wget --no-check-certificate -q $WEB_URL -O /dev/null
160 if [ $? -ne 0 ]; then
161 echo "WARNING: Branch '$BRANCH' was not found on the contrib git tree."
162 echo " Please check your remote and branch parameter before sending."
163 echo ""
164 fi
165fi
166
167if [ -e $ODIR ]; then
168 echo "ERROR: output directory $ODIR exists."
169 exit 1
170fi
171mkdir $ODIR
172
173
174# Generate the patches and cover letter
175git format-patch -M40 --subject-prefix="$PREFIX" -n -o $ODIR --thread=shallow --cover-letter $RELATIVE_TO..$COMMIT_ID > /dev/null
176
177
178# Customize the cover letter
179CL="$ODIR/0000-cover-letter.patch"
180PM="$ODIR/pull-msg"
181git request-pull $RELATIVE_TO $REMOTE_URL $COMMIT_ID >> "$PM"
182if [ $? -ne 0 ]; then
183 echo "ERROR: git request-pull reported an error"
184 exit 1
185fi
186
187# The cover letter already has a diffstat, remove it from the pull-msg
188# before inserting it.
189sed -n "0,\#$REMOTE_URL# p" "$PM" | sed -i "/BLURB HERE/ r /dev/stdin" "$CL"
190rm "$PM"
191
192# If this is an RFC, make that clear in the cover letter
193if [ $RFC -eq 1 ]; then
194(cat <<EOM
195Please review the following changes for suitability for inclusion. If you have
196any objections or suggestions for improvement, please respond to the patches. If
197you agree with the changes, please provide your Acked-by.
198
199EOM
200) | sed -i "/BLURB HERE/ r /dev/stdin" "$CL"
201fi
202
203# Insert the WEB_URL if there is one
204if [ -n "$WEB_URL" ]; then
205 echo " $WEB_URL" | sed -i "\#$REMOTE_URL# r /dev/stdin" "$CL"
206fi
207
208
209# If the user specified a message body, insert it into the cover letter and
210# remove the BLURB token.
211if [ -n "$BODY" ]; then
212 sed -i "/BLURB HERE/ r $BODY" "$CL"
213 sed -i "/BLURB HERE/ d" "$CL"
214fi
215
216# If the user specified a subject, replace the SUBJECT token with it.
217if [ -n "$SUBJECT" ]; then
218 sed -i -e "s/\*\*\* SUBJECT HERE \*\*\*/$SUBJECT/" "$CL"
219fi
220
221
222# Generate report for user
223cat <<EOM
224The following patches have been prepared:
225$(for PATCH in $(ls $ODIR/*); do echo " $PATCH"; done)
226
227Review their content, especially the summary mail:
228 $CL
229
230When you are satisfied, you can send them with:
231 send-pull-request -a -p $ODIR
232EOM
233
234# Check the patches for trailing white space
235egrep -q -e "^\+.*\s+$" $ODIR/*
236if [ $? -ne 1 ]; then
237 echo
238 echo "WARNING: Trailing white space detected at these locations"
239 egrep -nH --color -e "^\+.*\s+$" $ODIR/*
240fi