1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

add pre-commit git hook

This commit is contained in:
dark64 2020-05-13 22:51:21 +02:00
parent 3efcab6afc
commit c26710e13b
2 changed files with 32 additions and 0 deletions

29
.githooks/pre-commit Executable file
View file

@ -0,0 +1,29 @@
#!/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

3
scripts/install_hooks.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
git config core.hooksPath .githooks