#!/bin/bash 
name=$1
version=$2 
pushd $3
if [ -d .git ]; then 
    git tag | grep "$version" > /dev/null 2>&1 
    if [ "x$?" = "x0" ] ; then 
	git archive --format=tar  --prefix=${name}-${version}/ ${version} | xz -9 >$4/${name}-${version}.tar.xz
    else
	git archive --format=tar  --prefix=${name}-${version}/ HEAD | xz -9 >$4/${name}-${version}.tar.xz
	echo "version tag '$version' not found, using HEAD"
    fi
else 
     echo "Error: package creation only works from a git repository, since it uses 'git archive'"
fi 
popd
