hooks:pre-commit: Update to git's current version

The template has changed since I've added it.
This commit is contained in:
2025-05-30 01:21:48 +02:00
parent 4fba1bbf13
commit d4d21ceb1d

View File

@@ -13,22 +13,24 @@ if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
against=$(git hash-object -t tree /dev/null)
fi
# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --type=bool hooks.allownonascii)
# Redirect output to stderr.
exec 1>&2
# Check that all filenames include only ASCII characters.
allownonascii=$(git config --bool hooks.allownonascii)
if [ "$allownonascii" != "true" ]; then
# We exploit the fact that the printable range starts at the space character
# and ends with tilde.
# We exploit the fact that the printable range starts at the space
# character and ends with tilde.
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
num_nonascii=$(
git diff --cached --name-only --diff-filter=AR -z $against \
git diff-index --cached --name-only --diff-filter=A -z $against \
| LC_ALL=C tr -d '[ -~]\0' \
| wc -c
)