Automated commit detection #20
@@ -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
|
# The first argument to the hook is the path to the file containing the commit message
|
||||||
COMMIT_MSG_FILE=$1
|
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 ---
|
# --- Validation Functions ---
|
||||||
|
|
||||||
# Function to print an error message and exit
|
# Function to print an error message and exit
|
||||||
|
|||||||
Reference in New Issue
Block a user