path: root/scripts/create-pull-request
diff options
authorDarren Hart <>2010-11-06 09:42:28 -0400
committerRichard Purdie <>2010-11-10 21:22:27 +0800
commit1f0e2cf16afdc7d8e895a28d45b0d956144c56d6 (patch)
treec15ef0b5559076b515529ebe4bb986405c01fef1 /scripts/create-pull-request
parent09ee361d42634687e1dd130af8e343332320bf83 (diff)
git-pull: add the new create-pull-request script
The previous create-pull-request only generated a cover letter. When used to send to the list, it did not include the patches, which made it difficult to perform peer review. A pull request without patches is typically only sent by a maintainer. As we are not all maintainers, we need a means to easily submit patches for review. As we are accustomed to making pull requests, this script retains a git-pull-style cover letter, while sending the relevant patches as responses to the pull. This will provide the necessary context for peer review, and still allow people to collapse threads and see no more mail than they were previously. This version retains the relative_to, commit_id, and contrib_branch arguments from the original, along with their default values. It adds several more, resulting in a highly flexible tool. The script creates a pull directory (pull-$$ by default, configurable via the -o option) and populates it with a git-format-patch generated patch series and cover letter. The cover letter is modified to include the git and http pull URLs and branch name, as well as a basic signature from the author pulled from git's and config. git-format-patch provides the shortlog and diffstat of the series. Breaking a bit from the original, this script maintains the [PATCH] subject prefix in the cover letter (as opposed to [GIT PULL]. This is better suited to the majority of developers (who are not maintainers). This prefix is configurable with the -p option, allowing you to create an [RFC PATCH] prefix, for example. By default, the generated cover letter with contain "*** SUBJECT HERE ***" and "*** BLURB HERE ***" tokens which you should replace with something appropriate prior to sending the messages. When developing multiple versions of a patch series, it can save time to maintain a message.txt file, rather than having to retype the message body of the cover letter every time. The -m option allows you to specify a message file and replace the "*** BLURB HERE ***" token of the cover letter with the contents of the message file. Finally, the -s option will replace the "*** SUBJECT HERE ***" token in the cover letter with the specified subject. The generated patches are suitable for sending via sendmail. Signed-off-by: Darren Hart <> CC: Nitin A Kamble <> CC: Richard Purdie <> CC: Saul Wold <> CC: Bruce Ashfield <>
Diffstat (limited to 'scripts/create-pull-request')
1 files changed, 129 insertions, 0 deletions
diff --git a/scripts/create-pull-request b/scripts/create-pull-request
new file mode 100755
index 0000000000..5ad7666ab3
--- /dev/null
+++ b/scripts/create-pull-request
@@ -0,0 +1,129 @@
+usage() {
+CMD=$(basename $0)
+cat <<EOM
+Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s subject] [-r relative_to] [-i commit_id] -b contrib_branch
+ -h Display this help message
+ -o output_dir Specify the output directory for the messages (default: pull-PID)
+ -m msg_body_file The file containing a blurb to be inserted into the summary email
+ -r relative_to Starting commit (default: master)
+ -i commit_id Ending commit (default: HEAD)
+ -b contrib_branch Branch-name in the tree
+ -s subject The subject to be inserted into the summary email
+ -p prefix Use [prefix N/M] instead of [PATCH N/M] as the subject prefix
+ Examples:
+ $CMD -b nitin/basic
+ $CMD -r distro/master -i nitin/distro -b nitin/distro
+ $CMD -r master -i misc -b nitin/misc -o pull-misc
+ $CMD -p "RFC PATCH" -b nitin/experimental
+# Parse and validate arguments
+while getopts "b:hi:m:o:r:s:p:" OPT; do
+ case $OPT in
+ b)
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ i)
+ ;;
+ m)
+ if [ ! -e "$BODY" ]; then
+ echo "ERROR: Body file does not exist"
+ exit 1
+ fi
+ ;;
+ o)
+ ;;
+ p)
+ ;;
+ r)
+ ;;
+ s)
+ ;;
+ esac
+if [ -z "$CONTRIB_BRANCH" ]; then
+ usage
+ exit 1
+# Perform a sanity test on the web URL. Issue a warning if it is not
+# accessible, but do not abort as users may want to run offline.
+wget -q $WEB_URL -O /dev/null
+if [ $? -ne 0 ]; then
+ echo "WARNING: Branch '$CONTRIB_BRANCH' was not found on the contrib git tree."
+ echo " Please check your contrib-branch parameter before sending."
+ echo ""
+if [ -e $ODIR ]; then
+ echo "ERROR: output directory $ODIR exists."
+ exit 1
+mkdir $ODIR
+# Generate the patches and cover letter
+git format-patch -M --subject-prefix="$PREFIX" -n -o $ODIR --thread=shallow --cover-letter $RELATIVE_TO..$COMMIT_ID > /dev/null
+# Customize the cover letter
+(cat <<EOM
+ Browse: $WEB_URL
+ $(git config <$(git config>
+) | sed -i "/BLURB HERE/ r /dev/stdin" "$CL"
+# If the user specified a message body, insert it into the cover letter and
+# remove the BLURB token.
+if [ -n "$BODY" ]; then
+ sed -i "/BLURB HERE/ r $BODY" "$CL"
+ sed -i "/BLURB HERE/ d" "$CL"
+# If the user specified a subject, replace the SUBJECT token with it.
+if [ -n "$SUBJECT" ]; then
+ sed -i -e "s/\*\*\* SUBJECT HERE \*\*\*/$SUBJECT/" "$CL"
+# Generate report for user
+cat <<EOM
+The following patches have been prepared:
+$(for PATCH in $(ls $ODIR/*); do echo " $PATCH"; done)
+Review their content, especially the summary mail:
+ $CL
+When you are satisfied, you can send them with:
+ send-pull-request -a -p $ODIR