pre-commit.sample: Diff against the empty tree when HEAD is invalid
This was already the case for the old "diff --check" call, but the new one that checks whether there are any non-ascii file names was missing it, making that check fail for root commits. Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Björn Steinbrink committed
Nov 5, 2009 at 11:57 UTC
c30eb852e281d55b04465b7814e00396893f74f3
1 file changed
+9
-9
templates/hooks--pre-commit.sample
+9
-9
@@ -7,6 +7,14 @@
7
#
8
# To enable this hook, rename this file to "pre-commit".
9
10
+if git-rev-parse --verify HEAD >/dev/null 2>&1
11
+then
12
+ against=HEAD
13
+else
14
+ # Initial commit: diff against an empty tree object
15
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
16
+fi
17
+
18
# If you want to allow non-ascii filenames set this variable to true.
19
allownonascii=$(git config hooks.allownonascii)
20
@@ -17,7 +25,7 @@ if [ "$allownonascii" != "true" ] &&
25
# Note that the use of brackets around a tr range is ok here, (it's
26
# even required, for portability to Solaris 10's /usr/bin/tr), since
27
# the square bracket bytes happen to fall in the designated range.
20
- test "$(git diff --cached --name-only --diff-filter=A -z |
28
+ test "$(git diff --cached --name-only --diff-filter=A -z $against |
29
LC_ALL=C tr -d '[ -~]\0')"
30
then
31
echo "Error: Attempt to add a non-ascii file name."
@@ -35,12 +43,4 @@ then
43
exit 1
44
fi
45
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
44
-fi
45
-
46
exec git diff-index --check --cached $against --