[PATCH] Extend sample pre-commit hook to check for non ascii file/usernames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At the moment non-ascii encodings of file/usernames are not very well
supported by git. This will most likely change in the future but to
allow repositories to be portable among different file/operating systems
this check is enabled by default.

Signed-off-by: Heiko Voigt <heiko.voigt@xxxxxxx>
---
On Tue, May 12, 2009 at 11:55:39AM -0700, Jakub Narebski wrote:
> Somebody asked for a pre-add hook in the past; it would be good place
> to put such check.  But in meantime you can do it using pre-commit
> hook instead, isn't it?

I actually had this in my queue to be submitted...

 templates/hooks--pre-commit.sample |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample
index 0e49279..83ff873 100755
--- a/templates/hooks--pre-commit.sample
+++ b/templates/hooks--pre-commit.sample
@@ -7,6 +7,39 @@
 #
 # To enable this hook, rename this file to "pre-commit".
 
+# If you want to allow non-ascii filenames or usernames set
+# this variable to true.
+allownonascii=$(git config hooks.allownonascii)
+
+function is_ascii () {
+    test -z "$(cat | sed -e "s/[\ -~]*//g")"
+    return $?
+}
+
+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
+		echo "Non-ascii filenames are not allowed !"
+		echo "Please rename the file ..."
+		exit 1
+	fi
+
+	# non-ascii username issue a warning in git gui so tell the
+	# user to change it
+	if ! git config user.name | is_ascii; then
+		echo "Please only use ascii characters in your username!"
+		exit 1
+	fi
+
+	if ! git config user.email | is_ascii; then
+		echo "Please only use ascii characters in your email!"
+		exit 1
+	fi
+fi
+
 if git-rev-parse --verify HEAD 2>/dev/null
 then
 	against=HEAD
-- 
1.6.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]