#!/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 lilio/ directory, don't try to automatically fix anything
isort --recursive --check-only lilio

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

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