From 020bf55772f8b8a482c62151b39de537d908c841 Mon Sep 17 00:00:00 2001 From: Kasper Date: Sun, 2 Nov 2025 22:02:32 +0100 Subject: [PATCH] fix: automated commit detection ref: N25B-241 --- .githooks/check-commit-msg.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.githooks/check-commit-msg.sh b/.githooks/check-commit-msg.sh index 82bd441..f87749a 100755 --- a/.githooks/check-commit-msg.sh +++ b/.githooks/check-commit-msg.sh @@ -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