Created
March 11, 2021 08:22
-
-
Save lrytz/b7575e29fa8055b12570c8fafa244c32 to your computer and use it in GitHub Desktop.
fetchpr
This file contains hidden or 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 | |
set -e | |
[[ $# == 1 ]] || { | |
echo "usage: $0 <pr-number>" | |
exit 1 | |
} | |
pr=$1 | |
upstream=$(git remote -v | grep -E '^upstream\s+' | head -1 | sed 's/upstream.*github.com.\(.*\)\.git.*/\1/') | |
git fetch upstream pull/$pr/head -f | |
git checkout pr$pr 2> /dev/null || git checkout -b pr$pr | |
git reset --hard FETCH_HEAD | |
prInfo=$(curl -s https://api.github.com/repos/$upstream/pulls/$pr) | |
remoteName=$(echo -E $prInfo | jq -r '.head.user.login') | |
git remote -v | grep -E "^$remoteName\s+" > /dev/null || { | |
remoteUrl=$(echo -E $prInfo | jq -r '.head.repo.ssh_url') | |
echo "Adding remote $remoteName - $remoteUrl" | |
git remote add $remoteName $remoteUrl | |
} | |
branch=$(echo -E $prInfo | jq -r '.head.ref') | |
git fetch -f $remoteName $branch | |
echo "Push changes with:" | |
echo git push -f $remoteName HEAD:$branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment