Skip to content

Commit d00e364

Browse files
hvoigtgitster
authored andcommitted
Extend sample pre-commit hook to check for non ascii filenames
At the moment non-ascii encodings of filenames are not portably converted between different filesystems by git. This will most likely change in the future but to allow repositories to be portable among different file/operating systems this check is enabled by default. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 91fe2f9 commit d00e364

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

templates/hooks--pre-commit.sample

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@
77
#
88
# To enable this hook, rename this file to "pre-commit".
99

10+
# If you want to allow non-ascii filenames set this variable to true.
11+
allownonascii=$(git config hooks.allownonascii)
12+
13+
# Cross platform projects tend to avoid non-ascii filenames; prevent
14+
# them from being added to the repository. We exploit the fact that the
15+
# printable range starts at the space character and ends with tilde.
16+
if [ "$allownonascii" != "true" ] &&
17+
test "$(git diff --cached --name-only --diff-filter=A -z |
18+
LC_ALL=C tr -d '[ -~]\0')"
19+
then
20+
echo "Error: Attempt to add a non-ascii filename."
21+
echo
22+
echo "This can cause problems if you want to work together"
23+
echo "with people on other platforms than you."
24+
echo
25+
echo "To be portable it is adviseable to rename the file ..."
26+
echo
27+
echo "If you know what you are doing you can disable this"
28+
echo "check using:"
29+
echo
30+
echo " git config hooks.allownonascii true"
31+
echo
32+
exit 1
33+
fi
34+
1035
if git-rev-parse --verify HEAD >/dev/null 2>&1
1136
then
1237
against=HEAD

0 commit comments

Comments
 (0)