I wrote a commit-msg hook to prevent commits with empty messages by checking to see if COMMIT_EDITMSG is empty, and if so, then to exit process :
#!/bin/sh
# .git/hooks/commit-msg
# Read COMMIT_EDITMSG file
COMMIT_MSG_FILE=$(cat $1)
# No empty commit message rule
if [$COMMIT_MSG_FILE == '']
then
echo "Must have a commit message"
exit 1
fi
It is working as expected except when I make a commit with text in it terminal interprets the first string in the commit message as a command. Say for example if i do git commit -m "commit 1"
, shell interprets "commit" as a command. The commit still goes through but does anyone know why this is happening and how I can prevent this?