From bdf21e45caadd74c7f4c41d6e1bf4737d9300cf4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 16 Apr 2012 03:04:29 -0400 Subject: [PATCH 1/4] [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(-) 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() From 1ce8a1d7ee1f361278358f5b2b3e15b449d2a8aa Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:49:59 -0400 Subject: [PATCH 2/4] [ticket/10767] Default to non-fatal behavior. PHPBB3-10767 --- git-tools/hooks/commit-msg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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); From 45b910f9b445dc50cf65e456d8fe6f3aae2cbc11 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:56:09 -0400 Subject: [PATCH 3/4] [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(-) 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 From aceca2566b80753d79c1dc77f5470618b0a2078d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 17 Apr 2012 05:59:35 -0400 Subject: [PATCH 4/4] [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(-) 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 }