Skip to content

Instantly share code, notes, and snippets.

@tomjenkinson
Last active November 15, 2016 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomjenkinson/3699667 to your computer and use it in GitHub Desktop.
Save tomjenkinson/3699667 to your computer and use it in GitHub Desktop.
Simple script to create a pull request
#!/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
xdg-open 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
xdg-open 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
xdg-open 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
xdg-open 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
#xdg-open https://github.com/$upstreamname/$reponame/pull/new/$upstreamname:$1...$myname:$branchname
xdg-open https://github.com/$upstreamname/$reponame/compare/$upstreamname:$1...$myname:$branchname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment