aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-03-05 00:17:35 +0100
committerGravatar Tom Willemse2014-03-05 00:17:35 +0100
commita4279c3b6bd18b2aaeb9359f91c4f207d6f3e425 (patch)
treedbb22da4a638bddc7735d943a845e1916d5bab93
downloadcommit-check-a4279c3b6bd18b2aaeb9359f91c4f207d6f3e425.tar.gz
commit-check-a4279c3b6bd18b2aaeb9359f91c4f207d6f3e425.zip
Initial commit
-rwxr-xr-xcommit-check30
-rw-r--r--test-fail-barely.txt3
-rw-r--r--test-fail-miserably.txt4
-rw-r--r--test-pass.txt5
4 files changed, 42 insertions, 0 deletions
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