Add simple pre-commit hook for running 'cargo fmt'
Inspired by https://github.com/mimblewimble/grin/pull/110
This commit is contained in:
parent
d2db7d0cf2
commit
9e7bd29087
4
.hooks/install.sh
Executable file
4
.hooks/install.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd `dirname $0`/../.git/hooks/
|
||||
ln -s ../../.hooks/pre-commit
|
||||
21
.hooks/pre-commit
Executable file
21
.hooks/pre-commit
Executable 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
|
||||
Loading…
Reference in New Issue
Block a user