Skip to main content
Pre-commit hooks let you run custom scripts that automatically validate your changes before each commit. If the script exits with a non-zero code, the commit is blocked - giving you a chance to fix issues before they reach the repository.

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
How it works:
  • Before a commit, Diversion runs the .dvhooks/pre-commit script with the committed files as command-line arguments
  • Exit code 0 means 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

1

Create the hooks directory

Create a .dvhooks directory at the root of your repository:
2

Create the hook script

Create a pre-commit script inside .dvhooks/. The script can be written in any language, as long as it’s executable.
On Mac/Linux, make the script executable:
3

Commit the hook

Commit the .dvhooks/ directory to share the hook with your collaborators:
Once committed, every collaborator on the branch will have the hook and it will run automatically before their commits.

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: Example - require a ticket number in the commit message:

Skipping Hooks

Use the --no-verify flag to bypass pre-commit hooks for a single commit:
This is useful for urgent fixes when you need to commit without running validation.

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-commit in .dvhooks/. If the file exists but isn’t executable, you’ll see an error prompting you to run chmod +x.
    • Windows: Diversion looks for pre-commit.bat, pre-commit.cmd, or pre-commit.ps1 in .dvhooks/ (checked in that order).