From 6b3e748c7b73861c905f697429e4dd4ac6b299ff Mon Sep 17 00:00:00 2001 From: Muhammad Inam Ur Rasheed Date: Tue, 3 Jan 2017 14:29:29 +0530 Subject: [PATCH] Fixes #840: Git commit messages are not being validated. --- scripts/git-hooks/commit-msg | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/git-hooks/commit-msg b/scripts/git-hooks/commit-msg index 21db79017..9624124d7 100755 --- a/scripts/git-hooks/commit-msg +++ b/scripts/git-hooks/commit-msg @@ -4,11 +4,26 @@ # # You may adapt the message length check. Currently checking it's longer than # 15 characters. -ROOT_DIR="$(pwd)/" -PREFIX=$($ROOT_DIR/vendor/bin/drupal yaml:get:value $ROOT_DIR/blt/project.yml project.prefix) -regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\." + +ROOT_DIR="$(pwd)" +COMMAND="$ROOT_DIR/vendor/bin/drupal yaml:get:value $ROOT_DIR/blt/project.yml project.prefix" +ERROR=$($COMMAND 2>&1 > /dev/null) +PREFIX=$($COMMAND) RED='\033[0;31m' NO_COLOR='\033[0m' + +# Make sure there are no errors while running drupal console command +# todo: It would have be easy, just by discarding the std error, but for some +# reason the error message is repeated on std out - which messes up everything. +if [ -n "$ERROR" ]; then + printf "${RED}Error: could not get project prefix!${NO_COLOR} Please check:\n" + echo "* Project prefix is set properly in project.yml." + echo "* Drupal console is configured properly, to configure run \"drupal init\"." + exit 1; +fi + +# Validate the commit message. +regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\." if ! grep -iqE "$regex" "$1"; then printf "${RED}Error: invalid commit message!${NO_COLOR} Commit messages must:\n" echo "* Contain the project prefix followed by a hyphen" @@ -17,4 +32,3 @@ if ! grep -iqE "$regex" "$1"; then echo "Valid example: $PREFIX-135: Added the new picture field to the article feature." exit 1; fi -