#!/bin/sh

echo "Script $0 triggered ..."

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "Starting prospector analysis using configuration from .prospector.yml..."

# quietly run prospector
prospector 1>/dev/null

# use return code to abort commit if necessary
if [ $? != "0" ]; then
    echo "Commit aborted. Run 'prospector' to see the errors."
    exit 1
fi

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo "Starting isort analysis using configuration from setup.cfg..."

# recursively run isort on howfairis/ directory, don't try to automatically fix anything
isort --check-only howfairis

if [ $? != "0" ]; then
    echo "Commit aborted."
    echo "  Run 'isort --check-only --diff howfairis' to see what's wrong."
    echo "  Run 'isort howfairis' to let isort fix problems automatically."
    exit 1
fi

echo "Pre-commit checks completed successfully."
exit 0
