From 3f2d2921428ef2a4cdfe94217d7fad7e04928fce Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Tue, 6 Mar 2018 17:32:54 +0100 Subject: [PATCH] Add git commit message hook to the mystools bundle (#1067) The message hook validates that the c ommit message follows the MySensors requirements. More specifically, it checks that - Commit message does not exceed a line length of 72 characters - Commit title start with an uppercase character - Commit title does not end with a period ('.') Fixes #672 --- .mystools/hooks/commit-msg.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .mystools/hooks/commit-msg.sh diff --git a/.mystools/hooks/commit-msg.sh b/.mystools/hooks/commit-msg.sh new file mode 100644 index 0000000..4b5f780 --- /dev/null +++ b/.mystools/hooks/commit-msg.sh @@ -0,0 +1,23 @@ +#!/bin/bash +too_long_lines=$(awk 'length>72' $1) +if [[ ! -z $too_long_lines ]]; then + echo "Too long commit message lines:" $too_long_lines + has_failed=1 +fi + +leading_lowercases=$(awk 'NR==1' $1 | awk '/^[[:lower:][:punct:]]/') +if [[ ! -z $leading_lowercases ]]; then + echo "Leading lowercase in subject:" $leading_lowercases + has_failed=1 +fi + +trailing_periods=$(awk 'NR==1' $1 | awk '/(\.)$/') +if [[ ! -z $trailing_periods ]]; then + echo "Trailing periods in subject:" $trailing_periods + has_failed=1 +fi + +if [[ ! -z $has_failed ]]; then + echo "Please recommit with a new commit message." + exit 1 +fi