Skip to content

Instantly share code, notes, and snippets.

@mmagician
Forked from hryniuk/pre-commit-cargo-fmt
Last active March 13, 2024 14:06
Show Gist options
  • Save mmagician/1d660b7e2fd7155b1bc58ba39f6c8ea3 to your computer and use it in GitHub Desktop.
Save mmagician/1d660b7e2fd7155b1bc58ba39f6c8ea3 to your computer and use it in GitHub Desktop.
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
diff=$(cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
fi
exit 0
@mmagician
Copy link
Author

This file pre-commit should be placed in .git/hooks, per repo. To set globally, follow this post. Remember to make this an executable: chmod +x pre-commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment