fractal/hooks/pre-commit.hook

26 lines
692 B
Text
Raw Normal View History

#!/bin/sh
if ! which rustup &> /dev/null; then
curl https://sh.rustup.rs -sSf | sh -s -- -y
export PATH=$PATH:$HOME/.cargo/bin
if ! which rustup &> /dev/null; then
echo "Failed to install rustup"
fi
fi
if ! rustup component list --toolchain nightly|grep rustfmt-preview &> /dev/null; then
echo "Installing nightly rustfmt.."
rustup component add rustfmt-preview --toolchain nightly
fi
echo "--Checking style--"
cargo +nightly fmt --all -- --check
if test $? != 0; then
echo "--Checking style fail--"
echo "Please fix the above issues, either manually or by running: cargo +nightly fmt --all"
exit -1
else
echo "--Checking style pass--"
fi