-
-
Save shireeshj/a37c2245d3b654f8fe2fc621da3893a0 to your computer and use it in GitHub Desktop.
A git subcommand to "tophat" (build/run/test) a PR from a fork
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/zsh | |
function main { | |
if [[ ! "$1" =~ ".*:.*" ]]; then | |
echo "Empty username or branch name: \`$1\` should be of the form \`user:branch\`" | |
exit 1 | |
fi | |
local username="${1%:*}" | |
local branch="${1#*:}" | |
local tophat_url="$(git remote get-url origin | rg -o '(.*[/:])\w+/(\w+).git' -r "\${1}${username}/\${2}")" | |
git remote rm tophat &>/dev/null | |
git remote add -f -t "${branch}" tophat "${tophat_url}" \ | |
&& git checkout "tophat/${branch}" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment