Expand description
§husky-rs
Git hooks management for Rust projects.
§Zero-Config Usage
Just add husky-rs as a dependency and create hooks in .husky/hooks/.
The hooks will be automatically installed when you build your project:
cargo add husky-rs
mkdir -p .husky/hooks
echo '#!/bin/sh\necho "Running pre-commit hook"' > .husky/hooks/pre-commit
cargo build # Hooks installed automatically!That’s it! No configuration needed, no manual installation steps.
§How It Works
husky-rs uses a build script (build.rs) to automatically copy hooks from
.husky/hooks/ to .git/hooks/ during the build process. This means:
- Works with both
dependenciesanddev-dependencies - Hooks are installed automatically on
cargo buildorcargo test - Changes to hooks trigger automatic reinstallation (no
cargo cleanneeded!) - Cross-platform support (Unix-like systems and Windows)
§Skipping Hook Installation
Set the NO_HUSKY_HOOKS environment variable to skip hook installation:
NO_HUSKY_HOOKS=1 cargo build§Optional Utilities
The functions and constants below are completely optional - you don’t need them for basic usage. They’re provided for advanced use cases like custom tooling or programmatic hook management.
Constants§
- HUSKY_
DIR - The default directory name for husky configuration (
.husky) - HUSKY_
HOOKS_ DIR - The default hooks subdirectory name (
hooks) - SUPPORTED_
HOOKS - List of all Git hooks supported by husky-rs.
Functions§
- hooks_
dir - Returns the standard husky hooks directory path for a given project root.
- is_
valid_ hook_ name - Checks if a given hook name is valid/supported by Git.
- should_
skip_ installation - Checks if hook installation should be skipped based on the
NO_HUSKY_HOOKSenvironment variable.