#!/bin/sh # Install the versioned git hooks for this repository by pointing core.hooksPath # at the githooks directory. This is a one-time, per-checkout setup: # # ./scripts/install-git-hooks.sh # # After this, every `git commit` runs the test suite first and aborts if it # fails, then refreshes the generated devlog (client/js/devlog_data.js) and # stages it. Skip once with `git commit --no-verify`. # # Uninstall with: # git config --unset core.hooksPath set -e PROJECT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) HOOKS_DIR="$PROJECT_DIR/githooks" if [ ! -d "$HOOKS_DIR" ]; then echo "error: hooks directory not found at $HOOKS_DIR" >&2 exit 1 fi REPO_ROOT=$(git -C "$PROJECT_DIR" rev-parse --show-toplevel 2>/dev/null) || { echo "error: $PROJECT_DIR is not inside a git repository." >&2 echo " Run 'git init' first, then re-run this script." >&2 exit 1 } # Git only runs hooks that are executable. chmod +x "$HOOKS_DIR"/* # core.hooksPath is local (not committed), so each clone runs this once. git -C "$REPO_ROOT" config core.hooksPath "$HOOKS_DIR" echo "Installed git hooks from $HOOKS_DIR" echo " repository: $REPO_ROOT" echo " core.hooksPath $HOOKS_DIR" if ! command -v node >/dev/null 2>&1 && command -v nix-shell >/dev/null 2>&1; then echo " note: 'node' is not on PATH; the hook will fall back to 'nix-shell -p nodejs'." fi echo "" echo "Every commit now runs the test suite and refreshes the devlog." echo "Skip once with: git commit --no-verify"