Salome HOME
ménage
[modules/shaper.git] / GitHooks / pre-commit.in
1 #!/bin/bash
2
3 if git rev-parse --verify HEAD >/dev/null 2>&1
4 then
5   against=HEAD
6 else
7   # Initial commit: diff against an empty tree object
8   against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
9 fi
10
11 # If you want to allow non-ASCII filenames set this variable to true.
12 allownonascii=$(git config hooks.allownonascii)
13
14 # Redirect output to stderr.
15 exec 1>&2
16
17 # Cross platform projects tend to avoid non-ASCII filenames; prevent
18 # them from being added to the repository. We exploit the fact that the
19 # printable range starts at the space character and ends with tilde.
20 if [ "$allownonascii" != "true" ] &&
21   # Note that the use of brackets around a tr range is ok here, (it's
22   # even required, for portability to Solaris 10's /usr/bin/tr), since
23   # the square bracket bytes happen to fall in the designated range.
24   test $(git diff --cached --name-only --diff-filter=A -z $against |
25     LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
26 then
27   cat <<\EOF
28 Error: Attempt to add a non-ASCII file name.
29
30 This can cause problems if you want to work with people on other platforms.
31
32 To be portable it is advisable to rename the file.
33
34 If you know what you are doing you can disable this check using:
35
36   git config hooks.allownonascii true
37 EOF
38   exit 1
39 fi
40
41 # If there are whitespace errors, print the offending file names and fail.
42 exec git diff-index --check --cached $against -- . ':(exclude)*.rst'