Skip to content

Instantly share code, notes, and snippets.

@anentropic
Last active November 3, 2016 16:46
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anentropic/9397b75e24ef9f8f17d2 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: git getpull <SHA>"
exit 1
elif [ -z "$(git rev-parse --git-dir 2>/dev/null)" ]; then
echo "Not in a git directory"
exit 1
else
repo_details=( \
$(git config --get remote.origin.url 2>/dev/null \
| perl -lne 'print "$1 $2" if m%(?:[a-z0-9-.]+@|https?://)([a-z0-9-.]+)(?:[:/])(.*?).git%') \
)
git_host=${repo_details[0]}
repository_path=${repo_details[1]}
pull_id=$(\
git log $1..master --ancestry-path --merges --oneline 2>/dev/null \
| tail -n 1 | perl -nle 'print $1 if /#(\d+)/' \
)
if [ -n "$pull_id" ]; then
if [ "$git_host" = "bitbucket.org" ]; then
echo https://bitbucket.org/$repository_path/pull-requests/$pull_id
elif [ "$git_host" = "github.com" ]; then
echo https://github.com/$repository_path/pull/$pull_id
else
echo $pull_id
fi
else
echo "Sorry, couldn't find that pull"
exit 1
fi
fi
@anentropic
Copy link
Author

To use:

  1. copy this script to /usr/local/bin/git-getpull
  2. $ git getpull fc0358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment