#!/bin/sh
#
# Amend and tag releasing commit to take into account added autogenerated
# or updated files in the pre commit hooks.

git log -1 HEAD | grep -qi "releasing package"
found=$?

set -e

# we are on a release commit, add missing files and tag
if [ $found -eq 0 ]; then
    rootdir="$(dirname $(readlink -f $0))/../.."
    releasingfile="$rootdir/.git/releasing"

    # if we are already releasing (and so, amending the commit), don't redo anything (avoid loop)
    if [ -f $releasingfile ]; then
        rm $releasingfile
        exit 0
    fi
    touch $releasingfile

    git commit --amend -C HEAD --no-verify
    git tag -f $(cat ${rootdir}/umake/version)
fi
