git - Check length of commit message -


i have git hook should prevent commit messages have more 72 characters:

#!/usr/bin/env bash  # hook make sure no commit message line exceeds 72 characters  while read line;     if [ ${#line} -ge 72 ];         echo "commit messages limited 72 characters."         echo "the following commit message has ${#line} characters."         echo "${line}"         exit 1     fi done < "${1}"  exit 0 

this working fine until now. tried rebase commit , change commit message, , git rightfully tell me:

commit messages limited 72 characters. following commit message has 81 characters. # editing commit while rebasing branch 'master' on '984734a'. not amend commit after picking 19b8030dc0ad2fc8186df5159b91e0efe862b981... fill susy decay dictionary on fly when needed due empty commit message, or pre-commit hook failed. if pre-commit hook failed, may need resolve issue before able reword commit. 

the method use not smart. how properly?

simply skipping comments (lines starting # did trick):

#!/usr/bin/env bash  # hook make sure no commit message line exceeds 72 characters  while read line;     # skip comments     if [ "${line:0:1}" == "#" ];         continue     fi     if [ ${#line} -ge 72 ];         echo "commit messages limited 72 characters."         echo "the following commit message has ${#line} characters."         echo "${line}"         exit 1     fi done < "${1}"  exit 0 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -