Skip to content

Instantly share code, notes, and snippets.

@zeenix
Created November 20, 2017 17:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeenix/d797e299ae0000e471359ec2844acaae to your computer and use it in GitHub Desktop.
Save zeenix/d797e299ae0000e471359ec2844acaae to your computer and use it in GitHub Desktop.
Git pre-commit hook to ensure your changes don't break rustfmt formatting rules
#!/bin/sh
for FILE in `git diff --cached --name-only`; do
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
@tobsan
Copy link

tobsan commented Nov 20, 2017

Nice!

iirc, the [[ construct is bash specific and might not be supported in all variants of /bin/sh.

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