#!/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" if [ "$(git config --bool --get merge-pr.autoclose)" = false ]; then exit 0 fi # Rewrite last commit message to close GitHub issue. EDITOR='sh -c '\''git -c trailer.closes.ifExists=replace interpret-trailers \ --trailer "Closes: #'"$PR"' [via git-merge-pr]" "$1" > "$1-" && mv "$1-" "$1"'\'' -' \ git commit --quiet --amend