From 4759da4e208f3c9918862486ff0d7f870314c0cd Mon Sep 17 00:00:00 2001 From: Érico Rolim Date: Mon, 22 Jun 2020 02:32:38 -0300 Subject: Support curl, auto detect which one to use. Closes: #2 [via git-merge-pr] --- git-merge-pr | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/git-merge-pr b/git-merge-pr index 2d11511..03259b7 100755 --- a/git-merge-pr +++ b/git-merge-pr @@ -16,8 +16,19 @@ PROJECT=${URL%.git} PROJECT=${PROJECT##*:} PROJECT=${PROJECT#//github.com/} +if command -v wget >/dev/null; then + API_CMD="wget -q -O --header" + PATCH_CMD="wget -nv -O" +elif command -v curl >/dev/null; then + API_CMD="curl -s -H" + PATCH_CMD="curl -Lo" +else + echo "Neither wget or curl could be found in PATH" + exit 1 +fi + if [ -z "$PR" ]; then - wget -q -O- --header 'Accept: application/json' \ + $API_CMD 'Accept: application/json' \ "https://api.github.com/repos/${PROJECT}/pulls" | jq -r 'if length > 0 then reverse[] | "\(.number) <\(.user.login)> \(.title)" @@ -29,7 +40,7 @@ fi PATCH="$(mktemp)" trap "rm -f $PATCH" INT TERM EXIT -wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch +$PATCH_CMD "$PATCH" https://github.com/$PROJECT/pull/"$PR".patch WHITESPACE="$(git config --get merge-pr.whitespace || true)" git am "--whitespace=${WHITESPACE:-warn}" "$@" "$PATCH" -- cgit 1.4.1