#!/bin/sh

# Fail on error and unset variables
set -eu

# Determine project root as the parent directory of this hook script
PROJECT_ROOT="$(CDPATH= cd -- "$(dirname -- "$0")"/.. && pwd)"

# Run the Ruby hook within the direnv context (if available),
# so ENV from .envrc/.env.local at project root is loaded.
# One of the things .envrc needs to do is add $PROJECT_ROOT/bin/ to the path.
# You should have this line at the top of .envrc
#   PATH_add bin
# NOTE: this project needs to also add exe as well,
#       but other libraries won't generally need to do that.
if command -v direnv >/dev/null 2>&1; then
  exec direnv exec "$PROJECT_ROOT" "kettle-commit-msg" "$@"
else
  raise "direnv not found. Local development of this project ($PROJECT_ROOT) with tools from the kettle-dev gem may not work properly. Please run 'brew install direnv'."
fi
