Created
September 8, 2015 16:06
-
-
Save ethernetdan/319129e67ae471e6c7af to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
ROOT_DIR=~/repos | |
function main() { | |
export REMOTE=$1 | |
info "Checking the validity of remote $REMOTE" | |
checkRepo $REMOTE | |
repo=$(parseRepo) | |
git clone $REMOTE $ROOT_DIR/$repo | |
} | |
function checkRepo() { | |
git ls-remote "$REMOTE" &>- | |
if [ "$?" -ne 0 ]; then | |
error "[ERROR] Unable to read from '$REMOTE'" | |
fi | |
} | |
function parseRepo() { | |
python - <<END | |
import os | |
from giturlparse import parse | |
p = parse( os.environ['REMOTE'] ) | |
print "%s/%s/%s" % (p.host, p.owner, p.repo) | |
END | |
} | |
function info() { | |
printf "\e[1m$1\e[0m\n" | |
} | |
function error() { | |
>&2 printf "\e[31m\e[1m$1\e[0m\n"; exit 1; | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: fix to work with HTTPS