#!/bin/bash

export GIT_WORK_TREE=`dirname "$0"`
export GIT_DIR="$GIT_WORK_TREE/.git"

if [ ! -d "$GIT_WORK_TREE/.git" ]; then
  echo "Sorry could not generate archive with '$0' for [$GIT_WORK_TREE], which is not a git repository!"
  exit 1
fi

ID=`$GIT_WORK_TREE/git-version-gen $GIT_WORK_TREE/.tarball-git-version`
OUTPUT="./singular-$ID.tar"

git archive --format tar -o "$OUTPUT" HEAD || ( ret =$?; echo "Sorry could not generate archive for [$GIT_WORK_TREE] with '$0' -> code: $ret"; exit $ret; )

echo $ID > .tarball-git-version && tar uf "$OUTPUT" .tarball-git-version && rm .tarball-git-version

bzip2 "$OUTPUT"

echo "$OUTPUT.bz2 was generated from git repository at [$GIT_WORK_TREE]"
