#!/usr/bin/env perl ## commit-check --- Simple git commit style checker # Copyright (C) 2014 Tom Willemse # commit-check is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # commit-check is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with commit-ccheck. If not, see . use strict; use warnings; my $lineno = 0; my $status = 0; sub err { my ($msg) = @_; print STDERR "Error on line $lineno (actual line $.): ". $msg ."\n"; $status = 1; } open(my $commitfile, "<", $ARGV[0]) or die "Couldn't open $ARGV[0]"; while (<$commitfile>) { next if /^#/; # Discard comments next if $lineno == 0 && /^$/; # Discard leading empty lines $lineno++; # Start at 1, so increment first if ($lineno == 1) { err "Not capitalized" if /^[^[:upper:]]/; err "Longer than 50 characters" if /^.{51,}/; next; } err "Should be empty" if $lineno == 2 && /.+/; err "Longer than 72 characters" if /^.{73,}/; } close $commitfile; exit $status;