#!/bin/bash
# make sure the tag for the generated files is correct 
# by checking that all changes have been commited to GIT
# (this does not include newly created files)
if ( ! git diff-index --quiet --cached HEAD -- ) || ( ! git diff-files --quiet )
  then
    echo "Uncommitted changes in the GIT repository:"
    git status --untracked-files=no

    read -p "Add changes and commit, amend last commit or exit [c/a/e]: " res
    case $res in
        [Cc]* ) git commit -a;;
        [Aa]* ) git commit -a --amend;;
        * ) exit;;
    esac
fi

sbatch sbatch.tsh "`/usr/bin/git describe --tags --long`"

# waiting for batch job to start and send all output directly to terminal
sleep 2
tail -qf tmp/stdout.log tmp/stderr.log
