#!/bin/sh

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

#test -n "$SPECNAME" || SPECNAME=$(basename `pwd`).spec

if [ "$1" = "-h" ] ; then
	echo "gpush - publish current project repo to $GIRARHOST"
	echo "Use: gpush [project name] [target branch]"
	exit 1
fi

PUSHFORCE=
if [ "$1" = "-f" ] || [ "$1" = "--force" ] ; then
	PUSHFORCE="--force"
fi

# use as project name
if [ -n "$1" ] ; then
	PROJECTNAME=$1
	shift
else
	PROJECTNAME=$(basename `pwd`)
fi

CURRENTBRANCH=$(git branch | grep "^\*" | cut -d " " -f 2)

if [ -z "$CURRENTBRANCH" ] ; then
	echo "Can't detect current branch"
	exit 1
fi

# more correctly
CURRENTBRANCH=HEAD
# 
if [ -n "$1" ] ; then
	TARGETBRANCH=$CURRENTBRANCH:$1
	shift
else
	TARGETBRANCH=
fi

git push $@ $PUSHFORCE $GIRARHOST:packages/$PROJECTNAME.git $TARGETBRANCH
git push --tags $GIRARHOST:packages/$PROJECTNAME.git $TARGETBRANCH

#> $ git commit -a; A='0.23-alt1'; git tag -s $A; \
#>   git tag -s -f -m 'Sisyphus release $A' sisyphus $A