#!/bin/sh

# @file .config/husky/prepare-commit-msg
# @brief A git hook script for the `prepare-commit-msg` hook. Add the `-n` flag to bypass.
# @arg $1 string The full path to the MERGE_MSG
# @arg $2 string The type of the `prepare-commit-msg` event. For a `git pull origin master`
#   command, the event type is 'merge'.

if [ -f "$(dirname "$0")/_/husky.sh" ]; then
  . "$(dirname "$0")/_/husky.sh"
  chmod +x .config/log
  if [ "$2" != 'merge' ]; then
    .config/log info 'This git hook is configured to run even when --no-verify is used. In order to bypass this prompt, use the -n flag instead.'
    .config/log info 'Opening a `git commit` dialog'
    exec < /dev/tty && pnpx git-cz --hook || true
  fi
else
  .config/log warn 'Husky pre-commit hooks are currently not properly setup.'
fi
