#!/bin/bash
# http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

case "${1}" in
    --about )
        echo "make sure commit message is within line width limits"
        ;;
    * )
        awk '
/^#/ {
    NR--
    next
}

NR == 1 {
    if (length > 50) {
        print "title too long"
        exit 1
    }
}

NR == 2 {
    if (length != 0) {
        print "2nd line should be empty"
        exit 2
    }
}

{
    if (length > 72) {
        print "line ", FNR, " is too long";
    }
}' "${1}"
esac
