Skip to content

Commit

Permalink
Merge pull request #76 from rust-practice/conventional-commits-hook
Browse files Browse the repository at this point in the history
chore: add scripts to help setup recommended hooks
  • Loading branch information
pawarherschel authored Feb 2, 2024
2 parents 6c7c89c + ecf5378 commit 2911c04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

regex="^(feat|fix|build|chore|ci|docs|style|refactor|perf|test)(\[.+\])?: .+"

grep -E "$regex" "$1"
if [ $? != 0 ]
then
echo "[error] Commit message doesn't appear to in the conventional commit format"
echo "[info] expecting \"<type>[optional scope]: <description>\""
echo "[info] see https://www.conventionalcommits.org/en/v1.0.0/#summary for more info"
echo "[debug] using regex: \"$regex\""
echo "[debug] on commit message:"
cat "$1"
exit 1
fi
6 changes: 6 additions & 0 deletions scripts/hooks_setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
@REM Expected to be run from the scripts folder

copy commit-msg ..\.git\hooks\

if %ERRORLEVEL% NEQ 0 echo [error] The copy seems to have failed. This script expects to be run from inside the scripts folder
11 changes: 11 additions & 0 deletions scripts/hooks_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

# Expected to be run from the scripts folder

cp commit-msg ../.git/hooks/

if [ $? != 0 ]
then
echo "[error] The copy seems to have failed. This script expects to be run from inside the scripts folder"
exit 1
fi

0 comments on commit 2911c04

Please sign in to comment.