-
-
Save paulrobinson/6915611 to your computer and use it in GitHub Desktop.
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/bash | |
git remote | grep origin > /dev/null 2>&1 | |
if [ "$?" -ne 0 ]; then | |
echo This script assumes you have origin set as the repo to create reqs in | |
exit | |
fi | |
upstreamname=`git remote -v | grep upstream | grep fetch | sed "s#upstream.*github.com[:/]\(.*\)/.*#\1#"` | |
reponame=`git remote -v | grep origin | grep push | sed "s#.*/\(.*\)\.git.*#\1#g"` | |
myname=`git remote -v | grep origin | grep fetch | sed "s#origin.*github.com[:/]\(.*\)/.*#\1#"` | |
branchname=`git branch | grep "*" | sed "s/* //"` | |
if [ $# -eq 0 ] | |
then | |
ancestor417=`git merge-base $branchname 4.17` | |
if [ "$?" -ne 0 ] | |
then | |
#echo "no other option - I recommend master" | |
git push origin `git branch | grep "*" | sed "s/* //"` | |
if [ "$?" -eq 0 ] | |
then | |
echo https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:master...$myname:$branchname | |
fi | |
exit | |
fi | |
ancestorMaster=`git merge-base $branchname master` | |
if [ "$?" -ne 0 ] | |
then | |
#echo "no other option - I recommend 4.17" | |
git push origin `git branch | grep "*" | sed "s/* //"` | |
if [ "$?" -eq 0 ] | |
then | |
echo https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:4.17...$myname:$branchname | |
fi | |
exit | |
fi | |
myRev=`git rev-parse HEAD` | |
distanceFromMaster=`git log $ancestorMaster..$myRev | grep commit | wc | cut -c 1-7 | tr -d ' '` | |
distanceFrom417=`git log $ancestor417..$myRev | grep commit | wc | cut -c 1-7 | tr -d ' '` | |
if [ "$distanceFromMaster" -lt "$distanceFrom417" ] | |
then | |
#echo "I recommend master" | |
git push origin `git branch | grep "*" | sed "s/* //"` | |
if [ "$?" -eq 0 ] | |
then | |
echo https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:master...$myname:$branchname | |
fi | |
else | |
#echo "I recommend 4.17" | |
git push origin `git branch | grep "*" | sed "s/* //"` | |
if [ "$?" -eq 0 ] | |
then | |
echo https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:4.17...$myname:$branchname | |
fi | |
fi | |
exit | |
fi | |
git push origin `git branch | grep "*" | sed "s/* //"` | |
echo https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:$1...$myname:$branchname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment