From 5ce67a449d84fa4ca258d03fa6e46e1e7f30f660 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Salinas Date: Sat, 18 Nov 2023 21:27:19 -0300 Subject: [PATCH] chore: add git hooks --- build.rs | 2 +- hooks/install.sh | 11 +++++++++++ hooks/pre-commit.sh | 11 +++++++++++ hooks/pre-push.sh | 16 ++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 hooks/install.sh create mode 100755 hooks/pre-commit.sh create mode 100755 hooks/pre-push.sh diff --git a/build.rs b/build.rs index 7609593..d506869 100644 --- a/build.rs +++ b/build.rs @@ -2,4 +2,4 @@ fn main() { // trigger recompilation when a new migration is added println!("cargo:rerun-if-changed=migrations"); -} \ No newline at end of file +} diff --git a/hooks/install.sh b/hooks/install.sh new file mode 100755 index 0000000..be4d8e4 --- /dev/null +++ b/hooks/install.sh @@ -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 + diff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh new file mode 100755 index 0000000..4ac83ee --- /dev/null +++ b/hooks/pre-commit.sh @@ -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 diff --git a/hooks/pre-push.sh b/hooks/pre-push.sh new file mode 100755 index 0000000..a8263d7 --- /dev/null +++ b/hooks/pre-push.sh @@ -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