#!/bin/bash
set -euo pipefail

this_dir=$(cd "$(dirname "$0")"; pwd -P)
root_dir=$(dirname "$this_dir")

docs_only=true
while IFS= read -r file; do
  case "$file" in
    *.md|LICENSE|.gitignore)
      ;;
    *)
      docs_only=false
      break
      ;;
  esac
done < <(git diff --cached --name-only --diff-filter=ACMR)

if [ "$docs_only" = true ]; then
  exit 0
fi

if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
  "$root_dir/.venv/Scripts/bygge.exe" check
else
  exec "$root_dir/.venv/bin/bygge" check
fi
