Overview
Hooks are executable scripts stored in a.dvhooks/ directory at the root of your repository. Because they live inside the repository, they sync to all collaborators just like any other file.
Common use cases:
- Lint and syntax checks
- Code formatting enforcement
- Preventing commits of large or forbidden files
- Custom project-specific validation
- Before a commit, Diversion runs the
.dvhooks/pre-commitscript with the committed files as command-line arguments - Exit code
0means the hook passed - the commit proceeds - Any non-zero exit code means the hook failed - the commit is blocked
- The hook’s stdout/stderr output is displayed to the user
Pre-commit hooks are client-side only. They run when committing via the CLI or Desktop app. Commits made directly through the WebApp or API bypass hooks.
Creating a Pre-Commit Hook
Create the hook script
Create a On Mac/Linux, make the script executable:
pre-commit script inside .dvhooks/. The script can be written in any language, as long as it’s executable.File Arguments
The files being committed are passed to your hook script as command-line arguments. Your script can access them via$@ (Mac/Linux) or %* (Windows).
When the file list is too large for a single command invocation, Diversion automatically splits it into chunks and runs the hook multiple times in parallel. If any invocation fails, the commit is blocked.
Example - check committed files for large binaries:
Environment Variables
Diversion also passes context to your hook script via environment variables:| Variable | Description |
|---|---|
DV_REPO_ROOT | Absolute path to the workspace root |
DV_COMMIT_MESSAGE | The commit message |
DV_BRANCH | Current branch name |
Skipping Hooks
Use the--no-verify flag to bypass pre-commit hooks for a single commit:
Behavior Details
- Timeout: Hooks have a 60-second timeout. If the hook doesn’t finish in time, the commit is blocked with a timeout message.
- Working directory: The hook runs with the workspace root as its working directory.
- Output limit: Hook output is capped at 1 MB. Output beyond that limit is truncated.
- Output display: Hook output is always shown to the user, whether the hook passes or fails.
- Platform detection:
- Mac/Linux: Diversion looks for an executable file named
pre-commitin.dvhooks/. If the file exists but isn’t executable, you’ll see an error prompting you to runchmod +x. - Windows: Diversion looks for
pre-commit.bat,pre-commit.cmd, orpre-commit.ps1in.dvhooks/(checked in that order).
- Mac/Linux: Diversion looks for an executable file named

