#!/bin/bash

# called from git pre-commit to do basic checks before commit.

set -e

if ! ./ruff-format-check; then
  cat <<\EOF
Error: ruff not happy with formatting, run: ./ruff-format to fix.
skipping the rest of the test util this has been fixed.

git commit --no-verify bypasses all tests.
EOF
  exit 1
fi

if ! ./ruff-check; then
  cat <<\EOF
Error: ruff found problems, if it says it can fix some by itself you may run ./ruff-fix
skipping the rest of the test util this has been fixed.

git commit --no-verify bypasses all tests.

EOF
  exit 1
fi

if ! ./check-rst ; then
  cat <<\EOF
Error: RST syntax errors found in documentation files.
skipping the rest of the test util this has been fixed.

git commit --no-verify bypasses all tests.
EOF
  exit 1
fi

if ! ./mypy ; then
  cat <<\EOF
Error: fix mypy errors before trying to commit again.
skipping the rest of the test util this has been fixed.

git commit --no-verify bypasses all tests.
EOF
  exit 1
fi

if ! ./test ; then
  cat <<\EOF
Error: fix test errors before trying to commit again.
skipping the rest of the test util this has been fixed.

git commit --no-verify bypasses all tests.
EOF
  exit 1
fi
