diff options
Diffstat (limited to 'git-check-commit-msg')
-rw-r--r-- | git-check-commit-msg/Makefile-files | 7 | ||||
-rw-r--r-- | git-check-commit-msg/commit-1 | 5 | ||||
-rw-r--r-- | git-check-commit-msg/commit-2 | 1 | ||||
-rw-r--r-- | git-check-commit-msg/commit-3 | 3 | ||||
-rwxr-xr-x | git-check-commit-msg/git-check-commit-msg | 20 | ||||
-rwxr-xr-x | git-check-commit-msg/run-tests.sh | 28 |
6 files changed, 64 insertions, 0 deletions
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 |