#!/bin/sh
# Pre-commit hook to run lint and tests

echo "Running pre-commit checks..."

# Run ruff lint (use .venv/bin/ruff if available, otherwise assume globally installed)
if [ -f ".venv/bin/ruff" ]; then
    RUFF=".venv/bin/ruff"
else
    RUFF="ruff"
fi

echo "Running ruff..."
$RUFF check glassdash/ --no-fix
if [ $? -ne 0 ]; then
    echo "Ruff check failed. Fix errors before committing."
    exit 1
fi

# Run tests (use .venv/bin/python if available)
if [ -f ".venv/bin/python" ]; then
    PYTHON=".venv/bin/python"
else
    PYTHON="python"
fi

echo "Running pytest..."
$PYTHON -m pytest tests/ -q
if [ $? -ne 0 ]; then
    echo "Tests failed. Fix test failures before committing."
    exit 1
fi

echo "Pre-commit checks passed!"
exit 0
