Skip to content

Commit

Permalink
chore: update commit hook (#106)
Browse files Browse the repository at this point in the history
Make it compatible with the global hook
  • Loading branch information
1abhishekpandey authored Jan 22, 2025
1 parent aafd042 commit 0ee3217
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scripts/commit-msg
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/bin/bash

# check commit message
commit_message=$(cat $1)
# Path to the commit message file
commit_message_file=".git/COMMIT_EDITMSG"

# Read the commit message
commit_message=$(cat "$commit_message_file")

# Check if the commit message is empty
if [[ -z "$commit_message" || "$commit_message" =~ ^[[:space:]]*$ ]]; then
echo "Error: Commit message cannot be empty." >&2
exit 1
fi

echo "Checking commit message: $commit_message"
valid_commit_regex="^(feat|fix|refactor|perf|style|test|docs|chore|build|ci|revert)(\(.*\))?!?: .*$|^Merge .*"
message="There is something wrong with your commit message. Commit messages in this project must adhere to this contract: $valid_commit_regex. Your commit will be rejected. You should amend your commit message to a valid one and try again."
echo "Checking commit message: $commit_message"
if [[ ! $commit_message =~ $valid_commit_regex ]]
then
if [[ ! $commit_message =~ $valid_commit_regex ]]; then
echo "$message"
exit 1
fi

0 comments on commit 0ee3217

Please sign in to comment.