Skip to content

Commit

Permalink
[100] add githooks
Browse files Browse the repository at this point in the history
  • Loading branch information
akidon0000 committed Mar 19, 2024
1 parent 7b09ba8 commit 5825fc2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .githooks/README.md
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 4 additions & 0 deletions .githooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

git fetch
make setup
28 changes: 28 additions & 0 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5825fc2

Please sign in to comment.