1
0
mirror of https://github.com/proot-me/proot-rs.git synced 2024-11-23 13:36:17 +00:00
proot-rs/.githooks/pre-commit
2021-05-24 09:13:43 -04:00

24 lines
637 B
Bash
Executable File

#!/bin/bash
echo "Starting check shell code issues ..."
find . -name "*.sh" -print0 | xargs -0 --no-run-if-empty shellcheck || exit 1
echo "Starting check Rust code format ..."
has_issues=0
edition=2018
for file in $(git diff --name-only --staged | grep '\.rs$'); do
if [ -f "${file}" ] && ! rustfmt --edition ${edition} --check --color auto "${file}"; then
echo ""
has_issues=1
rustfmt --edition ${edition} "${file}"
fi
done
if [ ${has_issues} -eq 0 ]; then
exit 0
fi
echo "Your code contains formatting issues and has been corrected. Please run \`git add\` to add them and commit them."
exit 1