Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 7dcf845

Browse files
shahinamgrasmash
authored andcommitted
Fixes #840: Git commit messages are not being validated. (#901)
1 parent 17f2c30 commit 7dcf845

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

scripts/git-hooks/commit-msg

+18-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
#
55
# You may adapt the message length check. Currently checking it's longer than
66
# 15 characters.
7-
ROOT_DIR="$(pwd)/"
8-
PREFIX=$($ROOT_DIR/vendor/bin/drupal yaml:get:value $ROOT_DIR/blt/project.yml project.prefix)
9-
regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\."
7+
8+
ROOT_DIR="$(pwd)"
9+
COMMAND="$ROOT_DIR/vendor/bin/drupal yaml:get:value $ROOT_DIR/blt/project.yml project.prefix"
10+
ERROR=$($COMMAND 2>&1 > /dev/null)
11+
PREFIX=$($COMMAND)
1012
RED='\033[0;31m'
1113
NO_COLOR='\033[0m'
14+
15+
# Make sure there are no errors while running drupal console command
16+
# todo: It would have be easy, just by discarding the std error, but for some
17+
# reason the error message is repeated on std out - which messes up everything.
18+
if [ -n "$ERROR" ]; then
19+
printf "${RED}Error: could not get project prefix!${NO_COLOR} Please check:\n"
20+
echo "* Project prefix is set properly in project.yml."
21+
echo "* Drupal console is configured properly, to configure run \"drupal init\"."
22+
exit 1;
23+
fi
24+
25+
# Validate the commit message.
26+
regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\."
1227
if ! grep -iqE "$regex" "$1"; then
1328
printf "${RED}Error: invalid commit message!${NO_COLOR} Commit messages must:\n"
1429
echo "* Contain the project prefix followed by a hyphen"
@@ -17,4 +32,3 @@ if ! grep -iqE "$regex" "$1"; then
1732
echo "Valid example: $PREFIX-135: Added the new picture field to the article feature."
1833
exit 1;
1934
fi
20-

0 commit comments

Comments
 (0)