From a4279c3b6bd18b2aaeb9359f91c4f207d6f3e425 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 5 Mar 2014 00:17:35 +0100 Subject: Initial commit --- commit-check | 30 ++++++++++++++++++++++++++++++ test-fail-barely.txt | 3 +++ test-fail-miserably.txt | 4 ++++ test-pass.txt | 5 +++++ 4 files changed, 42 insertions(+) create mode 100755 commit-check create mode 100644 test-fail-barely.txt create mode 100644 test-fail-miserably.txt create mode 100644 test-pass.txt diff --git a/commit-check b/commit-check new file mode 100755 index 0000000..6543633 --- /dev/null +++ b/commit-check @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +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; +} + +while (<>) { + 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 80 characters" if /^.{73,}/; +} + +exit $status; diff --git a/test-fail-barely.txt b/test-fail-barely.txt new file mode 100644 index 0000000..0c36c81 --- /dev/null +++ b/test-fail-barely.txt @@ -0,0 +1,3 @@ +This line is the commit subject, it be 50 char long + +This is a regular line. It really should be 72 characters long. Let's see diff --git a/test-fail-miserably.txt b/test-fail-miserably.txt new file mode 100644 index 0000000..4cd991c --- /dev/null +++ b/test-fail-miserably.txt @@ -0,0 +1,4 @@ +# This is a comment and should not be checked at all. It can be as long as it wants to be. +this, on the other hand, is not a comment. It is also the first line and should not be longer than 50 characters. +This line should be empty +This line is a regular text line. It should not be longer than 80 characters. We should check that. diff --git a/test-pass.txt b/test-pass.txt new file mode 100644 index 0000000..e41dfbb --- /dev/null +++ b/test-pass.txt @@ -0,0 +1,5 @@ +# Since this is a comment it really doesn't matter how long it is, so anything should be fine here. + +This line is the commit subject, it be 50 chr long + +This is a regular line. It really should be 72 characters long. Lets see -- cgit v1.2.3-54-g00ecf