#!/bin/sh -ef

[ -n "$COMFORT_DIR" ] || COMFORT_DIR=/usr/share/comfort
. "$COMFORT_DIR/functions"

# ======================================================================

USAGE='[package-name]'
DESCRIPTION="
Uploads package to git.alt in user's home directory. Creates remote
repository if needed. If package name is not specified, use one in
current work directory."

# Parse command line
. "$COMFORT_DIR/getopt"
[ "$#" -le 1 ] || show_usage 'Too many arguments'
determine_package $1

# ======================================================================

ensure_ssh_key

pushd $GIT_HOME_DIR/$PACKAGE >/dev/null

# Create a remote repository if it's not there
ssh git.alt ls packages/$PACKAGE.git >/dev/null 2>/dev/null || {
	Verbose "No remote repository; creating $PACKAGE"
	ssh git.alt git-init-db $PACKAGE
}

# Do a git push 
git prune
git-repack -a -d
git-push --all ssh://git.alt/people/$ALT_USER/packages/$PACKAGE.git

popd >/dev/null
