annotate myTools/.git/hooks/pre-commit.sample @ 6:f9f71cf4c3e3

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