Created
March 20, 2025 05:18
-
-
Save 607011/d7b5ceae3751e46a30157d983a9f6bf9 to your computer and use it in GitHub Desktop.
git pre-commit hook for Rust projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run cargo fmt check | |
echo "Running cargo fmt check ..." | |
cargo fmt --all -- --check | |
if [ $? -ne 0 ]; then | |
echo "cargo fmt check failed! Fix the errors before committing." | |
exit 1 | |
fi | |
# Run cargo clippy | |
echo "Running cargo clippy ..." | |
cargo clippy -- -D warnings | |
if [ $? -ne 0 ]; then | |
echo "cargo clippy failed! Fix the errors and warnings before committing." | |
exit 1 | |
fi | |
# Run cargo test | |
echo "Running cargo test ..." | |
cargo test --all-features | |
if [ $? -ne 0 ]; then | |
echo "cargo test failed! Investigate the failed tests before committing." | |
exit 1 | |
fi | |
# If all checks pass, allow the commit | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment