set -e
echo "๐ง Running pre-commit checks..."
STAGED_RS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.rs$' || true)
if [ -z "$STAGED_RS_FILES" ]; then
echo "No Rust files staged, skipping Rust checks..."
else
echo "๐ Running cargo fmt..."
cargo fmt --all
for file in $STAGED_RS_FILES; do
if [ -f "$file" ]; then
git add "$file"
fi
done
echo "โ Formatting complete and changes re-staged"
fi
echo "๐ Running cargo clippy --fix..."
cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features 2>&1 || true
if [ -n "$STAGED_RS_FILES" ]; then
for file in $STAGED_RS_FILES; do
if [ -f "$file" ]; then
git add "$file"
fi
done
echo "โ Clippy fixes applied and re-staged"
fi
echo "๐ Running clippy check..."
cargo clippy --all-targets --all-features -- -D warnings
echo "๐ Running cargo check..."
cargo check --all-targets
echo "๐งช Running cargo test..."
cargo test --all
echo "๐ Running doctests..."
cargo test --all --doc
echo "โ
All pre-commit checks passed!"