chore: add git hooks

This commit is contained in:
Felipe 2023-11-18 21:27:19 -03:00
parent d593d0a6ab
commit 5ce67a449d
Signed by: pitbuster
SSH key fingerprint: SHA256:HDYu2Pm4/TmSX8GBwV49UvFWr1Ljg8XlHxKeCpjJpOk
4 changed files with 39 additions and 1 deletions

View file

@ -2,4 +2,4 @@
fn main() { fn main() {
// trigger recompilation when a new migration is added // trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations"); println!("cargo:rerun-if-changed=migrations");
} }

11
hooks/install.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
set -eu
if GIT_ROOT="$(git rev-parse --show-toplevel)"; then
ln -s $GIT_ROOT/hooks/pre-commit.sh $GIT_ROOT/.git/hooks/pre-commit
ln -s $GIT_ROOT/hooks/pre-push.sh $GIT_ROOT/.git/hooks/pre-push
else
echo "Failed to get git root, aborting"
exit 1
fi

11
hooks/pre-commit.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
set -eu
if ! cargo fmt -- --check
then
echo "There are some code style issues."
echo "Run cargo fmt first."
exit 1
fi
exit 0

16
hooks/pre-push.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
set -eu
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