annotate .git/hooks/pre-commit.sample @ 2:801f5e934011 draft default tip

Uploaded
author devteam
date Thu, 23 Oct 2014 11:40:52 -0400
parents b76a4f17bbbb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
1 #!/bin/sh
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
2 #
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
3 # An example hook script to verify what is about to be committed.
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
4 # Called by "git commit" with no arguments. The hook should
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
5 # exit with non-zero status after issuing an appropriate message if
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
6 # it wants to stop the commit.
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
7 #
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
8 # To enable this hook, rename this file to "pre-commit".
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
9
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
10 if git rev-parse --verify HEAD >/dev/null 2>&1
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
11 then
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
12 against=HEAD
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
13 else
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
14 # Initial commit: diff against an empty tree object
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
15 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
16 fi
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
17
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
18 # If you want to allow non-ascii filenames set this variable to true.
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
19 allownonascii=$(git config hooks.allownonascii)
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
20
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
21 # Cross platform projects tend to avoid non-ascii filenames; prevent
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
22 # them from being added to the repository. We exploit the fact that the
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
23 # printable range starts at the space character and ends with tilde.
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
24 if [ "$allownonascii" != "true" ] &&
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
25 # Note that the use of brackets around a tr range is ok here, (it's
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
26 # even required, for portability to Solaris 10's /usr/bin/tr), since
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
27 # the square bracket bytes happen to fall in the designated range.
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
28 test "$(git diff --cached --name-only --diff-filter=A -z $against |
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
29 LC_ALL=C tr -d '[ -~]\0')"
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
30 then
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
31 echo "Error: Attempt to add a non-ascii file name."
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
32 echo
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
33 echo "This can cause problems if you want to work"
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
34 echo "with people on other platforms."
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
35 echo
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
36 echo "To be portable it is advisable to rename the file ..."
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
37 echo
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
38 echo "If you know what you are doing you can disable this"
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
39 echo "check using:"
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
40 echo
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
41 echo " git config hooks.allownonascii true"
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
42 echo
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
43 exit 1
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
44 fi
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
45
b76a4f17bbbb Uploaded
devteam
parents:
diff changeset
46 exec git diff-index --check --cached $against --