Skip to content

Instantly share code, notes, and snippets.

@Duncaen
Last active February 2, 2019 10:32
Show Gist options
  • Save Duncaen/08ccb0d406c3aa78574eac3ff1b0b82a to your computer and use it in GitHub Desktop.
Save Duncaen/08ccb0d406c3aa78574eac3ff1b0b82a to your computer and use it in GitHub Desktop.
#!/bin/dash
# git-get repo [git clone args...] -- clone repositories like go get
err() { printf "%s: %s\n" "$0" "${@}"; exit 1; }
url=$1; shift
[ -z "$GIT_PATH" ] && err '$GIT_PATH must be set'
[ ! -d "$GIT_PATH" ] &&
err '$GIT_PATH does not exist or is not a directory'
case "$url" in
*@*:*) repo=${url#*:} ;;
http*://*) repo=${url#http*://*/} ;;
# default to github?
#*/*) repo=$url; set -- "git@github.com:$url" ;;
*) err "'$url' doesn't look like a repository" ;;
esac
repo=${repo%*.git}
path="$GIT_PATH/$repo"
[ -e "$path" ] && err 'repository already exists'
mkdir -p "${path%/*}" || exit
git clone "$@" "$url" "$path" || exit
printf '%s\n' "$path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment