#!/bin/sh
NAME=$1

if [ "x$NAME" == "x" ]; then
	# Try to autodetect
	if [ -f .git/remotes/origin ]; then
		NAME=`grep 'URL: git.alt:packages/' .git/remotes/origin | sed 's!.*/!!'`
		echo "Using name: '$NAME'"
	fi
fi

if [ "x$NAME" == "x" ]; then
	echo "Using: $0 packagename"
	exit -1
fi

rm -f .git/remotes/origin 2> /dev/null
rmdir .git/remotes 2> /dev/null

T=`git-config --get remote.origin.url`

if [ "x$T" == "x" ]; then
	git config 'remote.origin.url' "git.alt:packages/$NAME"
	git config 'remote.origin.push' "refs/heads/*:refs/heads/*"
	git config 'remote.origin.fetch' "refs/heads/*:refs/remotes/origin/heads/*"
else
	echo "Already exists!"
	exit -1
fi

