Add simple pre-commit hook for running 'cargo fmt'

Inspired by https://github.com/mimblewimble/grin/pull/110
This commit is contained in:
Roman Zeyde 2018-11-21 09:43:10 +02:00
parent d2db7d0cf2
commit 9e7bd29087
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 25 additions and 0 deletions

4
.hooks/install.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
cd `dirname $0`/../.git/hooks/
ln -s ../../.hooks/pre-commit

21
.hooks/pre-commit Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
CARGO_FMT="cargo +stable fmt --all"
$CARGO_FMT --version &>/dev/null
if [ $? != 0 ]; then
printf "[pre_commit] \033[0;31merror\033[0m: \"$CARGO_FMT\" not available?\n"
exit 1
fi
$CARGO_FMT -- --check
result=$?
printf "[pre_commit] $CARGO_FMT → "
if [ $result != 0 ]; then
printf "\033[0;31merror\033[0m \n"
else
printf "\033[0;32mOK\033[0m \n"
fi
exit $result