From e791f657cc3906addb63d0dc9c49d0409b26f560 Mon Sep 17 00:00:00 2001 From: Junha Date: Fri, 7 Jul 2023 13:33:58 +0000 Subject: [PATCH] chore: add git (local env) prehook but not auto setup --- .github/hooks/prepare-commit-msg | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/hooks/prepare-commit-msg diff --git a/.github/hooks/prepare-commit-msg b/.github/hooks/prepare-commit-msg new file mode 100644 index 00000000..c3e9ab38 --- /dev/null +++ b/.github/hooks/prepare-commit-msg @@ -0,0 +1,30 @@ +#!/bin/sh + +echo "prepare-commit-msg hook script is running" + +commit_template_file=$(git config commit.template) + +if [ -z "$commit_template_file" ]; then + echo "Commit template is not configured. Please set the commit.template configuration." + exit 1 +fi + +commit_msg_file="$1" +commit_msg_type="$2" +commit_msg="$3" + +if [ "$commit_msg_type" = "-m" ]; then + echo "$commit_msg" > "$commit_msg_file" +fi + +commit_msg=$(cat "$commit_msg_file") + +commit_msg_regex=$(cat "$(dirname "$0")/../../.github/commit-regular.txt") + +if ! echo "$commit_msg" | grep -Eq "$commit_msg_regex"; then + echo "Invalid commit message format." + echo + cat "$commit_template_file" + echo + exit 1 +fi \ No newline at end of file