From 0cb83f99abd67c33fecc511b2e7ac6a49acf058d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 26 Nov 2011 17:32:40 -0500 Subject: [ticket/10093] Document phpbb.hooks.commit-msg.fatal setting. PHPBB3-10093 --- git-tools/hooks/commit-msg | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 4f6ae71d4b..03a602c16c 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -11,6 +11,11 @@ # # 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, this is the default) +# git config phpbb.hooks.commit-msg.fatal false (warn only, do not abort) config_ns="phpbb.hooks.commit-msg"; -- cgit v1.2.1 From 26d01d4408a25d70e2bbe32992a1c348ddefff04 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 26 Nov 2011 17:35:10 -0500 Subject: [ticket/10093] Respect phpbb.hooks.commit-msg.fatal on syntax errors. PHPBB3-10093 --- git-tools/hooks/commit-msg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 03a602c16c..39d5bb3350 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -254,7 +254,7 @@ do echo ">> $line" >&2; echo -n "Expecting: " >&2; echo "$expecting" | sed 's/ /, /g' >&2; - exit $err; + quit $err; fi i=$(( $i + 1 )); -- cgit v1.2.1 From 6a3ee0996e1b4faf765d72e7249f505fafd5812d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 26 Nov 2011 17:41:25 -0500 Subject: [ticket/10093] Refactor complaining in commit-msg hook for color support. PHPBB3-10093 --- git-tools/hooks/commit-msg | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 39d5bb3350..5c51127dcc 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -60,6 +60,11 @@ quit() fi } +complain() +{ + echo "$@" +} + # Check for empty commit message if ! grep -qv '^#' "$1" then @@ -75,9 +80,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 @@ -131,9 +136,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 "Warning: 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) @@ -165,7 +170,7 @@ do echo "$line" | grep -Eq "^#"; ;; *) - echo "Unrecognised token $expect" >&2; + complain "Unrecognised token $expect" >&2; quit $err; ;; esac @@ -236,7 +241,7 @@ do expecting="eof"; ;; *) - echo "Unrecognised token $expect" >&2; + complain "Unrecognised token $expect" >&2; quit 254; ;; esac @@ -250,10 +255,10 @@ 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; + complain "Syntax error on line $i:" >&2; + complain ">> $line" >&2; + complain -n "Expecting: " >&2; + complain "$expecting" | sed 's/ /, /g' >&2; quit $err; fi @@ -263,7 +268,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 @@ -274,8 +279,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 @@ -283,8 +288,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 -- cgit v1.2.1 From 92cdf08d48cba4eac30708ab089aae917db13970 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 26 Nov 2011 18:04:03 -0500 Subject: [ticket/10093] Use color in commit-msg hook warning/error messages. By default color is used if the message is printed to a tty, phpbb.hooks.commit-msg.color configuration setting can override this. PHPBB3-10093 --- git-tools/hooks/commit-msg | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 5c51127dcc..959c4e3979 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -16,6 +16,13 @@ # # git config phpbb.hooks.commit-msg.fatal true (abort, this is the default) # git config phpbb.hooks.commit-msg.fatal false (warn only, do not abort) +# +# 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"; @@ -60,9 +67,51 @@ quit() 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() { - echo "$@" + 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[10m" + else + # This will print one trailing space. + # Not sure how to avoid this at the moment. + echo "$@" $(printf "\033[10m") + fi + else + echo "$@" + fi } # Check for empty commit message -- cgit v1.2.1 From 88cad5523e7cdac6826dd8581e27e22a65afda26 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 3 Dec 2011 16:40:05 -0500 Subject: [ticket/10093] Make commit-msg always not fatal by nuking all fatal logic. PHPBB3-10093 --- git-tools/hooks/commit-msg | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 959c4e3979..e5a4c5e60b 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -12,11 +12,6 @@ # 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, this is the default) -# git config phpbb.hooks.commit-msg.fatal false (warn only, do not abort) -# # 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: @@ -26,13 +21,6 @@ config_ns="phpbb.hooks.commit-msg"; -if [ "$(git config --bool $config_ns.fatal)" = "false" ] -then - fatal=0; -else - fatal=1; -fi - debug_level=$(git config --int $config_ns.debug || echo 0); # Error codes @@ -59,12 +47,9 @@ debug() quit() { - if [ $1 -gt 0 ] && [ $1 -ne $ERR_UNKNOWN ] && [ $fatal -eq 0 ] - then - exit 0; - else - exit $1; - fi + # Now we always exit with success, since git will trash + # entered commit message if commit-msg hook exits with a failure. + exit 0 } use_color() -- cgit v1.2.1 From 8e59699424f4870e4ad77542b0e37eca696a18a3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 3 Dec 2011 16:42:04 -0500 Subject: [ticket/10093] Use correct ANSI code for clearing color. PHPBB3-10093 --- git-tools/hooks/commit-msg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index e5a4c5e60b..52969670ca 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -88,11 +88,11 @@ complain() if [ "$1" = "-n" ] then echo "$@" - printf "\033[10m" + printf "\033[0m" else # This will print one trailing space. # Not sure how to avoid this at the moment. - echo "$@" $(printf "\033[10m") + echo "$@" $(printf "\033[0m") fi else echo "$@" -- cgit v1.2.1 From 5e52734c240e5ecfb812202cd4cae305be9290c5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 2 Jan 2012 15:09:38 +0000 Subject: [ticket/9916] Changing header in non-distributed files PHPBB3-9916 --- git-tools/merge.php | 2 +- git-tools/setup_github_network.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/merge.php b/git-tools/merge.php index cbd84b896f..034bd2032c 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -4,7 +4,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index e4e212eef6..5f2e1609a7 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -4,7 +4,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From 57209a1e680da729cad0a1cd7e9462254edcd6cb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 3 Apr 2012 23:05:15 -0400 Subject: [ticket/10760] Use externally specified PHP_BIN if any. We have a PHP_BIN variable but we always set it unconditionally, therefore in order to use a different php binary one had to modify the hook script. Instead set PHP_BIN if it is not set. Now one can set PHP_BIN in their environment to use a non-default php binary. PHPBB3-10760 --- git-tools/hooks/pre-commit | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 4d03359773..a8bb12e96e 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -12,8 +12,10 @@ # ln -s ../../git-tools/hooks/pre-commit \\ # .git/hooks/pre-commit -# NOTE: this is run through /usr/bin/env -PHP_BIN=php +if [ -z "$PHP_BIN" ] +then + PHP_BIN=php +fi # necessary check for initial commit if git rev-parse --verify HEAD >/dev/null 2>&1 @@ -64,7 +66,7 @@ do # check the staged file content for syntax errors # using php -l (lint) - result=$(git cat-file -p $sha | /usr/bin/env $PHP_BIN -l 2>/dev/null) + result=$(git cat-file -p $sha | $PHP_BIN -l 2>/dev/null) if [ $? -ne 0 ] then error=1 -- cgit v1.2.1 From 786fcbf212caf4c201d9abba36fca3b8f58617a9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 3 Apr 2012 23:06:50 -0400 Subject: [ticket/10760] Use echo -e only if echo understands -e. /bin/echo on freebsd and dash's builtin echo do not understand -e, therefore -e is printed with the other messages in such cases. Test if echo understands -e, if not do not use it. PHPBB3-10760 --- git-tools/hooks/pre-commit | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index a8bb12e96e..0e230d3308 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -17,6 +17,13 @@ then PHP_BIN=php fi +if [ $(echo -e test) = test ] +then + echo_e="echo -e" +else + echo_e="echo" +fi + # necessary check for initial commit if git rev-parse --verify HEAD >/dev/null 2>&1 then @@ -78,7 +85,7 @@ unset IFS if [ $error -eq 1 ] then - echo -e "PHP Syntax check failed:"; - echo -e "$errors" | grep "^Parse error:" + echo "PHP Syntax check failed:" + $echo_e "$errors" | grep "^Parse error:" exit 1 fi -- cgit v1.2.1 From b803fc4351431bc53ee3221fa6232664134aa0ba Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 3 Apr 2012 23:14:44 -0400 Subject: [ticket/10760] Quote PHP_BIN when using it. This should make a difference on windows where paths may include spaces. PHPBB3-10760 --- git-tools/hooks/pre-commit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 0e230d3308..5be33fb9a1 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -36,7 +36,7 @@ fi error=0 errors="" -if ! which $PHP_BIN >/dev/null 2>&1 +if ! which "$PHP_BIN" >/dev/null 2>&1 then echo "PHP Syntax check failed:" echo "PHP binary does not exist or is not in path: $PHP_BIN" @@ -73,7 +73,7 @@ do # check the staged file content for syntax errors # using php -l (lint) - result=$(git cat-file -p $sha | $PHP_BIN -l 2>/dev/null) + result=$(git cat-file -p $sha | "$PHP_BIN" -l 2>/dev/null) if [ $? -ne 0 ] then error=1 -- cgit v1.2.1 From a0da2408e7cb0054da5d766bffa91f23d7beaec9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 3 Apr 2012 23:18:33 -0400 Subject: [ticket/10760] Account for display_errors=stderr in pre-commit hook. With that php.ini value set errors are printed to stderr, therefore by redirecting stderr to /dev/null we also throw out the errors. Instead merge stderr into stdout. PHPBB3-10760 --- git-tools/hooks/pre-commit | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 5be33fb9a1..a0c2b6b247 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -73,7 +73,13 @@ do # check the staged file content for syntax errors # using php -l (lint) - result=$(git cat-file -p $sha | "$PHP_BIN" -l 2>/dev/null) + # note: if display_errors=stderr in php.ini, + # parse errors are printed on stderr; otherwise + # they are printed on stdout. + # we filter everything other than parse errors + # with a grep below, therefore it should be safe + # to combine stdout and stderr in all circumstances + result=$(git cat-file -p $sha | "$PHP_BIN" -l 2>&1) if [ $? -ne 0 ] then error=1 -- cgit v1.2.1 From f2967b666974c6622717a064060e546129e11e37 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 4 Apr 2012 00:01:08 -0400 Subject: [ticket/10760] Catch both versions of parse error output in php. PHPBB3-10760 --- git-tools/hooks/pre-commit | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index a0c2b6b247..bb667bf8ff 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -92,6 +92,20 @@ unset IFS if [ $error -eq 1 ] then echo "PHP Syntax check failed:" + # php "display errors" (display_errors php.ini value) + # and "log errors" (log_errors php.ini value). + # these are independent settings - see main/main.c in php source. + # the "log errors" setting produces output which + # starts with "PHP Parse error:"; the "display errors" + # setting produces output starting with "Parse error:". + # if both are turned on php dumps the parse error twice. + # therefore here we try to grep for one version and + # if that yields no results grep for the other version. $echo_e "$errors" | grep "^Parse error:" + if [ $? -ne 0 ] + then + # match failed + $echo_e "$errors" | grep "^PHP Parse error:" + fi exit 1 fi -- cgit v1.2.1 From 6536a36208b3a2ecebaf5ab8e93f63b84127ae3f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 4 Apr 2012 00:27:06 -0400 Subject: [ticket/10760] PHP is great. This commit is the proof. PHPBB3-10760 --- git-tools/hooks/pre-commit | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index bb667bf8ff..9e78edd90d 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -101,6 +101,30 @@ then # if both are turned on php dumps the parse error twice. # therefore here we try to grep for one version and # if that yields no results grep for the other version. + # + # other fun php facts: + # + # 1. in cli, display_errors and log_errors have different + # destinations by default. display_errors prints to + # standard output and log_errors prints to standard error. + # whether these destinations make sense is left + # as an exercise for the reader. + # 2. as mentioned above, with all output turned on + # php will print parse errors twice, one time on stdout + # and one time on stderr. + # 2. it is possible to set both display_errors and log_errors + # to off. if this is done php will print the text + # "Errors parsing " but will not say what + # the errors are. useful behavior, this. + # 3. on my system display_errors defaults to on and + # log_errors defaults to off, therefore providing + # by default one copy of messages. your mileage may vary. + # 4. by setting display_errors=stderr and log_errors=on, + # both sets of messages will be printed on stderr. + # 5. php-cgi binary, given display_errors=stderr and + # log_errors=on, still prints both sets of messages + # on stderr, but formats one set as an html fragment. + # 6. your entry here? ;) $echo_e "$errors" | grep "^Parse error:" if [ $? -ne 0 ] then -- cgit v1.2.1 From efdd1e623e2dc060ae9b524b67c624037d8a94f0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 4 Apr 2012 11:41:14 -0400 Subject: [ticket/10760] Value must be quoted as it might be two words. PHPBB3-10760 --- git-tools/hooks/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 9e78edd90d..ecc3a35ba3 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -17,7 +17,7 @@ then PHP_BIN=php fi -if [ $(echo -e test) = test ] +if [ "$(echo -e test)" = test ] then echo_e="echo -e" else -- cgit v1.2.1 From dc63db1860e597b1201994a17fd7679bfdc9b0d8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 4 Apr 2012 11:43:59 -0400 Subject: [ticket/10760] Fix numbering in php fun facts. PHPBB3-10760 --- git-tools/hooks/pre-commit | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index ecc3a35ba3..03babe47cd 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -112,19 +112,19 @@ then # 2. as mentioned above, with all output turned on # php will print parse errors twice, one time on stdout # and one time on stderr. - # 2. it is possible to set both display_errors and log_errors + # 3. it is possible to set both display_errors and log_errors # to off. if this is done php will print the text # "Errors parsing " but will not say what # the errors are. useful behavior, this. - # 3. on my system display_errors defaults to on and + # 4. on my system display_errors defaults to on and # log_errors defaults to off, therefore providing # by default one copy of messages. your mileage may vary. - # 4. by setting display_errors=stderr and log_errors=on, + # 5. by setting display_errors=stderr and log_errors=on, # both sets of messages will be printed on stderr. - # 5. php-cgi binary, given display_errors=stderr and + # 6. php-cgi binary, given display_errors=stderr and # log_errors=on, still prints both sets of messages # on stderr, but formats one set as an html fragment. - # 6. your entry here? ;) + # 7. your entry here? ;) $echo_e "$errors" | grep "^Parse error:" if [ $? -ne 0 ] then -- cgit v1.2.1 From bdf21e45caadd74c7f4c41d6e1bf4737d9300cf4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 16 Apr 2012 03:04:29 -0400 Subject: [ticket/10767] Revert unconditional unfatality in commit-msg hook. Revert "[ticket/10093] Make commit-msg always not fatal by nuking all fatal logic." This reverts commit 88cad5523e7cdac6826dd8581e27e22a65afda26. PHPBB3-10093 PHPBB3-10767 --- git-tools/hooks/commit-msg | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 52969670ca..3c42411602 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -12,6 +12,11 @@ # 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, this is the default) +# git config phpbb.hooks.commit-msg.fatal false (warn only, do not abort) +# # 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: @@ -21,6 +26,13 @@ config_ns="phpbb.hooks.commit-msg"; +if [ "$(git config --bool $config_ns.fatal)" = "false" ] +then + fatal=0; +else + fatal=1; +fi + debug_level=$(git config --int $config_ns.debug || echo 0); # Error codes @@ -47,9 +59,12 @@ debug() quit() { - # Now we always exit with success, since git will trash - # entered commit message if commit-msg hook exits with a failure. - exit 0 + if [ $1 -gt 0 ] && [ $1 -ne $ERR_UNKNOWN ] && [ $fatal -eq 0 ] + then + exit 0; + else + exit $1; + fi } use_color() -- cgit v1.2.1 From 1ce8a1d7ee1f361278358f5b2b3e15b449d2a8aa Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:49:59 -0400 Subject: [ticket/10767] Default to non-fatal behavior. PHPBB3-10767 --- git-tools/hooks/commit-msg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 3c42411602..4c9e56f555 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -14,9 +14,11 @@ # # You can configure whether invalid commit messages abort commits: # -# git config phpbb.hooks.commit-msg.fatal true (abort, this is the default) +# 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: @@ -26,11 +28,11 @@ 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; +else + fatal=0; fi debug_level=$(git config --int $config_ns.debug || echo 0); -- cgit v1.2.1 From 45b910f9b445dc50cf65e456d8fe6f3aae2cbc11 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:56:09 -0400 Subject: [ticket/10767] Use warning/error language as appropriate. When commit-msg hook is fatal, label the message as an error. When it is not fatal, label the message as a warning. "Syntax error" is still always an error, not sure if this should be changed. PHPBB3-10767 --- git-tools/hooks/commit-msg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index 4c9e56f555..fbeda805b7 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -31,8 +31,10 @@ config_ns="phpbb.hooks.commit-msg"; if [ "$(git config --bool $config_ns.fatal)" = "true" ] then fatal=1; + severity=Error; else fatal=0; + severity=Warning; fi debug_level=$(git config --int $config_ns.debug || echo 0); @@ -187,7 +189,7 @@ do # Don't be too strict. # Commits may be temporary, intended to be squashed later. # Just issue a warning here. - complain "Warning: heading should be a sentence beginning with a capital letter." 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 -- cgit v1.2.1 From aceca2566b80753d79c1dc77f5470618b0a2078d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:59:35 -0400 Subject: [ticket/10767] Clarify what happens at the end of the hook. If there are problems and fatal is true, print that the commit is aborted. If there are problems and fatal is false, print instructions for fixing the commit. PHPBB3-10767 --- git-tools/hooks/commit-msg | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'git-tools') diff --git a/git-tools/hooks/commit-msg b/git-tools/hooks/commit-msg index fbeda805b7..b156d276df 100755 --- a/git-tools/hooks/commit-msg +++ b/git-tools/hooks/commit-msg @@ -63,10 +63,17 @@ 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 } -- cgit v1.2.1