pw-pull: allow setting pull URL explicitly

For cases where patchwork got completely confused allow
specifying pull URL on the command line.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
diff --git a/README b/README
index d56677d..e97bdb9 100644
--- a/README
+++ b/README
@@ -235,6 +235,9 @@
 
   $ pw-pull -s 12345 -c
 
+Last but not least it can pull from an explicit URL with -P which can be
+useful as well (it will at least provide the merge commit template).
+
 I don't mark as applied from the command line (yet) because I double
 check the tests passed in the UI, anyway.
 
diff --git a/pw-pull b/pw-pull
index e0bd966..4d25883 100755
--- a/pw-pull
+++ b/pw-pull
@@ -14,12 +14,13 @@
 usage()
 {
   cat <<-EOF
-  usage: pw-pull [-p PULL] [-s SERIES] [-c] [-h]
+  usage: pw-pull [-p PULL] [-s SERIES] [-c] [-P PULL_URL] [-h]
 EOF
   exit
 }
 
 pull=""
+pull_url=""
 cover=""
 series=""
 series_branch="tmp"
@@ -29,13 +30,15 @@
     -p | --pull ) pull="$2"; shift 2 ;;
     -s | --series ) series="$2"; shift 2 ;;
     -c | --pull-from-cover ) cover="y"; shift ;;
+    -P | --pull-url ) pull_url="$2"; shift 2 ;;
     -h | --help ) usage; break ;;
     -- ) shift; break ;;
     * )  break ;;
   esac
 done
-[ -z "$pull" ] && [ -z "$cover" ]     && usage
-[ ! -z "$pull" ] && [ ! -z "$cover" ] && usage
+[ -z "$pull" ] && [ -z "$cover" ]        && usage
+[ ! -z "$pull" ] && [ ! -z "$cover" ]    && usage
+[ ! -z "$pull" ] && [ ! -z "$pull_url" ] && usage
 
 srv=$(git config --get pw.server)
 srv=${srv%/} # strip trailing slash
@@ -69,11 +72,13 @@
                         /^Please consider/ {e=1}
                         {if(!e) print}')
 
-  pull_url=$(echo "$cover_json" |
-	       jq -r '.content' |
-	       awk '/^.+$/                      { if (n) {n=0; print} }
-	            /and are available in the git repository at:/ {n=1}')
-  pull_url=$(echo $pull_url)
+  if [ -z "$pull_url" ]; then
+    pull_url=$(echo "$cover_json" |
+		 jq -r '.content' |
+		 awk '/^.+$/                      { if (n) {n=0; print} }
+		      /and are available in the git repository at:/ {n=1}')
+    pull_url=$(echo $pull_url)
+  fi
 
   if [ -z "$pull_url" ]; then
     echo "Unable to parse out pull URL"