Skip to content

Commit 2911c04

Browse files
Merge pull request #76 from rust-practice/conventional-commits-hook
chore: add scripts to help setup recommended hooks
2 parents 6c7c89c + ecf5378 commit 2911c04

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

scripts/commit-msg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
regex="^(feat|fix|build|chore|ci|docs|style|refactor|perf|test)(\[.+\])?: .+"
4+
5+
grep -E "$regex" "$1"
6+
if [ $? != 0 ]
7+
then
8+
echo "[error] Commit message doesn't appear to in the conventional commit format"
9+
echo "[info] expecting \"<type>[optional scope]: <description>\""
10+
echo "[info] see https://www.conventionalcommits.org/en/v1.0.0/#summary for more info"
11+
echo "[debug] using regex: \"$regex\""
12+
echo "[debug] on commit message:"
13+
cat "$1"
14+
exit 1
15+
fi

scripts/hooks_setup.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
@REM Expected to be run from the scripts folder
3+
4+
copy commit-msg ..\.git\hooks\
5+
6+
if %ERRORLEVEL% NEQ 0 echo [error] The copy seems to have failed. This script expects to be run from inside the scripts folder

scripts/hooks_setup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Expected to be run from the scripts folder
4+
5+
cp commit-msg ../.git/hooks/
6+
7+
if [ $? != 0 ]
8+
then
9+
echo "[error] The copy seems to have failed. This script expects to be run from inside the scripts folder"
10+
exit 1
11+
fi

0 commit comments

Comments
 (0)