Skip to content

Commit b4cbcbf

Browse files
Joseph Edmondsclaude
andcommitted
feat(git-hooks): Add signature for smart hook redeployment
Add signature comment to git hook and update deployment logic to: - Detect if existing pre-commit hook is php-qa-ci managed (via signature) - If managed: overwrite with updated version (automatic updates) - If custom: skip deployment (preserve user customizations) SIGNATURE FORMAT: # PHP-QA-CI-HOOK-SIGNATURE: pre-commit-check-vendor-uncommitted # DO NOT EDIT: This hook is managed by php-qa-ci DEPLOYMENT LOGIC: 1. Check if .git/hooks/pre-commit exists 2. If exists, grep for signature 3. If signature found → overwrite (it's our hook, update it) 4. If signature not found → skip (it's custom, preserve it) 5. If doesn't exist → install fresh This allows automatic hook updates via composer update while respecting custom user hooks. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 486a29f commit b4cbcbf

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

git-hooks/pre-commit-check-vendor-uncommitted

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
2+
# PHP-QA-CI-HOOK-SIGNATURE: pre-commit-check-vendor-uncommitted
3+
# DO NOT EDIT: This hook is managed by php-qa-ci and will be automatically updated
24
#
35
# Git Pre-Commit Hook: Check Vendor Libraries for Uncommitted Changes
46
#

scripts/deploy-skills.bash

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fi
268268
# ============================================================================
269269
# Phase 3: Git Hooks Deployment
270270
# ============================================================================
271-
# Deploy git hooks (if not already present)
271+
# Deploy git hooks (if not already present, or update if it's our hook)
272272
GIT_HOOKS_SOURCE="$QACI_PATH/git-hooks"
273273
GIT_HOOKS_TARGET="$PROJECT_ROOT/.git/hooks"
274274

@@ -282,9 +282,17 @@ if [[ -d "$GIT_HOOKS_SOURCE" ]] && [[ -d "$GIT_HOOKS_TARGET" ]]; then
282282

283283
if [[ -f "$PRE_COMMIT_SOURCE" ]]; then
284284
if [[ -f "$PRE_COMMIT_TARGET" ]]; then
285-
echo " ⚠️ Git pre-commit hook already exists - skipping deployment"
286-
echo " Existing: $PRE_COMMIT_TARGET"
287-
echo " To use php-qa-ci hook, backup existing and re-run deployment"
285+
# Check if existing hook is our hook (by signature)
286+
if grep -q "PHP-QA-CI-HOOK-SIGNATURE: pre-commit-check-vendor-uncommitted" "$PRE_COMMIT_TARGET" 2>/dev/null; then
287+
echo " Updating git pre-commit hook (php-qa-ci managed)..."
288+
cp "$PRE_COMMIT_SOURCE" "$PRE_COMMIT_TARGET"
289+
chmod +x "$PRE_COMMIT_TARGET"
290+
echo " ✓ Git pre-commit hook updated: $PRE_COMMIT_TARGET"
291+
else
292+
echo " ⚠️ Git pre-commit hook already exists (custom) - skipping deployment"
293+
echo " Existing: $PRE_COMMIT_TARGET"
294+
echo " To use php-qa-ci hook, backup existing and re-run deployment"
295+
fi
288296
else
289297
echo " Installing git pre-commit hook..."
290298
cp "$PRE_COMMIT_SOURCE" "$PRE_COMMIT_TARGET"

0 commit comments

Comments
 (0)