#!/bin/sh

# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
load_mod git

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
	echo "ginit - initialize repo in $GIRARHOST for current project"
	echo "Use: ginit [GIRAR]"
	echo "     ginit git.eter - for init in git.eter gear repo"
	exit 1
fi

if is_girar_name $1 ; then
	GIRARHOST=$1
	shift
fi

test -r "$1" && fatal "Do not need any files in params"

PROJECTNAME=$(get_gear_name)

# FIXME: если не нашли, стоит взять название каталога за основу
[ -n "$PROJECTNAME" ] || fatal "Can't detect project name. Run inside git repo."

echo "Create remote $PROJECTNAME repo in $GIRARHOST:"
ssh $GIRARHOST git-init-db "$PROJECTNAME.git"
echo "Create $GIRARHOST remote repo alias"
git remote add $GIRARHOST $GIRARHOST:packages/$PROJECTNAME.git
