#! /bin/sh
# Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
# Contact: http://www.qt-project.org/legal
#
# You may use this file under the terms of the 3-clause BSD license.
# See the file LICENSE from this package for details.
#

# Usage: in every repository you want to have checked:
#    cd .git/hooks
#    ln -s /path/to/git_post_commit_hook post-commit
#

makeAbsolute() {
    case $1 in
        /*)
            # already absolute, return it
            echo "$1"
            ;;
        *)
            # relative, prepend $2 made absolute
            echo `makeAbsolute "$2" "$PWD"`/"$1" | sed 's,/\.$,,'
            ;;
    esac
}

me=$0
if test -L "$me"; then
    # Try GNU readlink(1)
    nme=`readlink -nf "$me" 2>/dev/null`
    if test -n "$nme"; then
        me=$nme
    else
        # No GNU readlink(1), so let's try ls -l
        me=`ls -l "$me" | sed 's/^.*-> //'`
        base=`dirname "$me"`
        me=`makeAbsolute "$me" "$base"`
    fi
fi

sha1=${1-HEAD} # just for debugging
GIT_PUSH=${GIT_PUSH+$GIT_PUSH,}wip # this check makes totally no sense locally
export GIT_PUSH
exec `dirname "$me"`/sanitize-commit $sha1 strict >&2