Skip to content

Instantly share code, notes, and snippets.

@thegedge
Last active April 8, 2021 07:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thegedge/76c9922a07a654d267335c80944da205 to your computer and use it in GitHub Desktop.
Save thegedge/76c9922a07a654d267335c80944da205 to your computer and use it in GitHub Desktop.
A git subcommand to "tophat" (build/run/test) a PR from a fork
#!/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