Skip to content

Git Hooks Management

Husky is used in VUP to run checks automatically during Git workflows.

Current Setup in VUP

VUP enables Husky with:

json
{
  "scripts": {
    "prepare": "husky",
    "lint-staged": "lint-staged"
  }
}

After pnpm install, the prepare script installs hooks automatically.

Existing Hooks

Current hooks in the repository:

  • .husky/pre-commit
  • .husky/pre-push

Example pre-commit from VUP:

bash
# Run ESLint + Prettier via lint-staged
pnpm lint-staged

# Regenerate apps list used by templates
node .husky/scripts/generate-apps-list.js

# Stage generated file
git add .template.config.json

Example pre-push from VUP:

bash
# Pre-push lightweight notice
echo "✅ Preparing to push..."

Add or Update Hooks

Create or edit hook files directly under .husky/:

bash
# Example: add commit-msg hook
cat > .husky/commit-msg <<'HOOK'
npx commitlint --edit "$1"
HOOK
chmod +x .husky/commit-msg

Common Practices

  • Keep pre-commit fast (format/lint staged files only).
  • Put long-running checks in CI instead of local hooks.
  • Keep hook logic in scripts when commands become complex.

Troubleshooting

Hook not running

  • Ensure file is executable: chmod +x .husky/*
  • Reinstall dependencies to trigger prepare: pnpm install

Need to bypass temporarily

bash
# Skip hooks for one commit (emergency only)
git commit --no-verify -m "chore: emergency fix"