From 5825fc22ae5ab44de07213532e5c6e9c6887ca94 Mon Sep 17 00:00:00 2001 From: akidon0000 Date: Tue, 19 Mar 2024 19:27:30 +0900 Subject: [PATCH] [100] add githooks --- .githooks/README.md | 20 ++++++++++++++++++++ .githooks/post-checkout | 4 ++++ .githooks/prepare-commit-msg | 28 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 .githooks/README.md create mode 100644 .githooks/post-checkout create mode 100644 .githooks/prepare-commit-msg diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 0000000..97e8405 --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,20 @@ +# githooks +このディレクトリは本来であれば、.git/hooks/ に配置するディレクトリです。 + +.git は、リポジトリの設定を管理するディレクトリであり、バージョン管理対象外です。 + +そのため、.githooks/の内容を.git/hooks/へコピーすることで、リポジトリのGit操作に適用しています。 + +以下のコマンドは、mint setupの一部として実行されます。 + + +```zsh +$ cp -r .githooks .git/hooks + +$ chmod -R +x .git/hooks +``` + +# 参考 +https://git-scm.com/docs/githooks + +https://www.farend.co.jp/blog/2020/04/git-hook/ diff --git a/.githooks/post-checkout b/.githooks/post-checkout new file mode 100644 index 0000000..6550af0 --- /dev/null +++ b/.githooks/post-checkout @@ -0,0 +1,4 @@ +#!/bin/sh + +git fetch +make setup diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg new file mode 100644 index 0000000..e8347f0 --- /dev/null +++ b/.githooks/prepare-commit-msg @@ -0,0 +1,28 @@ +#!/bin/sh + +# コミットメッセージは .git/COMMIT_EDITMSG に保存されてる +COMMIT_MSG_FILE_PATH="$1" + +# コミットメッセージ読み込み +COMMIT_MSG=$(cat "$COMMIT_MSG_FILE_PATH") + +# [Int値] の正規表現 +PATTERN="^\[\d+\]" + +# コミットメッセージの検証 +if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then + # \033[31m は赤文字にするANSIエスケープシーケンス + echo "\033[31mERROR: コミットメッセージは '[Issue番号]' で始めてください。" + echo "このままコミットを続けますか? (y/n)" + read answer + case $answer in + [Yy]* ) + ;; + * ) + echo "コミットを中止します。" + exit 1 + ;; + esac +fi + +exit 0 \ No newline at end of file