#!/usr/bin/env bash
#
# Clone a remote GIT repository.
# Copyright (c) Petr Baudis, 2005
#
# This is like cg-init, but works only for remote repositories and
# will create a new directory where it will do the checkout.
#
# Takes an parameter specifying location of the source repository.

. cg-Xlib

location=$1
[ "$location" ] || die "usage: cg-clone SOURCE_LOC"
location=${location%/}

dir=${location##*/}; dir=${dir%.git}
[ -e "$dir" ] && die "$dir/ already exists"
mkdir "$dir"
cd "$dir"

cg-init $location || exit $?
echo "Cloned to $dir/ (origin $location available as branch \"origin\")"
