1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/.githooks/pre-commit
2020-05-13 22:51:21 +02:00

29 lines
693 B
Bash
Executable file

#!/bin/bash
rustfmt +nightly --version &>/dev/null
if [ $? != 0 ]; then
printf "[pre-commit] \033[0;31mERROR\033[0m: rustfmt +nightly not available, install rustfmt via -\n"
printf "[pre-commit] \033[0;31mERROR\033[0m: $ rustup component add rustfmt --toolchain nightly\n"
exit 0
fi
files=()
for file in $(git diff --name-only --cached); do
if [ ${file: -3} == ".rs" ]; then
rustfmt +nightly --check $file &>/dev/null
if [ $? != 0 ]; then
files+=($file)
fi
fi
done
if [ -n "$files" ]; then
for file in "${files[@]}"; do
rustfmt +nightly $file
git add $file
printf "[\033[1;32mrustfmt\033[0m] $file\n"
done
fi
exit 0