From 064b39ff22f2269e6341bec2f10dc0133edfc5c8 Mon Sep 17 00:00:00 2001 From: sarthakjdev Date: Sat, 1 Jun 2024 19:03:58 +0530 Subject: [PATCH] feat: add husky Signed-off-by: sarthakjdev --- .husky/hooks/commit-msg | 32 ++++++++++++++------------------ .husky/hooks/pre-commit | 7 +++---- .husky/hooks/pre-push | 3 +-- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/.husky/hooks/commit-msg b/.husky/hooks/commit-msg index db0a7b4..f37eba3 100755 --- a/.husky/hooks/commit-msg +++ b/.husky/hooks/commit-msg @@ -1,26 +1,22 @@ #!/bin/sh -. "$(dirname "$0")/_/husky.sh" +# # Check for conventional commit format +# commit_msg=$(cat "$1") +# # Modified regex to allow for more valid formats +# conventional_commit_regex='^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+\))?(!)?(:)(\s.*)?$' -# check for conventional commit format -commit_msg=$(cat "$1") -# Regex to match Conventional Commit format -conventional_commit_regex='^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$' - -if ! [[ "$commit_msg" =~ $conventional_commit_regex ]]; then - echo "ERROR: Commit message does not adhere to Conventional Commits format:" - echo "$commit_msg" - exit 1 -fi +# echo "$conventional_commit_regex" +# if ! [[ "$commit_msg" =~ $conventional_commit_regex ]]; then +# echo "ERROR: Commit message does not adhere to Conventional Commits format:" +# echo "$commit_msg" +# echo "$($commit_msg =~ $conventional_commit_regex )" +# exit 1 +# fi # If not a merge commit, require commit to be signed off if [ ! -e .git/MERGE_MSG ] && ! grep -q "^Signed-off-by: " "$1"; then - echo >&2 "Commit message must be signed off with your user name and email." - echo >&2 "To sign off your commit, add the -s flag to the git commit command." - exit 1 + echo >&2 "Commit message must be signed off with your user name and email." + echo >&2 "To sign off your commit, add the -s flag to the git commit command." + exit 1 fi - - - - diff --git a/.husky/hooks/pre-commit b/.husky/hooks/pre-commit index ffc3b34..35d2694 100755 --- a/.husky/hooks/pre-commit +++ b/.husky/hooks/pre-commit @@ -1,11 +1,10 @@ #!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" -branch=`git symbolic-ref HEAD` +branch=$(git symbolic-ref HEAD) if [ "$branch" = "refs/heads/master" ]; then - echo "\\033[31mDirect commit to master is not allowed.\\033[0m" - exit 1 + echo "\\033[31mDirect commit to master is not allowed.\\033[0m" + exit 1 fi go fmt ./... diff --git a/.husky/hooks/pre-push b/.husky/hooks/pre-push index 2a4657e..864d02f 100755 --- a/.husky/hooks/pre-push +++ b/.husky/hooks/pre-push @@ -1,7 +1,6 @@ #!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" -branch=`git symbolic-ref HEAD` +branch=$(git symbolic-ref HEAD) if [ "$branch" = "refs/heads/master" ]; then echo "\\033[31mDirect push to master is not allowed.\\033[0m"