#!/bin/sh
set -eu

repository_root=$(git rev-parse --show-toplevel)
cd "$repository_root"

if ! command -v npm >/dev/null 2>&1; then
    echo "commitlint requires Node.js and npm from the version in .node-version." >&2
    echo "Install that runtime, then run 'make install'." >&2
    exit 1
fi

if [ ! -d node_modules/@commitlint ]; then
    echo "commitlint dependencies are missing; run 'make install'." >&2
    exit 1
fi

exec npm run --silent commitlint:edit -- "$1"
