Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created September 17, 2014 18:37
Show Gist options
  • Select an option

  • Save ConradIrwin/c8a8f2468f3aa3f1e347 to your computer and use it in GitHub Desktop.

Select an option

Save ConradIrwin/c8a8f2468f3aa3f1e347 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Fetch a pull request from github. Guesses the name of your repo from its `origin`
# remote.
#
# e.g. git fetch-pr 8
#
# (relies on `wip/git-url` and `jq` for now)
set -e
t="$(mktemp -t XXXXX.json)"
function json() {
cat $t | jq -r "$@"
}
echo "Fetching $(git url --api /pulls/$1)"
curl --netrc -sS $(git url --api /pulls/$1) > $t
if [ "$(json .message)" != "null" ]
then
echo "$(json .message)"
else
echo "Fetching $(json .head.repo.owner.login)/$(json .head.ref)"
git fetch "$(json .head.repo.ssh_url)" "$(json .head.ref)"
git branch "$(json .head.repo.owner.login)/$(json .head.ref)" "$(json .head.sha)"
fi
rm $t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment