Skip to main content

6. Git Hooks Enterprise

6.1 Architecture

Batho's Git hooks provide automated quality gates and workflow enforcement:

Figure 9: Git Hooks Architecture - Flowchart showing how YAML-defined hooks map to Git hook scripts.

6.2 Hook Lifecycle

The hook lifecycle provides a consistent workflow for configuration and management:

StageCommandAction
DefineEdit .batho/hooks.yamlConfigure stages and commands
Planbatho hooks listShow supported + configured hooks
Installbatho hooks install --allGenerate scripts in .git/hooks/
ExecuteGit trigger or batho hooks run --hook NAMERun stage pipeline
Removebatho hooks remove --allClean managed scripts

6.3 Supported Git Hooks

All standard Git client-side hooks are supported:

HookTypical Use Case
applypatch-msgPatch message validation
pre-commitLint, format, type-check
prepare-commit-msgAuto-generate commit messages
commit-msgCommit message policy enforcement
post-commitNotifications, metrics
pre-rebasePrevent dangerous rebases
post-checkoutEnvironment reset, re-index
post-mergeDependency updates
pre-pushTest suite, security scans
pre-receiveServer-side validation stub
updateBranch-specific policies
post-updateDeploy triggers

6.4 Configuration Example

# .batho/hooks.yaml
hooks:
pre-commit:
- name: "Check formatting"
command: "ruff format --check ."
- name: "Lint"
command: "ruff check ."
- name: "Type check"
command: "mypy ."

pre-push:
- name: "Run tests"
command: "pytest"
- name: "Security scan"
command: "bandit -r src/"

post-checkout:
- name: "Re-index"
command: "batho index --root ."

6.5 Best Practices

  1. Fast pre-commit: Keep pre-commit hooks under 2 seconds
  2. Cache dependencies: Use cached virtual environments
  3. Parallel execution: Run independent checks in parallel
  4. Fail fast: Order checks by likelihood of failure