Skip to content

About

Pre-commit git hooks for Rust crate

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smbCloud Logo
pre-commit-hooks

Run cargo fmt, clippy or any command as a git pre-commit hook, configured in Cargo.toml.

Website · Source · crates.io

Crates.io License

pre-commit-hooks reads hook commands from Cargo.toml and runs them on git commit. It works with Cargo workspaces. It is a fork of the unmaintained pre-commit.

Install

[dependencies]
pre-commit-hooks = "0.3"

In a workspace, add it to one package, usually the main one. The hook applies to the whole repository.

Usage

Add a table like this to your root Cargo.toml:

[package.metadata.precommit]
fmt = "cargo fmt"
sort = "cargo sort"

For a workspace:

[workspace.metadata.precommit]
fmt = "cargo fmt"
sort = "cargo sort -w"

Then run:

cargo clean
cargo build

You now have a pre-commit file in .git/hooks that runs the listed entries.

FAQ

How do I run cargo fmt before every commit? Add fmt = "cargo fmt" under [package.metadata.precommit], run cargo clean && cargo build, and the hook is installed.

Does it work with Cargo workspaces? Yes. Use [workspace.metadata.precommit] in the root Cargo.toml and add the crate to one member package.

Is pre-commit-hooks maintained? Yes, by smbCloud. Releases are small and focus on keeping it working with current Cargo.

About smbCloud

smbCloud is a cloud platform for small and medium businesses with Deploy, Auth, Mail and GresIQ. Enterprise power at startup velocity. Read the docs or install the CLI with cargo install smbcloud-cli.

Credit

Derived from rustation/pre-commit by Joe Grund. The find_crate_root function is refactored with the help of emilgardis.

License

MIT

Copyright

© 2026 Seto Elkahfi (smbCloud). Distributed by Splitfire AB.

About

Pre-commit git hooks for Rust crate

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages