Skip to content

Instantly share code, notes, and snippets.

@zeenix
Created December 13, 2017 14:59
Show Gist options
  • Save zeenix/e09e829120546592d68d56b2b60f0cd0 to your computer and use it in GitHub Desktop.
Save zeenix/e09e829120546592d68d56b2b60f0cd0 to your computer and use it in GitHub Desktop.
git hook to ensure commit doesn't break rustfmt
#!/bin/sh
# Put in your Rust repository's .git/hooks/pre-commit to ensure you never
# breaks rustfmt.
#
# WARNING: rustfmt is a fast moving target so ensure you have the version that
# all contributors have.
for FILE in `git diff --cached --name-only`; do
#if [[ $FILE == *.rs ]] && ! rustup run nightly rustfmt --write-mode diff --skip-children $FILE; then
if [[ $FILE == *.rs ]] && ! rustfmt --write-mode diff --skip-children $FILE; then
echo "Commit rejected due to invalid formatting of \"$FILE\" file."
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment