Last active
December 10, 2020 23:17
-
-
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
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/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