gitweb: Fix blob linenr links in pathinfo mode
[git/gitweb.git] / templates / hooks--pre-commit.sample
blob043970a751f0a85cfa99684be5d610b33b15a358
1 #!/bin/sh
3 # An example hook script to verify what is about to be committed.
4 # Called by git-commit with no arguments. The hook should
5 # exit with non-zero status after issuing an appropriate message if
6 # it wants to stop the commit.
8 # To enable this hook, rename this file to "pre-commit".
10 # If you want to allow non-ascii filenames set this variable to true.
11 allownonascii=$(git config hooks.allownonascii)
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 # Note that the use of brackets around a tr range is ok here, (it's
18 # even required, for portability to Solaris 10's /usr/bin/tr), since
19 # the square bracket bytes happen to fall in the designated range.
20 test "$(git diff --cached --name-only --diff-filter=A -z |
21 LC_ALL=C tr -d '[ -~]\0')"
22 then
23 echo "Error: Attempt to add a non-ascii file name."
24 echo
25 echo "This can cause problems if you want to work"
26 echo "with people on other platforms."
27 echo
28 echo "To be portable it is advisable to rename the file ..."
29 echo
30 echo "If you know what you are doing you can disable this"
31 echo "check using:"
32 echo
33 echo " git config hooks.allownonascii true"
34 echo
35 exit 1
38 if git-rev-parse --verify HEAD >/dev/null 2>&1
39 then
40 against=HEAD
41 else
42 # Initial commit: diff against an empty tree object
43 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
46 exec git diff-index --check --cached $against --