Skip to content

Instantly share code, notes, and snippets.

@ethernetdan
Created September 8, 2015 16:06
Show Gist options
  • Save ethernetdan/319129e67ae471e6c7af to your computer and use it in GitHub Desktop.
Save ethernetdan/319129e67ae471e6c7af to your computer and use it in GitHub Desktop.
#!/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 "$@"
@ethernetdan
Copy link
Author

TODO: fix to work with HTTPS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment