Skip to content

Commit

Permalink
Add git commit message hook to the mystools bundle (#1067)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fallberg authored and bblacey committed Mar 6, 2018
1 parent eb83946 commit 3f2d292
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .mystools/hooks/commit-msg.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f2d292

Please sign in to comment.