blob: 91bacb2e4fad46a67e6f0c80608f6f3f083f71e0 [file] [log] [blame]
Hans-Christoph Steiner0761ec32019-01-09 13:00:45 +01001#!/bin/sh
2#
3# An hook script to verify what is about to be committed.
4# Called by "git commit" with no arguments. The hook will
5# exit with non-zero status after issuing an appropriate message if
6# it wants to stop the commit.
7
8if git rev-parse --verify HEAD >/dev/null 2>&1
9then
Hans-Christoph Steinera0b7f612019-01-09 14:28:35 +010010 against=HEAD
Hans-Christoph Steiner0761ec32019-01-09 13:00:45 +010011else
Hans-Christoph Steinera0b7f612019-01-09 14:28:35 +010012 # Initial commit: diff against an empty tree object
13 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
Hans-Christoph Steiner0761ec32019-01-09 13:00:45 +010014fi
15
16# If you want to allow non-ascii filenames set this variable to true.
17allownonascii=$(git config hooks.allownonascii)
18
19# Redirect output to stderr.
20exec 1>&2
21
22# Cross platform projects tend to avoid non-ascii filenames; prevent
23# them from being added to the repository. We exploit the fact that the
24# printable range starts at the space character and ends with tilde.
25if [ "$allownonascii" != "true" ] &&
Hans-Christoph Steinera0b7f612019-01-09 14:28:35 +010026 # Note that the use of brackets around a tr range is ok here, (it's
27 # even required, for portability to Solaris 10's /usr/bin/tr), since
28 # the square bracket bytes happen to fall in the designated range.
29 test $(git diff --cached --name-only --diff-filter=A -z $against |
30 LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
Hans-Christoph Steiner0761ec32019-01-09 13:00:45 +010031then
Hans-Christoph Steinera0b7f612019-01-09 14:28:35 +010032 echo "Error: Attempt to add a non-ascii file name."
33 echo
34 echo "This can cause problems if you want to work"
35 echo "with people on other platforms."
36 echo
37 echo "To be portable it is advisable to rename the file ..."
38 echo
39 echo "If you know what you are doing you can disable this"
40 echo "check using:"
41 echo
42 echo " git config hooks.allownonascii true"
43 echo
44 exit 1
Hans-Christoph Steiner0761ec32019-01-09 13:00:45 +010045fi
46
47# If there are whitespace errors, print the offending file names and fail.
48exec git diff-index --check --cached $against --