chore: add git hooks (#35)

Reviewed-on: #35
Co-authored-by: Felipe Contreras Salinas <felipe@bstr.cl>
Co-committed-by: Felipe Contreras Salinas <felipe@bstr.cl>
This commit is contained in:
Felipe 2023-11-18 21:39:42 -03:00 committed by Felipe
parent c992711ab3
commit 9d5680e133
Signed by: Ludwig
GPG key ID: 441A26F83D31FAFF
5 changed files with 45 additions and 1 deletions

View file

@ -1,5 +1,11 @@
# Changelog
## [unreleased]
### Miscellaneous Tasks
- Add git hooks
## [0.2.2] - 2023-11-10
### Bug Fixes

View file

@ -2,4 +2,4 @@
fn main() {
// trigger recompilation when a new migration is added
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