Loading...
Loading...
This skill should be used when the user asks to "create git hooks", "set up pre-commit hooks", "configure git hooks", "add commit validation", "implement pre-push hooks", or needs guidance on Git hooks implementation, validation scripts, or hook best practices.
npx skill4agent add the-perfect-developer/the-perfect-opencode git-hooks.git/hooks/core.hooksPathpre-commitprepare-commit-msgcommit-msgpost-commitpre-pushpost-checkoutpre-rebasepre-receiveupdatepost-receiveDeveloper action → Git event → Hook script runs → Exit code determines outcomechmod +x .git/hooks/pre-commit.git/hooks/core.hooksPathmkdir .githooksgit config core.hooksPath .githooksgit add .githooks/
git commit -m "Add version-controlled git hooks"git config core.hooksPath .githooks.githooks/touch .githooks/pre-commit
chmod +x .githooks/pre-commit#!/bin/bash
set -e
echo "🔍 Validating bash scripts..."
# Get staged .sh files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.sh$' || true)
if [ -z "$STAGED_FILES" ]; then
echo "✅ No bash scripts to validate"
exit 0
fi
# Validate syntax
for file in $STAGED_FILES; do
if [ -f "$file" ]; then
echo "Checking $file..."
bash -n "$file" || exit 1
fi
done
echo "✅ All bash scripts valid"
exit 0set -egit diff --cachedmkdir .githooks/hooks.d#!/bin/bash
set -e
HOOKS_DIR="$(dirname "$0")/hooks.d"
if [ -d "$HOOKS_DIR" ]; then
for hook in "$HOOKS_DIR"/*; do
if [ -x "$hook" ]; then
echo "Running: $(basename "$hook")"
"$hook" || exit 1
fi
done
fi
exit 0# .githooks/hooks.d/10-validate-bash.sh
# .githooks/hooks.d/20-validate-yaml.sh
# .githooks/hooks.d/30-run-tests.sh15-validate-json.sh.githooks/hooks.d/#!/bin/bash
COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
# Pattern: type(scope): description
PATTERN="^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{10,}$"
if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
echo "❌ Invalid commit message format"
echo ""
echo "Expected format: type(scope): description"
echo "Types: feat, fix, docs, style, refactor, test, chore"
echo "Example: feat(auth): add OAuth2 login support"
exit 1
fi
echo "✅ Commit message valid"
exit 0#!/bin/bash
set -e
echo "🧪 Running tests before push..."
# Run test suite
npm test || {
echo "❌ Tests failed. Push aborted."
exit 1
}
echo "✅ All tests passed"
exit 0#!/bin/bash
PROTECTED_BRANCHES="^(main|master|production)$"
while read local_ref local_sha remote_ref remote_sha; do
remote_branch=$(echo "$remote_ref" | sed 's/refs\/heads\///')
if echo "$remote_branch" | grep -qE "$PROTECTED_BRANCHES"; then
# Check if it's a force push
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
echo "❌ Deleting $remote_branch is not allowed"
exit 1
fi
# Check for force push
if ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then
echo "❌ Force push to $remote_branch is not allowed"
exit 1
fi
fi
done
exit 0.githooks/
├── pre-commit # Orchestrator script
├── hooks.d/ # Individual validation scripts
│ ├── the-perfect-developer-base-collection-10-validate-bash.sh
│ └── the-perfect-developer-base-collection-20-validate-skills.sh
└── README.md # Documentation./setup-hooks.shgit config core.hooksPath .githooksthe-perfect-developer-base-collection-<number>-<description>.sh15-validate-json.sh# Test single hook
.githooks/hooks.d/10-validate-bash.sh
# Test orchestrator
.githooks/pre-commit
# Temporarily disable a hook
chmod -x .githooks/hooks.d/20-validate-skills.sh
# Or rename with .disabled extension
mv .githooks/hooks.d/20-validate-skills.sh{,.disabled}#!/bin/bash
set -e
echo "🔍 Running [VALIDATION NAME]..."
# Get staged files matching pattern
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep 'pattern' || true)
if [ -z "$STAGED_FILES" ]; then
echo "✅ No files to validate"
exit 0
fi
# Validation logic
for file in $STAGED_FILES; do
if [ -f "$file" ]; then
echo "Validating $file..."
# Add validation command here
# validation-command "$file" || exit 1
fi
done
echo "✅ Validation passed"
exit 0#!/bin/bash
# Access staged files via git commands
STAGED=$(git diff --cached --name-only)#!/bin/bash
COMMIT_MSG_FILE=$1
message=$(cat "$COMMIT_MSG_FILE")#!/bin/bash
while read local_ref local_sha remote_ref remote_sha; do
# Process each ref
done#!/bin/bash
PREV_HEAD=$1
NEW_HEAD=$2
IS_BRANCH=$3 # 1 for branch checkout, 0 for file checkoutGIT_DIRGIT_WORK_TREEGIT_INDEX_FILEGIT_AUTHOR_NAMEGIT_AUTHOR_EMAILGIT_COMMITTER_NAMEGIT_COMMITTER_EMAIL#!/bin/bash
echo "Running $BASH_SOURCE"
set | grep GIT
echo "PWD is $PWD"core.hooksPath# Bad: Command injection risk
git diff --cached --name-only | xargs some-command
# Good: Proper quoting and validation
git diff --cached --name-only | while read file; do
if [ -f "$file" ]; then
some-command "$file"
fi
donechmod 755 .githooks/pre-commit # Owner write, others read+execute# Bad: Hardcoded token
API_TOKEN="secret123"
# Good: Read from environment
API_TOKEN="${API_TOKEN:-$(cat ~/.api_token)}"ls -l .githooks/pre-commitcore.hooksPathgit config core.hooksPath.sample#!/bin/bash.githooks/pre-commitecho $?set -xgit commit --no-verify--no-verifycore.hooksPath.git/hooks/.githooks/git ls-files .githooks/git config core.hooksPathreferences/hook-types.mdreferences/server-side-hooks.mdreferences/advanced-patterns.mdreferences/ci-cd-integration.mdexamples/modular-pre-commit/examples/validate-bash.shexamples/validate-skills.shexamples/setup-hooks.shgit config core.hooksPath .githookschmod +x .githooks/pre-commit.githooks/pre-commitgit commit --no-verify#!/bin/bash
set -e
echo "🔍 Running validation..."
# Validation logic here
echo "✅ Validation passed"
exit 0git diff --cached --name-only --diff-filter=ACMcommand || exit 1