| Crates.io | hooksmith |
| lib.rs | hooksmith |
| version | 1.15.0 |
| created_at | 2025-04-21 01:21:33.334488+00 |
| updated_at | 2025-09-12 10:08:05.01042+00 |
| description | Trivial git hook management tool |
| homepage | https://github.com/TomPlanche/hooksmith |
| repository | https://github.com/TomPlanche/hooksmith |
| max_upload_size | |
| id | 1642166 |
| size | 102,393 |
,"( .
////\ /
(//////--,,,,,_____ ,"
_;"""----/////_______;,, //
__________;"o,-------------......"""""`'-._/(
""'==._.__,;;;;""" ____,.-.==
"-.:______,...;---""/" " \(
'-._ `-._(" \\
'-._ '._
Hooksmith is a lightweight, easy-to-use tool that simplifies Git hook management. Define your hooks in a simple YAML file and let Hooksmith handle the rest.
build.rscargo install hooksmith
Add to your Cargo.toml:
[build-dependencies]
hooksmith = "1.10.0"
Create a build.rs file:
use std::path::Path;
fn main() {
let config_path = Path::new("hooksmith.yaml");
hooksmith::init(&config_path);
}
๐ก Note: Hooksmith includes shell completions for Fish. After installation, they become available automatically.
Hooksmith is built with minimal but powerful dependencies:
clap: For robust command-line argument parsingconsole & dialoguer: For beautiful terminal interfacesserde & serde_yaml: For YAML configuration handlingthiserror: For ergonomic error handlinghooksmith.yaml file in your project root:pre-commit:
commands:
- cargo fmt --all -- --check
- cargo clippy -- --deny warnings
pre-push:
commands:
- cargo test
hooksmith install
That's it! Your Git hooks are now ready to use.
Hooksmith uses a YAML configuration file (default: hooksmith.yaml) to define your hooks:
# Format and lint code before committing
pre-commit:
commands:
- cargo fmt --all -- --check
- cargo clippy --workspace --all-features -- --deny warnings
# Run tests before pushing
pre-push:
commands:
- cargo test --all-features
- cargo build --verbose
# Validate commit messages
commit-msg:
commands:
# Use custom script to validate commit messages
- ./scripts/verify-commit-message.sh $1
You can optionally assign names to your commands for better readability and clearer output. This is especially useful for long or complex commands:
pre-commit:
commands:
- cargo fmt --all -- --check
- clippy-linter: cargo clippy --workspace --release --all-targets --all-features -- --deny warnings -D warnings -W clippy::correctness -W clippy::suspicious -W clippy::complexity -W clippy::perf -W clippy::style -W clippy::pedantic
- typos
pre-push:
commands:
- cargo build -q
- test-suite: cargo test -q
Benefits of named commands:
When you use named commands, both the dry-run output and performance monitoring will display the command name followed by the actual command in parentheses.
# Install all hooks defined in configuration
hooksmith install
# Run a specific hook manually
hooksmith run pre-commit
# Run a hook with performance monitoring
hooksmith run pre-commit --profile
# Uninstall all hooks or a specific one
hooksmith uninstall
hooksmith uninstall pre-commit
# Compare installed hooks with configuration
hooksmith compare
# Validate hook configuration against Git standards
hooksmith validate
Add --dry-run to any command to preview changes without applying them:
hooksmith install --dry-run
Hooksmith includes built-in performance monitoring to help you optimize your hook execution times. Use the --profile flag with the run command to see detailed timing information:
hooksmith run pre-commit --profile
This will show you:
โฑ๏ธ Hook execution summary:
Hook 'pre-commit' (768ms)
cargo fmt --all -- --check: 146ms
clippy-linter: 394ms
typos: 226ms
Total: 768ms
Performance monitoring is particularly useful for:
Define commands that only run when files within specific paths have changed. This lets you scope expensive checks to the parts of the repository they affect.
pre-commit:
# Global commands: always run
commands:
- cargo fmt --all -- --check
# Path-based blocks: run only if matching files changed
paths:
src/:
commands:
- cargo clippy --workspace -- -D warnings
crates/api/:
working_directory: crates/api
commands:
- npm ci
- npm test
src/).pre-commit and pre-push.
pre-commit: uses git diff --name-only --cached.pre-push: diffs @{u}..HEAD when upstream exists, otherwise falls back to HEAD~1..HEAD.commands run.working_directory (optional) sets the directory for those commands only. Global commands run in the current directory.commands if you want nothing to run in that case.| Command | Description |
|---|---|
install |
Install all hooks from configuration file |
run <hook> |
Run a specific hook manually |
run <hook> --profile |
Run a hook with performance timing information |
uninstall [hook] |
Uninstall all hooks or a specific one |
compare |
Compare installed hooks with configuration |
validate |
Validate hook configuration against Git standards |
| Option | Description |
|---|---|
--config-path <PATH> |
Specify a custom configuration file path |
--dry-run |
Preview changes without applying them |
--verbose |
Show detailed output during execution |
--help |
Display help information |
| Option | Description |
|---|---|
--interactive or -i |
Interactively select hooks to run |
--profile or -p |
Show performance timing for hook execution |
Contributions are welcome! Feel free to:
This project is dual-licensed under either:
at your option.