add standard pre-commit hook that does quick checks, e.g. l18n scripts
This commit is contained in:
parent
2daf741c4a
commit
1e0200fa30
30
hooks/install-hooks.sh
Executable file
30
hooks/install-hooks.sh
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Install all the client hooks
|
||||||
|
|
||||||
|
BASE_DIR="$(cd $(dirname $0); pwd -P)"
|
||||||
|
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-push post-push pre-receive update post-receive post-update pre-auto-gc"
|
||||||
|
HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
|
||||||
|
|
||||||
|
for hook in $HOOK_NAMES; do
|
||||||
|
|
||||||
|
shipped_hook="$BASE_DIR/$hook"
|
||||||
|
installed_hook="$HOOK_DIR/$hook"
|
||||||
|
|
||||||
|
# If we don't distribute it, continue
|
||||||
|
if [ ! -f "$shipped_hook" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -h "$installed_hook" ]; then
|
||||||
|
echo "$installed_hook is a symlink - replacing."
|
||||||
|
elif [ -e "$installed_hook" ]; then
|
||||||
|
echo "$installed_hook hook already exists."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the symlink
|
||||||
|
echo "ln -s -f \"$shipped_hook\" \"$installed_hook\""
|
||||||
|
ln -s -f "$shipped_hook" "$installed_hook"
|
||||||
|
|
||||||
|
done
|
52
hooks/pre-commit
Executable file
52
hooks/pre-commit
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# An hook script to verify what is about to be committed.
|
||||||
|
# Called by "git commit" with no arguments. The hook will
|
||||||
|
# exit with non-zero status after issuing an appropriate message if
|
||||||
|
# it wants to stop the commit.
|
||||||
|
|
||||||
|
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
against=HEAD
|
||||||
|
else
|
||||||
|
# Initial commit: diff against an empty tree object
|
||||||
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If you want to allow non-ascii filenames set this variable to true.
|
||||||
|
allownonascii=$(git config hooks.allownonascii)
|
||||||
|
|
||||||
|
# Redirect output to stderr.
|
||||||
|
exec 1>&2
|
||||||
|
|
||||||
|
# Cross platform projects tend to avoid non-ascii filenames; prevent
|
||||||
|
# them from being added to the repository. We exploit the fact that the
|
||||||
|
# printable range starts at the space character and ends with tilde.
|
||||||
|
if [ "$allownonascii" != "true" ] &&
|
||||||
|
# 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.
|
||||||
|
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||||
|
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||||
|
then
|
||||||
|
echo "Error: Attempt to add a non-ascii file name."
|
||||||
|
echo
|
||||||
|
echo "This can cause problems if you want to work"
|
||||||
|
echo "with people on other platforms."
|
||||||
|
echo
|
||||||
|
echo "To be portable it is advisable to rename the file ..."
|
||||||
|
echo
|
||||||
|
echo "If you know what you are doing you can disable this"
|
||||||
|
echo "check using:"
|
||||||
|
echo
|
||||||
|
echo " git config hooks.allownonascii true"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec ./tools/fix-ellipsis.sh
|
||||||
|
exec ./tools/check-format-strings.py
|
||||||
|
exec ./tools/remove-unused-and-blank-translations.py
|
||||||
|
|
||||||
|
# If there are whitespace errors, print the offending file names and fail.
|
||||||
|
exec git diff-index --check --cached $against --
|
@ -1,5 +1,9 @@
|
|||||||
#!/bin/bash -x
|
#!/bin/bash
|
||||||
|
|
||||||
# Fix TypographyEllipsis programmatically
|
# Fix TypographyEllipsis programmatically
|
||||||
|
|
||||||
sed -i 's/\.\.\./…/g' app/src/main/res/values*/*.xml
|
sed -i 's/\.\.\./…/g' app/src/main/res/values*/*.xml
|
||||||
|
if git diff | grep -Eo '^\+.*…'; then
|
||||||
|
echo Fix TypographyEllipsis
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
@ -7,8 +7,11 @@
|
|||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
|
||||||
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res')
|
||||||
sourcepath = os.path.join(resdir, 'values', 'strings.xml')
|
sourcepath = os.path.join(resdir, 'values', 'strings.xml')
|
||||||
|
|
||||||
@ -60,6 +63,7 @@ for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
|||||||
found_other = True
|
found_other = True
|
||||||
if not found_other:
|
if not found_other:
|
||||||
print(os.path.relpath(str_path) + ': Missing "other" string in', e.attrib['name'])
|
print(os.path.relpath(str_path) + ': Missing "other" string in', e.attrib['name'])
|
||||||
|
count += 1
|
||||||
|
|
||||||
result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8'))
|
result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8'))
|
||||||
|
|
||||||
@ -67,3 +71,5 @@ for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))):
|
|||||||
f.write(header)
|
f.write(header)
|
||||||
f.write(result)
|
f.write(result)
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
|
|
||||||
|
sys.exit(count)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user