logo

utils

~/.local/bin tools and git-hooks
commit: d406abbb2014aa4aa342974d60325a5f0c5fcd1a
parent: 86ee0399782cf51a80344ed57412b553ff32335b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 15 Mar 2019 20:35:11 +0100

git-client-hooks/post-commit: Add hook

This client-side hook is present to warn on commits
that aren’t respecting the 50/72 ~rule

Diffstat:

Agit-client-hooks/post-commit22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/git-client-hooks/post-commit b/git-client-hooks/post-commit @@ -0,0 +1,22 @@ +#!/bin/sh +subject="$(git log --format='format:%s' -1 HEAD | wc -c)" +body_max="$(git log --format='format:%B' -1 HEAD | awk 'length>max{max=length}END{print max}')" +body_lines="$(git log --format='format:%B' -1 HEAD | wc -l)" + +if [ "$subject" -gt 50 ] +then + echo "Subject line is ${subject}, try to make it >= 50" +fi + +if [ "$body_max" -gt 72 ] +then + echo "Longest line in subject+body is ${subject}, try to make it >= 72" +fi + +if [ "$body_lines" -gt 1 ] +then + if [ -n "$(git log --format='format:%B' | head -2 | tail -1)" ] + then + echo "Second line isn’t empty yet there is a commit body" + fi +fi