mirror of
https://github.com/apify/agent-skills.git
synced 2026-09-14 20:00:06 +08:00
fix: replace git hook with Claude Code PreToolUse hook
Git hooks can't stage files during commit (index lock). Using Claude Code PreToolUse hook instead - runs before the bash command executes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Git commit-msg hook for automatic version bumping
|
||||
# This hook runs the version bump script before the commit is finalized
|
||||
#
|
||||
# To install this hook, run:
|
||||
# git config core.hooksPath .githooks
|
||||
# Or copy it manually:
|
||||
# cp .githooks/commit-msg .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg
|
||||
|
||||
COMMIT_MSG_FILE="$1"
|
||||
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
|
||||
|
||||
# Skip if this is a merge commit or amend
|
||||
if [ -f .git/MERGE_HEAD ] || [ "$GIT_AUTHOR_DATE" != "$GIT_COMMITTER_DATE" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Skip if commit message starts with "Merge" or is empty
|
||||
if [[ "$COMMIT_MSG" =~ ^Merge ]] || [ -z "$COMMIT_MSG" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run version bump script
|
||||
echo "Running version bump script..."
|
||||
uv run scripts/generate_agents.py --bump "$COMMIT_MSG"
|
||||
|
||||
# Stage any version files that were modified
|
||||
git add -u .claude-plugin/marketplace.json .claude-plugin/plugin.json 2>/dev/null
|
||||
git add -u skills/*/reference/scripts/run_actor.py 2>/dev/null
|
||||
|
||||
exit 0
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# Claude Code PreToolUse hook - runs version bump before git commit
|
||||
# This script receives tool input JSON on stdin
|
||||
|
||||
# Read tool input
|
||||
INPUT=$(cat)
|
||||
|
||||
# Extract the bash command
|
||||
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // ""')
|
||||
|
||||
# Quick exit if not a git commit command
|
||||
if ! echo "$COMMAND" | grep -qE 'git\s+commit'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract commit message from -m "message" or -m 'message'
|
||||
COMMIT_MSG=$(echo "$COMMAND" | grep -oE '\-m\s+["'"'"'][^"'"'"']+["'"'"']' | sed -E 's/-m\s+["'"'"'](.*)["'"'"']/\1/' | head -1)
|
||||
|
||||
# If no message found, skip bump (might be interactive commit)
|
||||
if [ -z "$COMMIT_MSG" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run version bump
|
||||
cd "$CLAUDE_PROJECT_DIR" 2>/dev/null || cd "$(dirname "$0")/../.."
|
||||
uv run scripts/generate_agents.py --bump "$COMMIT_MSG"
|
||||
|
||||
# Stage any modified version files
|
||||
git add -u .claude-plugin/marketplace.json .claude-plugin/plugin.json 2>/dev/null
|
||||
git add -u skills/*/reference/scripts/run_actor.py 2>/dev/null
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user