AGENT SKILL

git-hooks

Auto-generate and manage Git hooks for pre-commit, pre-push, commit-msg, and more.

License 许可
MIT
最近更新
2026-08-23
Stars
★ 1
Forks
0

01 前言 Front Matter

description
Auto-generate and manage Git hooks for pre-commit, pre-push, commit-msg, and more.

02 资源文件 2

03 SKILL.md 正文

Git Hooks

Set up and manage Git hooks for any repository.

Use when adding automated checks to git workflows — linting, testing, commit message validation.

Requirements

  • Git repository (.git/ directory must exist)
  • No API keys needed

Instructions

  1. Verify repo root: test -d .git && echo "OK" || echo "Not a git repo". Never create hooks outside a git repo.

  2. Back up existing hooks before overwriting:

    [ -f .git/hooks/pre-commit ] && cp .git/hooks/pre-commit .git/hooks/pre-commit.bak
    
  3. Create the hook and make it executable:

    cat > .git/hooks/<hook-name> << 'EOF'
    #!/bin/sh
    # hook content here
    EOF
    chmod +x .git/hooks/<hook-name>
    

Common Hooks

Pre-commit: Lint Staged Files

#!/bin/sh
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
# JavaScript/TypeScript
echo "$STAGED" | grep -E '\.(js|ts|jsx|tsx)$' | xargs -r npx eslint --quiet 2>/dev/null
[ $? -ne 0 ] && echo "❌ ESLint failed" && exit 1
# Python
echo "$STAGED" | grep -E '\.py$' | xargs -r python3 -m py_compile 2>&1
[ $? -ne 0 ] && echo "❌ Python syntax check failed" && exit 1
exit 0

Pre-push: Run Tests

#!/bin/sh
[ -f package.json ] && npm test
[ -f pytest.ini ] || [ -d tests/ ] && python3 -m pytest -q
exit $?

Commit-msg: Enforce Conventional Commits

#!/bin/sh
MSG=$(cat "$1")
if ! echo "$MSG" | grep -qE '^(feat|fix|docs|style|refactor|test|chore|ci|perf|build)(\(.+\))?: .+'; then
  echo "❌ Commit message must follow Conventional Commits format"
  echo "   Example: feat(auth): add login page"
  exit 1
fi

Pre-commit: Prevent Secret Leaks

#!/bin/sh
STAGED=$(git diff --cached --diff-filter=ACM -p)
if echo "$STAGED" | grep -qEi '(api[_-]?key|secret|password|token)\s*[=:]\s*["\x27][^\s]+'; then
  echo "❌ Potential secret detected in staged changes!"
  echo "   Review your changes and use environment variables instead."
  exit 1
fi

Management Commands

# List active hooks (non-sample)
ls .git/hooks/ | grep -v '\.sample$'

# Disable a hook temporarily
chmod -x .git/hooks/pre-commit

# Re-enable
chmod +x .git/hooks/pre-commit

# Remove a hook
rm .git/hooks/pre-commit

Edge Cases & Troubleshooting

  • Hook not running: Check chmod +x and shebang line (#!/bin/sh or #!/bin/bash).
  • Bypass when needed: git commit --no-verify skips pre-commit and commit-msg hooks.
  • Team sharing: Hooks in .git/hooks/ aren't committed. Use a hooks/ directory in repo root + git config core.hooksPath hooks/ for team-wide hooks.
  • Windows compatibility: Use #!/bin/sh (not bash) for cross-platform support. Avoid bash-specific syntax.
  • Slow hooks: Keep pre-commit hooks under 5 seconds. Only lint staged files, not the whole project.

Security Considerations

  • Add a secret-detection hook (see above) to prevent accidental credential commits.
  • Never store API keys or passwords in hook scripts themselves.

04 同仓库更多 Skills

kbarbel640-del
kbarbel640-del/skills

crowd-prompting

A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.

★ 1
kbarbel640-del
kbarbel640-del/skills

dilemm-ai

Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).

★ 1
kbarbel640-del
kbarbel640-del/skills

arxiv-paper-reviews

Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.

★ 1
kbarbel640-del
kbarbel640-del/skills

arxiv-paper-reviews

Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.

★ 1
kbarbel640-del
kbarbel640-del/skills

git-summary

Get a quick summary of the current Git repository including status, recent commits, branches, and contributors.

★ 1
kbarbel640-del
kbarbel640-del/skills

agent-constitution

Interact with AgentConstitution governance contracts on Base Sepolia. Check compliance, read rules, log actions, query governance state.

★ 1