about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xgit-merge-pr23
1 files changed, 23 insertions, 0 deletions
diff --git a/git-merge-pr b/git-merge-pr
new file mode 100755
index 0000000..07a8386
--- /dev/null
+++ b/git-merge-pr
@@ -0,0 +1,23 @@
+#!/bin/sh
+# git merge-pr PRNUM[@REMOTE] [GIT-AM FLAGS...] - apply GitHub pull request from command-line
+set -e
+
+PR=${1?no pull request given}
+REMOTE=
+case "$PR" in
+*@*)
+	REMOTE=${PR#*@}
+	PR=${PR%%@*};;
+esac
+shift
+
+URL=$(git ls-remote --get-url $REMOTE)
+
+PROJECT=${URL%.git}
+PROJECT=${PROJECT##*:}
+PROJECT=${PROJECT#//github.com/}
+
+PATCH=$(mktemp)
+trap "rm -f $PATCH" INT TERM EXIT
+wget -nv -O "$PATCH" https://github.com/$PROJECT/pull/$PR.patch
+git am "$@" "$PATCH"