#!/bin/bash
__SUMMARY__=$(cat <<"__TLDR__"
git-fetch-pr [remote] <PR#>

Fetch the refs from a GitHub PR into the current repository.
They will be stored under refs/remotes/<remote>-pull (so if
the remote is "upstream" and the PR number is 35 then you'll
have remote branches named "upstream-pull/35/head" and
"upstream-pull/35/merge".

If not specified, the default remote is "upstream".
__TLDR__
)


usage () {
	echo >&2 "$__SUMMARY__"
	exit "$1"
}


if [[ $1 == -h || $1 == --help ]]; then
	usage 0
fi

set -o nounset

case $# in
	1) Remote=upstream; Pr=$1 ;;
	2) Remote=$1; Pr=$2 ;;
	*) usage 2 ;;
esac

Src=refs/pull/${Pr}
Dst=refs/remotes/${Remote}-pull/${Pr}

git fetch "$Remote" "+${Src}/*:${Dst}/*"

# vim:noet:sw=8:sts=8:ts=8
