fix: automated commit detection

ref: N25B-241
This commit is contained in:
2025-11-02 22:02:32 +01:00
parent c6edad0bb4
commit 020bf55772

View File

@@ -23,6 +23,37 @@ NC='\033[0m' # No Color
# The first argument to the hook is the path to the file containing the commit message
COMMIT_MSG_FILE=$1
# --- Automated Commit Detection ---
# Git directory (.git/)
GIT_DIR=$(git rev-parse --git-dir)
# Check for a merge commit
if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
echo "Hook: Detected a merge commit."
# Ensure the message follows a 'Merge branch...' pattern.
first_line=$(head -n1 "$COMMIT_MSG_FILE")
if [[ ! "$first_line" =~ ^Merge.* ]]; then
echo "Error: Merge commit message should start with 'Merge'." >&2
exit 1
fi
exit 0
# Check for a squash commit (from git merge --squash)
elif [ -f "$GIT_DIR/SQUASH_MSG" ]; then
echo "Hook: Detected a squash commit. Skipping validation."
exit 0
# Check for a revert commit
elif [ -f "$GIT_DIR/REVERT_HEAD" ]; then
echo "Hook: Detected a revert commit. Skipping validation."
exit 0
# Check for a cherry-pick commit
elif [ -f "$GIT_DIR/CHERRY_PICK_HEAD" ]; then
echo "Hook: Detected a cherry-pick commit. Skipping validation."
exit 0
fi
# --- Validation Functions ---
# Function to print an error message and exit