Update Release Notes to 1.6.5
[git/git.git] / templates / hooks--pre-commit.sample
CommitLineData
89e2c5f1
JH
1#!/bin/sh
2#
3# An example hook script to verify what is about to be committed.
215a7ad1 4# Called by git-commit with no arguments. The hook should
89e2c5f1
JH
5# exit with non-zero status after issuing an appropriate message if
6# it wants to stop the commit.
7#
f98f8cba 8# To enable this hook, rename this file to "pre-commit".
89e2c5f1 9
d00e364d
HV
10# If you want to allow non-ascii filenames set this variable to true.
11allownonascii=$(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.
16if [ "$allownonascii" != "true" ] &&
17 test "$(git diff --cached --name-only --diff-filter=A -z |
18 LC_ALL=C tr -d '[ -~]\0')"
19then
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
33fi
34
c646217e 35if git-rev-parse --verify HEAD >/dev/null 2>&1
d37fd032 36then
03e2b630 37 against=HEAD
d37fd032 38else
03e2b630
JH
39 # Initial commit: diff against an empty tree object
40 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
41fi
42
43exec git diff-index --check --cached $against --