From 4e553018d2c5264a0f25607c1a254d49d48dfbe5 Mon Sep 17 00:00:00 2001 From: Bot Date: Fri, 29 May 2026 14:15:08 -0400 Subject: [PATCH] fix(hooks): self-update pre-commit hook when .github/hooks/pre-commit is newer --- .github/hooks/pre-commit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit index fe17eb2d..423dfb51 100644 --- a/.github/hooks/pre-commit +++ b/.github/hooks/pre-commit @@ -1,10 +1,26 @@ #!/bin/sh # pre-commit: +# 0. Self-update: reinstall if .github/hooks/pre-commit is newer than the installed copy # 1. Portability checks (non-ASCII, PS backtick escapes) on staged files # 2. Auto-regen llms-full.txt when any of its inputs are staged # # Works on Windows (Git Bash), Linux, and macOS. +# ============================================================================ +# Part 0: self-update +# ============================================================================ +REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) +if [ -n "$REPO_ROOT" ]; then + HOOK_SRC="$REPO_ROOT/.github/hooks/pre-commit" + HOOK_DST="$REPO_ROOT/.git/hooks/pre-commit" + if [ -f "$HOOK_SRC" ] && [ -f "$HOOK_DST" ] && [ "$HOOK_SRC" -nt "$HOOK_DST" ]; then + cp "$HOOK_SRC" "$HOOK_DST" + chmod +x "$HOOK_DST" + echo "pre-commit: hook updated from .github/hooks -- re-running" + exec "$HOOK_DST" "$@" + fi +fi + STAGED=$(git diff --cached --name-only --diff-filter=ACM) [ -z "$STAGED" ] && exit 0