mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[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
This commit is contained in:
parent
6a3ee0996e
commit
92cdf08d48
1 changed files with 50 additions and 1 deletions
|
@ -16,6 +16,13 @@
|
||||||
#
|
#
|
||||||
# git config phpbb.hooks.commit-msg.fatal true (abort, this is the default)
|
# 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)
|
# 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";
|
config_ns="phpbb.hooks.commit-msg";
|
||||||
|
|
||||||
|
@ -60,9 +67,51 @@ quit()
|
||||||
fi
|
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()
|
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 "$@"
|
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
|
# Check for empty commit message
|
||||||
|
|
Loading…
Add table
Reference in a new issue