From 9d5680e1338439dac68253ce17369ab92f7393ac Mon Sep 17 00:00:00 2001 From: Felipe Contreras Salinas Date: Sat, 18 Nov 2023 21:39:42 -0300 Subject: [PATCH] chore: add git hooks (#35) Reviewed-on: https://oolong.ludwig.dog/pitbuster/huellas/pulls/35 Co-authored-by: Felipe Contreras Salinas Co-committed-by: Felipe Contreras Salinas --- CHANGELOG.md | 6 ++++++ build.rs | 2 +- hooks/install.sh | 11 +++++++++++ hooks/pre-commit.sh | 11 +++++++++++ hooks/pre-push.sh | 16 ++++++++++++++++ 5 files changed, 45 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/CHANGELOG.md b/CHANGELOG.md index 4c9f5a9..3d0e7d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [unreleased] + +### Miscellaneous Tasks + +- Add git hooks + ## [0.2.2] - 2023-11-10 ### Bug Fixes 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