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

change pre-commit hook to only check for formatting errors

This commit is contained in:
dark64 2020-05-14 15:40:46 +02:00
parent c26710e13b
commit 30028e4179

View file

@ -1,9 +1,12 @@
#!/bin/bash #!/bin/bash
log () {
printf "[\033[1;37mpre-commit\033[0m] $1\n"
}
rustfmt +nightly --version &>/dev/null rustfmt +nightly --version &>/dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
printf "[pre-commit] \033[0;31mERROR\033[0m: rustfmt +nightly not available, install rustfmt via -\n" log "\033[0;33mWARN\033[0m: rustfmt +nightly not found, skipping pre-commit hook"
printf "[pre-commit] \033[0;31mERROR\033[0m: $ rustup component add rustfmt --toolchain nightly\n"
exit 0 exit 0
fi fi
@ -19,11 +22,13 @@ for file in $(git diff --name-only --cached); do
done done
if [ -n "$files" ]; then if [ -n "$files" ]; then
log "the following files have improper formatting:\n"
for file in "${files[@]}"; do for file in "${files[@]}"; do
rustfmt +nightly $file printf "\033[0;33m\t$file\n"
git add $file
printf "[\033[1;32mrustfmt\033[0m] $file\n"
done done
printf "\n\033[0m"
log "aborting commit"
exit 1
fi fi
exit 0 exit 0