From: Johannes Sixt Date: Mon, 18 May 2009 10:40:09 GMT Subject: Re: [PATCH] Extend sample pre-commit hook to check for non ascii filenames Message-ID: <4A113B09.6040301@viscovery.net> In-Reply-To: <20090518095044.GB910@heiko-voigts-macbook.local> Heiko Voigt schrieb: > +# is_ascii() Tests the string given given on standard input for > +# printable ascii conformance. We exploit the fact that the printable > +# range starts at the space character and ends with tilde. > +is_ascii() { > + test -z "$(LC_ALL=C tr -d \ -~)" > +} > + > +if [ "$allownonascii" != "true" ] > +then > + # until git can handle non-ascii filenames gracefully > + # prevent them to be added into the repository > + if ! git diff --cached --name-only --diff-filter=A -z \ > + | tr "\0" "\n" | is_ascii; then Will this not fail to add more than one file with allowed names? The \n is not removed in is_ascii(), and so the resulting string will not be empty. BTW, not all tr work well with NULs. See the commit message of e85fe4d8, for example. Otherwise, I would have suggested to convert the NUL to some allowed ASCII character, e.g. 'A'. BTW, you should really use '\0' and '\n' (single-quotes) to guarantee that the shell does not ignore the backslash. -- Hannes