From 2c2cb00e2e485e1a187678e018d13c4681ecf6cf Mon Sep 17 00:00:00 2001 From: bad Date: Sun, 3 Apr 2022 22:10:55 +0200 Subject: [PATCH] Add a pre-commit-hook --- pre-commit-hook.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 pre-commit-hook.sh diff --git a/pre-commit-hook.sh b/pre-commit-hook.sh new file mode 100755 index 0000000..34f56aa --- /dev/null +++ b/pre-commit-hook.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Stolen from +# https://deaddabe.fr/blog/2021/09/29/git-pre-commit-hook-for-rust-projects/ +# Run `ln -s ../../pre-commit-hook.sh .git/hooks/pre-commit` to install + +set -eu + +if ! cargo fmt -- --check +then + echo "There are some code style issues." + echo "Run cargo fmt first." + exit 1 +fi + +if ! cargo clippy --all-targets -- -D warnings +then + echo "There are some clippy issues." + exit 1 +fi + +if ! cargo test +then + echo "There are some test issues." + exit 1 +fi + +exit 0