aboutsummaryrefslogtreecommitdiffstats
path: root/git-tools/hooks/commit-msg
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-11-06 11:11:27 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-11-06 11:11:27 -0500
commit87ea50948ea53c0d1beab5b44badebeae4292d1a (patch)
treedbc99fde4dfc62b84bae60c7e4ab5c02ddbe8a3c /git-tools/hooks/commit-msg
parent5b48df41685da785b082612318ebe7a8012c4149 (diff)
parent44ff9d020fd218cbdb2f07a0d7f85a630367e3c2 (diff)
downloadforums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.gz
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.bz2
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.tar.xz
forums-87ea50948ea53c0d1beab5b44badebeae4292d1a.zip
Merge remote-tracking branch 'upstream/develop' into feature/prune-users
* upstream/develop: (2171 commits) [ticket/11164] Update composer.phar [ticket/10933] Use inheritDoc, eliminate copy pasted docblocks. [ticket/10933] Dependency inject template context. [ticket/10933] Expanded prose documentation for phpbb_extension_provider. [ticket/10933] Specify empty template path for absolute includephp test. [ticket/10933] Useful documentation for template locate function [ticket/10933] Typo fixes [ticket/10933] Initialize template context when template is constructed. [ticket/11099] Mark acp_ban::display_ban_options() as static. [ticket/11158] Require acl_u_sig for ucp signature module. [ticket/11158] Revert old fix in PHPBB3-10186. [ticket/11159] static public is the currently approved order. [ticket/11157] static public is the currently approved order. [ticket/11157] Fix remaining captcha spam. [ticket/11157] get_captcha_types is an instance method. [ticket/11156] Delete "Misc" tab of forum based permissions + move items [ticket/10848] Move include up. [ticket/11014] Fix old pagination assignment [ticket/11018] Fix several paginations in ACP [ticket/11014] Fix IF statements for new template pagination ... Conflicts: phpBB/includes/functions_user.php
Diffstat (limited to 'git-tools/hooks/commit-msg')
-rwxr-xr-xgit-tools/hooks/commit-msg114
1 files changed, 92 insertions, 22 deletions
diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg
index 4f6ae71d4b..b156d276df 100755
--- a/git-tools/hooks/commit-msg
+++ b/git-tools/hooks/commit-msg
@@ -11,14 +11,30 @@
#
# ln -s ../../git-tools/hooks/commit-msg \\
# .git/hooks/commit-msg
+#
+# You can configure whether invalid commit messages abort commits:
+#
+# git config phpbb.hooks.commit-msg.fatal true (abort)
+# git config phpbb.hooks.commit-msg.fatal false (warn only, do not abort)
+#
+# The default is to warn only.
+#
+# Warning/error messages use color by default if the output is a terminal
+# ("output" here is normally standard error when you run git commit).
+# To force or disable the use of color:
+#
+# git config phpbb.hooks.commit-msg.color true (force color output)
+# git config phpbb.hooks.commit-msg.color false (disable color output)
config_ns="phpbb.hooks.commit-msg";
-if [ "$(git config --bool $config_ns.fatal)" = "false" ]
+if [ "$(git config --bool $config_ns.fatal)" = "true" ]
then
- fatal=0;
-else
fatal=1;
+ severity=Error;
+else
+ fatal=0;
+ severity=Warning;
fi
debug_level=$(git config --int $config_ns.debug || echo 0);
@@ -47,14 +63,68 @@ debug()
quit()
{
- if [ $1 -gt 0 ] && [ $1 -ne $ERR_UNKNOWN ] && [ $fatal -eq 0 ]
+ if [ $1 -eq 0 ] || [ $1 -eq $ERR_UNKNOWN ]
+ then
+ # success
+ exit 0;
+ elif [ $fatal -eq 0 ]
then
+ # problems found but fatal is false
+ complain 'Please run `git commit --amend` and fix the problems mentioned.' 1>&2
exit 0;
else
+ complain "Aborting commit." 1>&2
exit $1;
fi
}
+use_color()
+{
+ if [ -z "$use_color_cached" ]
+ then
+ case $(git config --bool $config_ns.color)
+ in
+ false)
+ use_color_cached=1
+ ;;
+ true)
+ use_color_cached=0
+ ;;
+ *)
+ # tty detection in shell:
+ # http://hwi.ath.cx/jsh/list/shext/isatty.sh.html
+ tty 0>/dev/stdout >/dev/null 2>&1
+ use_color_cached=$?
+ ;;
+ esac
+ fi
+ # return value is the flag inverted -
+ # if return value is 0, this means use color
+ return $use_color_cached
+}
+
+complain()
+{
+ if use_color
+ then
+ # Careful: our argument may include arguments to echo like -n
+ # ANSI color codes:
+ # http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html
+ printf "\033[31m\033[1m"
+ if [ "$1" = "-n" ]
+ then
+ echo "$@"
+ printf "\033[0m"
+ else
+ # This will print one trailing space.
+ # Not sure how to avoid this at the moment.
+ echo "$@" $(printf "\033[0m")
+ fi
+ else
+ echo "$@"
+ fi
+}
+
# Check for empty commit message
if ! grep -qv '^#' "$1"
then
@@ -70,9 +140,9 @@ msg=$(grep -v '^#' "$1" |grep -nE '.{81,}')
if [ $? -eq 0 ]
then
- echo "The following lines are greater than 80 characters long:" >&2;
- echo >&2
- echo "$msg" >&2;
+ complain "The following lines are greater than 80 characters long:" >&2;
+ complain >&2
+ complain "$msg" >&2;
quit $ERR_LENGTH;
fi
@@ -126,9 +196,9 @@ do
# Don't be too strict.
# Commits may be temporary, intended to be squashed later.
# Just issue a warning here.
- echo "Warning: heading should be a sentence beginning with a capital letter." 1>&2
- echo "You entered:" 1>&2
- echo "$line" 1>&2
+ complain "$severity: heading should be a sentence beginning with a capital letter." 1>&2
+ complain "You entered:" 1>&2
+ complain "$line" 1>&2
fi
# restore exit code
(exit $result)
@@ -160,7 +230,7 @@ do
echo "$line" | grep -Eq "^#";
;;
*)
- echo "Unrecognised token $expect" >&2;
+ complain "Unrecognised token $expect" >&2;
quit $err;
;;
esac
@@ -231,7 +301,7 @@ do
expecting="eof";
;;
*)
- echo "Unrecognised token $expect" >&2;
+ complain "Unrecognised token $expect" >&2;
quit 254;
;;
esac
@@ -245,11 +315,11 @@ do
else
# None of the expected line formats matched
# Guess we'll call it a day here then
- echo "Syntax error on line $i:" >&2;
- echo ">> $line" >&2;
- echo -n "Expecting: " >&2;
- echo "$expecting" | sed 's/ /, /g' >&2;
- exit $err;
+ complain "Syntax error on line $i:" >&2;
+ complain ">> $line" >&2;
+ complain -n "Expecting: " >&2;
+ complain "$expecting" | sed 's/ /, /g' >&2;
+ quit $err;
fi
i=$(( $i + 1 ));
@@ -258,7 +328,7 @@ done
# If EOF is expected exit cleanly
echo "$expecting" | grep -q "eof" || (
# Unexpected EOF, error
- echo "Unexpected EOF encountered" >&2;
+ complain "Unexpected EOF encountered" >&2;
quit $ERR_EOF;
) && (
# Do post scan checks
@@ -269,8 +339,8 @@ echo "$expecting" | grep -q "eof" || (
if [ ! -z "$dupes" ]
then
- echo "The following tickets are repeated:" >&2;
- echo "$dupes" | sed 's/ /\n/g;s/^/* /g' >&2;
+ complain "The following tickets are repeated:" >&2;
+ complain "$dupes" | sed 's/ /\n/g;s/^/* /g' >&2;
quit $ERR_FOOTER;
fi
fi
@@ -278,8 +348,8 @@ echo "$expecting" | grep -q "eof" || (
if [ $ticket -gt 0 ]
then
echo "$tickets" | grep -Eq "\bPHPBB3-$ticket\b" || (
- echo "Ticket ID [$ticket] of branch missing from list of tickets:" >&2;
- echo "$tickets" | sed 's/ /\n/g;s/^/* /g' >&2;
+ complain "Ticket ID [$ticket] of branch missing from list of tickets:" >&2;
+ complain "$tickets" | sed 's/ /\n/g;s/^/* /g' >&2;
quit $ERR_FOOTER;
) || exit $?;
fi