diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-10-27 03:24:55 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-10-27 03:24:55 +0400 |
commit | 997a1946a55cafb992c4ba8e5e0795aa73f5a4a9 (patch) | |
tree | 7b3422278cddd3f9721b29e5586f014b7b335192 | |
parent | 425c771534f9f569d97d69106dc21043f812e506 (diff) | |
parent | 25f745fbec0e92a29e33aa85413c2bf7762608bf (diff) |
Merge branch 'maint'
* maint:
make the sample pre-commit hook script reject names with newlines, too
-rwxr-xr-x | templates/hooks--pre-commit.sample | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample index b187c4bb1f..18c4829765 100755 --- a/templates/hooks--pre-commit.sample +++ b/templates/hooks--pre-commit.sample @@ -18,6 +18,9 @@ fi # If you want to allow non-ascii filenames set this variable to true. allownonascii=$(git config hooks.allownonascii) +# Redirect output to stderr. +exec 1>&2 + # Cross platform projects tend to avoid non-ascii filenames; prevent # them from being added to the repository. We exploit the fact that the # printable range starts at the space character and ends with tilde. @@ -25,8 +28,8 @@ if [ "$allownonascii" != "true" ] && # Note that the use of brackets around a tr range is ok here, (it's # even required, for portability to Solaris 10's /usr/bin/tr), since # the square bracket bytes happen to fall in the designated range. - test "$(git diff --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0')" + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 then echo "Error: Attempt to add a non-ascii file name." echo @@ -43,4 +46,5 @@ then exit 1 fi +# If there are whitespace errors, print the offending file names and fail. exec git diff-index --check --cached $against -- |