Run vg in a Pre-Commit Hook
Add the Vibgrate CLI to a pre-commit hook so a drift budget breach blocks the commit locally. Keep it fast with --changed-only and mirror the budget in CI.
Catching drift before it leaves a developer's machine is the cheapest place to fix it. A pre-commit hook runs the Vibgrate CLI on each commit, so a budget breach stops the commit locally rather than failing later in CI.
Prerequisites
- A git repository.
- The Vibgrate CLI installed locally.
Steps
1. Choose a hook approach
You can use a hook manager (like the pre-commit framework) or a plain git hook script. Either way, the hook runs a vg command and a non-zero exit aborts the commit.
2. Install the CLI
Install the CLI globally so vg is on your PATH for the hook.
npm i -g @vibgrate/cli
3. Add the hook command
In your pre-commit hook, run a budgeted scan. A breach exits non-zero and blocks the commit.
vg scan --drift-budget 60
If you use the pre-commit framework, add an equivalent local hook entry that runs this command.
4. Keep it fast
A full scan on every commit can be slow. Limit the hook to changed files so it stays snappy.
vg scan --changed-only --drift-budget 60
5. Verify the hook blocks commits
Stage a change that pushes drift over the budget and attempt to commit; the hook should abort with a non-zero exit. Stage a clean change and the commit should proceed.
Verification
Run the hook command manually and check the exit code: 0 lets the commit through, non-zero blocks it. This mirrors exactly how git treats the pre-commit hook.
vg scan --changed-only --drift-budget 60
Next Steps
- Mirror the same budget in CI so local and remote gates agree.
- Use
vg shareto install a code-map pre-commit hook for your team. - Push results to Vibgrate Cloud with
vg scan --pushfrom CI.