Skip to content

Instantly share code, notes, and snippets.

@DanielShterenberg
Last active December 10, 2020 23:17
Show Gist options
  • Save DanielShterenberg/aebbd5d30ac5b74d5fc2ad0c239a2fac to your computer and use it in GitHub Desktop.
Save DanielShterenberg/aebbd5d30ac5b74d5fc2ad0c239a2fac to your computer and use it in GitHub Desktop.
pre-push hook that prints in the terminal the url to the remote branch
#!/bin/sh
remote=$1
url=$2
###extract host:
host=${url#*@} # chop off the beginning until the first '@'
host=${host%%:*} # chop off everything after the first ':'
###extract org:
org=${url#*:} # chop off the beginning until the first ':'
org=${org%%/*} # chop off everything after the first '/'
###extract project
project=${url#*/} # chop off the beginning until the first '/'
project=${project%%.*} # chop off the beginning until the first '.'
while read local_ref local_sha remote_ref remote_sha; do
if [ $host='github.com' ]; then
remote_branch=${remote_ref#*/*/} # get the part after the second '/'
echo "https://github.com/${org}/${project}/pull/new/${remote_branch}\n"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment