#!/bin/bash -e
# checkin script for Git that serves to cause
# platforms/Cross/vm/sqSCCSVersion.h to be checked-in so that its version
# info reflects that of the current check-in.

if [ -d `dirname $0`/../.git ]; then
	hooks_dir="`git rev-parse --git-dir`/hooks"
    mkdir -p $hooks_dir
    cp -f $0 $hooks_dir/post-commit
    cp -f $0 $hooks_dir/post-merge
    cp -f $0 $hooks_dir/post-checkout
    cd `dirname $0`/..
else
    cd `dirname $0`/../..
    if [[ "$(basename $0)" == "post-checkout" ]]; then
        prevHEAD=$1
        newHEAD=$2
        branchChange=$3
        if [[ "$branchChange" == "0" ]] && [[ "$prevHEAD" == "$newHEAD" ]]; then
            # we did not switch branches and did not move to a new head (e.g. we
            # just did a checkout on a file
            exit 0
        fi
    fi
fi

git config --local include.path ../.gitconfig
git stash -q || true
echo "//" >> platforms/Cross/vm/sqSCCSVersion.h
echo "//" >> platforms/Cross/plugins/sqPluginsSCCSVersion.h
git checkout HEAD -- platforms/Cross/vm/sqSCCSVersion.h
git checkout HEAD -- platforms/Cross/plugins/sqPluginsSCCSVersion.h
git stash pop -q || true
