#!/usr/bin/env bash

## Description: Install the repository git hooks (sets core.hooksPath to .githooks)
## Usage: install-git-hooks
## Example: "ddev install-git-hooks"

# Provided by this project, not by ddev-drupal-contrib. Deliberately has no
# "#ddev-generated" marker, so that ddev treats it as project-owned and never
# replaces it when the add-on is updated.
#
# This is a host command because it configures the git checkout on the host.

set -eu -o pipefail

cd "${DDEV_APPROOT}" || exit 1

if [ ! -d .githooks ]; then
  echo "No .githooks directory found in ${DDEV_APPROOT}." >&2
  exit 1
fi

chmod +x .githooks/*
git config core.hooksPath .githooks

echo "Git hooks installed: core.hooksPath -> .githooks"
echo
echo "  pre-commit  phpcs, on the staged files only"
echo "  pre-push    composer lint, phpcs, phpstan, phpunit"
echo
echo "Bypass once with --no-verify, or set SKIP_HOOKS=1 to disable both hooks."
echo "Remove with: git config --unset core.hooksPath"
