Skip to content

Instantly share code, notes, and snippets.

@shvargon
Forked from zeenix/pre-commit
Last active April 21, 2020 12:37
Show Gist options
  • Save shvargon/1fefd3e4d92df4ae627f8246eb5f2f91 to your computer and use it in GitHub Desktop.
Save shvargon/1fefd3e4d92df4ae627f8246eb5f2f91 to your computer and use it in GitHub Desktop.
git hook to ensure commit doesn't break rustfmt
#!/usr/bin/env bash
# Put in your Rust repository's .git/hooks/pre-commit to ensure you never breaks rustfmt.
for FILE in `git diff --cached --name-only`; do
if [[ $FILE == *.rs ]] && ! rustfmt --edition=2018 --check $FILE; then
echo -e "\n Commit rejected due to invalid formatting of \"$FILE\" file."
exit 1
fi
done
# default 2018 edition
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#edition
edition = "2018"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment