Skip to content

Instantly share code, notes, and snippets.

@diggit
Created October 15, 2016 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diggit/4c6c6fb847180b8ebf6bab92884046d8 to your computer and use it in GitHub Desktop.
Save diggit/4c6c6fb847180b8ebf6bab92884046d8 to your computer and use it in GitHub Desktop.
Custom function to easily clone and pull upstream pullrequests
function echoR
echo -e "\x1b[31;1m""$argv""\x1b[0m"
end
function echoG
echo -e "\x1b[32;1m""$argv""\x1b[0m"
end
function echoY
echo -e "\x1b[33;1m""$argv""\x1b[0m"
end
function echoB
echo -e "\x1b[34;1m""$argv""\x1b[0m"
end
function gfupr
echoR "Git Fetch Upstream Pull Request"
if test (count $argv) -gt 1
set -x branch $argv[2]
else
set -x branch $argv[1]
end
git fetch upstream refs/pull/$argv[1]/head:$branch
if test $status -eq 0
echoG "fetch successful, running checkout"
git checkout $branch
fish -c 'echoY "you are in branch $branch, after closing shell, you will be switched to master"; fish'
git checkout master
echoY "you are back in branch master"
end
end
function gpupr
echoR "Git Pull Upstream Pull Request"
set PR (git describe --contains --all HEAD)
git pull upstream "refs/pull/$PR/head";
if test $status -ne 0
echoR "failed!"
else
echoG "done!"
fish -c 'echoY "you are in branch $branch, after closing shell, you will be switched to master"; fish'
git checkout master
echoY "you are back in branch master"
end
end
function gupr
echoR "Git Upstream Pull Request handler"
set BRANCH (git describe --contains --all HEAD)
if test (count $argv) -eq 1
#1 arg
if test $argv[1] -eq $BRANCH
echoY "We are on requested branch"
gpupr
else
echoY "Switching branch..."
git checkout $argv[1]
if test $status -eq 0
gpupr
else
echoR "branch des not exist, fetching..."
gfupr $argv[1]
end
end
else
if test (count $argv) -eq 0
echoY "assuming, we are on PR branch"
gpupr
else
echoR "Wrong parameter count!"
exit 1
end
end
end
@ashtonchase
Copy link

Thanks for this man. I'll git it a try soon! We need more tools like this to burn those pull-requests down faster.

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