summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--git-check-commit-msg/Makefile-files7
-rw-r--r--git-check-commit-msg/commit-15
-rw-r--r--git-check-commit-msg/commit-21
-rw-r--r--git-check-commit-msg/commit-33
-rwxr-xr-xgit-check-commit-msg/git-check-commit-msg20
-rwxr-xr-xgit-check-commit-msg/run-tests.sh28
7 files changed, 68 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 7487af9..97f94cd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,9 @@ check_SCRIPTS =
TESTS =
AM_INSTALLCHECK_STD_OPTIONS_EXEMPT =
+# For the test cases
+export top_srcdir
+
AM_CPPFLAGS = -I${top_builddir}/include
ACLOCAL_AMFLAGS = -I m4 --install
@@ -22,6 +25,7 @@ include git-ndim-sh/Makefile-files
include git-amb/Makefile-files
include git-buildmsg/Makefile-files
include git-rebase-subtree/Makefile-files
+include git-check-commit-msg/Makefile-files
if HAVE_NDIM_MAN2TXT
.man.txt:
diff --git a/git-check-commit-msg/Makefile-files b/git-check-commit-msg/Makefile-files
new file mode 100644
index 0000000..c0b0e01
--- /dev/null
+++ b/git-check-commit-msg/Makefile-files
@@ -0,0 +1,7 @@
+# -*- makefile -*-
+
+AM_INSTALLCHECK_STD_OPTIONS_EXEMPT += git-check-commit-msg
+bin_SCRIPTS += git-check-commit-msg/git-check-commit-msg
+EXTRA_DIST += git-check-commit-msg/git-check-commit-msg
+
+TESTS += git-check-commit-msg/run-tests.sh
diff --git a/git-check-commit-msg/commit-1 b/git-check-commit-msg/commit-1
new file mode 100644
index 0000000..043a3ec
--- /dev/null
+++ b/git-check-commit-msg/commit-1
@@ -0,0 +1,5 @@
+First line first line first line first line first
+
+This is a perfect comment. This is a perfect comment. This is a
+perfect comment. This is a perfect comment. This is a perfect
+comment. This is a perfect comment. This is a perfect comment.
diff --git a/git-check-commit-msg/commit-2 b/git-check-commit-msg/commit-2
new file mode 100644
index 0000000..49678a1
--- /dev/null
+++ b/git-check-commit-msg/commit-2
@@ -0,0 +1 @@
+This 1st line is just one lousy character too long!
diff --git a/git-check-commit-msg/commit-3 b/git-check-commit-msg/commit-3
new file mode 100644
index 0000000..ab98cac
--- /dev/null
+++ b/git-check-commit-msg/commit-3
@@ -0,0 +1,3 @@
+Moo
+# Foo
+# Bar
diff --git a/git-check-commit-msg/git-check-commit-msg b/git-check-commit-msg/git-check-commit-msg
new file mode 100755
index 0000000..4ef9e9a
--- /dev/null
+++ b/git-check-commit-msg/git-check-commit-msg
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+msgfile="$1"
+test -s "$msgfile" || {
+ echo >&2 "Commit message must not be empty"
+ exit 1
+}
+
+# Check first line is <= 50 chars, and followed by empty line
+test "x$(sed -n '1s/^.\{,50\}//p' "$msgfile")" = "x" || {
+ echo >&2 "First line is too long. It should be <= 50 characters."
+ echo >&2 "These characters fit: $(sed -n '1s/^\(.\{,50\}\)\(.*\)$/\1/p' "$1")"
+ echo >&2 "These exceed the limit: $(sed -n '1s/^\(.\{,50\}\)\(.*\)$/\2/p' "$1")"
+ exit 1
+}
+test "x$(sed -n 's/^#.*//; 2p' "$msgfile")" = "x" || {
+ echo >&2 "Second line should be empty."
+ exit 1
+}
+
diff --git a/git-check-commit-msg/run-tests.sh b/git-check-commit-msg/run-tests.sh
new file mode 100755
index 0000000..d3da61c
--- /dev/null
+++ b/git-check-commit-msg/run-tests.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+tcdir="${top_srcdir-.}"
+script="${top_srcdir-.}/git-check-commit-msg/git-check-commit-msg"
+
+errors=0
+
+while read tc expect restofline
+do
+ tcfile="${tcdir}/git-check-commit-msg/${tc}"
+ test -s "$tcfile" || continue
+
+ "$script" "$tcfile"; s="$?"
+
+ if [ "$s" -eq 0 ] && [ "x$expect" = "xOK" ]; then :;
+ elif [ "$s" -ne 0 ] && [ "x$expect" = "xFAIL" ]; then :;
+ else
+ sh -x "$script" "$tcfile"
+ echo "TC: $tc expected $expect, but deviates."
+ errors="$(expr $errors + 1)"
+ fi
+done<<EOF
+commit-1 OK
+commit-2 FAIL
+commit-3 OK
+EOF
+
+[ "$errors" -ne 0 ] && exit 1