So that we don't have specify "-u <contrib>" everytime, and
CONTRIB_REMOTE can be overrided by -u.

[YOCTO #9409]

Signed-off-by: Robert Yang <[email protected]>
---
 scripts/create-pull-request | 66 +++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/scripts/create-pull-request b/scripts/create-pull-request
index 7dc9836..613e7ae 100755
--- a/scripts/create-pull-request
+++ b/scripts/create-pull-request
@@ -45,7 +45,7 @@ Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s 
subject] [-r relative_to
   -p prefix           Use [prefix N/M] instead of [PATCH N/M] as the subject 
prefix
   -r relative_to      Starting commit (default: master)
   -s subject          The subject to be inserted into the summary email
-  -u remote           The git remote where the branch is located
+  -u remote           The git remote where the branch is located, or set 
CONTRIB_REMOTE in env
   -d relative_dir     Generate patches relative to directory
 
  Examples:
@@ -58,6 +58,7 @@ Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s 
subject] [-r relative_to
 EOM
 }
 
+REMOTE="$CONTRIB_REMOTE"
 # Parse and validate arguments
 while getopts "b:cd:hi:m:o:p:r:s:u:l:" OPT; do
        case $OPT in
@@ -101,35 +102,42 @@ while getopts "b:cd:hi:m:o:p:r:s:u:l:" OPT; do
                ;;
        u)
                REMOTE="$OPTARG"
-               REMOTE_URL=$(git config remote.$REMOTE.url)
-               if [ $? -ne 0 ]; then
-                       echo "ERROR: git config failed to find a url for 
'$REMOTE'"
-                       echo
-                       echo "To add a remote url for $REMOTE, use:"
-                       echo "  git config remote.$REMOTE.url <url>"
-                       exit 1
-               fi
-
-               # Rewrite private URLs to public URLs
-               # Determine the repository name for use in the WEB_URL later
-               case "$REMOTE_URL" in
-               *@*)
-                       USER_RE="[A-Za-z0-9_.@][A-Za-z0-9_.@-]*\$\?"
-                       PROTO_RE="[a-z][a-z+]*://"
-                       
GIT_RE="\(^\($PROTO_RE\)\?$USER_RE@\)\([^:/]*\)[:/]\(.*\)"
-                       REMOTE_URL=${REMOTE_URL%.git}
-                       REMOTE_REPO=$(echo $REMOTE_URL | sed "s#$GIT_RE#\4#")
-                       REMOTE_URL=$(echo $REMOTE_URL | sed 
"s#$GIT_RE#git://\3/\4#")
-                       ;;
-               *)
-                       echo "WARNING: Unrecognized remote URL: $REMOTE_URL"
-                       echo "         The pull and browse URLs will likely be 
incorrect"
-                       ;;
-               esac
                ;;
        esac
 done
 
+if [ -z "$REMOTE" ]; then
+       echo "ERROR: Missing parameter -u or CONTRIB_REMOTE in env, no git 
remote!"
+       usage
+       exit 1
+fi
+
+REMOTE_URL=$(git config remote.$REMOTE.url)
+if [ $? -ne 0 ]; then
+       echo "ERROR: git config failed to find a url for '$REMOTE'"
+       echo
+       echo "To add a remote url for $REMOTE, use:"
+       echo "  git config remote.$REMOTE.url <url>"
+       exit 1
+fi
+
+# Rewrite private URLs to public URLs
+# Determine the repository name for use in the WEB_URL later
+case "$REMOTE_URL" in
+*@*)
+       USER_RE="[A-Za-z0-9_.@][A-Za-z0-9_.@-]*\$\?"
+       PROTO_RE="[a-z][a-z+]*://"
+       GIT_RE="\(^\($PROTO_RE\)\?$USER_RE@\)\([^:/]*\)[:/]\(.*\)"
+       REMOTE_URL=${REMOTE_URL%.git}
+       REMOTE_REPO=$(echo $REMOTE_URL | sed "s#$GIT_RE#\4#")
+       REMOTE_URL=$(echo $REMOTE_URL | sed "s#$GIT_RE#git://\3/\4#")
+       ;;
+*)
+       echo "WARNING: Unrecognized remote URL: $REMOTE_URL"
+       echo "         The pull and browse URLs will likely be incorrect"
+       ;;
+esac
+
 if [ -z "$BRANCH" ]; then
        BRANCH=$(git branch | grep -e "^\* " | cut -d' ' -f2)
        echo "NOTE: Assuming remote branch '$BRANCH', use -b to override."
@@ -140,12 +148,6 @@ if [ -z "$L_BRANCH" ]; then
        echo "NOTE: Assuming local branch HEAD, use -l to override."
 fi
 
-if [ -z "$REMOTE_URL" ]; then
-       echo "ERROR: Missing parameter -u, no git remote!"
-       usage
-       exit 1
-fi
-
 if [ $RFC -eq 1 ]; then
        PREFIX="RFC $PREFIX"
 fi
-- 
2.7.4

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to