From e96a8aa85c8f2cc753c92546793c73991a8440af Mon Sep 17 00:00:00 2001 From: Pablo Baleztena Date: Wed, 18 Sep 2024 22:46:53 -0300 Subject: [PATCH] Update git hooks to protect main branch and force good practices --- .husky/pre-commit | 9 ++++++++- .husky/pre-push | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .husky/pre-push diff --git a/.husky/pre-commit b/.husky/pre-commit index 9348d24..c43da26 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,9 @@ # .husky/pre-commit -yarn lint-staged \ No newline at end of file +yarn lint-staged + +branch="$(git rev-parse --abbrev-ref HEAD)" + +if [ "$branch" = "main" ]; then + echo "You can't commit directly to main branch" + exit 1 +fi \ No newline at end of file diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..e8f3c80 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,12 @@ +# .husky/pre-push +branch="$(git rev-parse --abbrev-ref HEAD)" + +while read local_ref local_sha remote_ref remote_sha +do + echo $local_ref + echo $local_sha + echo $remote_ref + echo $remote_sha +done + +exit 1 \ No newline at end of file