Last active
November 3, 2016 16:46
-
-
Save anentropic/9397b75e24ef9f8f17d2 to your computer and use it in GitHub Desktop.
based on: http://genius.com/Andrew-warner-git-getpull-quickly-find-the-pull-request-that-merged-your-commit-to-master-annotated ...updated to parse both GitHub and BitBucket repo urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use:
/usr/local/bin/git-getpull
$ git getpull fc0358