Crate husky_rs

Crate husky_rs 

Source
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 dependencies and dev-dependencies
  • Hooks are installed automatically on cargo build or cargo test
  • Changes to hooks trigger automatic reinstallation (no cargo clean needed!)
  • 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_HOOKS environment variable.