Last active
January 11, 2020 22:53
-
-
Save yanatan16/6071081 to your computer and use it in GitHub Desktop.
pullreq - A bash function to make a pull request.
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
# Push your current branch to origin and open a pull request to upstream:$1 or upstream:master | |
pullreq() | |
{ | |
local browser=google-chrome # replace with your browser command | |
local regex='(https?://|git://|git@)([a-zA-Z0-9\.]+)[:/]([a-zA-Z0-9]+)/(.+)?' | |
local origin=$(git remote -v | grep origin | grep push | cut -f2 | cut -d' ' -f1) | |
local upstream=$(git remote -v | grep upstream | grep fetch | cut -f2 | cut -d' ' -f1) | |
local params=$(python -c "import sys;import re;print ':'.join(re.match('${regex}',sys.argv[1]).groups()[1:])" $origin) | |
local site=$(echo $params | cut -d':' -f1) | |
local user=$(echo $params | cut -d':' -f2) | |
local repo=$(echo $params | cut -d':' -f3 | sed 's/\.git//') | |
local branch=$(git branch | grep \* | cut -d' ' -f2) | |
if [ ${upstream} = "" ]; then | |
local uuser=user | |
else | |
local uparams=$(python -c "import sys;import re;print ':'.join(re.match('${regex}',sys.argv[1]).groups()[1:])" $upstream) | |
local uuser=$(echo $uparams | cut -d':' -f2) | |
fi | |
if [ ${#@} -eq 1 ]; then | |
local tobranch=${1}; | |
else | |
local tobranch="master"; | |
fi | |
git push origin ${branch} | |
${browser} http://${site}/${user}/${repo}/pull/new/${uuser}:${tobranch}...${branch} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: