{"thread":{"id":"42614","subject":"[PATCH] hooks--pre-commit.sample: check for chars, that are not allowed for a windows file name","startedAt":"2016-06-16T06:55:53Z","lastAt":"2016-06-17T22:24:23Z","messageCount":4,"participants":["dexteritas","Thomas Braun","Junio C Hamano","dex teritas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"289281","messageId":"0102015553154cde-5c798c87-87c1-4acf-919a-c824dce01fae-000000@eu-west-1.amazonses.com","threadId":"42614","inReplyTo":null,"subject":"[PATCH] hooks--pre-commit.sample: check for chars, that are not allowed for a windows file name","fromName":"dexteritas","fromEmail":"dexteritas1@gmx.de","sentAt":"2016-06-15T08:02:32Z","receivedAt":"2016-06-16T06:55:53Z","isPatch":true,"sender":{"key":"dexteritas1@gmx.de","avatar":null},"body":"After the ASCII-check, test the windows compatibility of file names.\nCan be disabled by:\ngit config hooks.allownonwindowschars true\n---\n templates/hooks--pre-commit.sample | 22 ++++++++++++++++++++++\n 1 file changed, 22 insertions(+)\n\ndiff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\nindex 68d62d5..120daf1 100755\n--- a/templates/hooks--pre-commit.sample\n+++ b/templates/hooks--pre-commit.sample\n@@ -17,6 +17,7 @@ fi\n \n # If you want to allow non-ASCII filenames set this variable to true.\n allownonascii=$(git config --bool hooks.allownonascii)\n+allownonwindowschars=$(git config --bool hooks.allownonwindowschars)\n \n # Redirect output to stderr.\n exec 1>&2\n@@ -43,6 +44,27 @@ If you know what you are doing you can disable this check using:\n   git config hooks.allownonascii true\n EOF\n \texit 1\n+elif [ \"$allownonwindowschars\" != \"true\" ] &&\n+\t# If you work with linux and windows, there is a problem, if you use\n+\t# chars like \\ / : * ? \" < > |\n+\t# Check if there are used only windows compatible chars\n+\ttest $(git diff --cached --name-only --diff-filter=A -z $against |\n+\t  LC_ALL=C tr -d '[0-9A-Za-z\\[\\]\\{\\}_ -)+-.]\\0' | wc -c) != 0\n+then\n+\tcat <<\\EOF\n+Error: Attempt to add a chars that are not allowed for a windows file name.\n+\n+This can cause problems if you want to work with people on other platforms.\n+\n+To be portable it is advisable to rename the file.\n+\n+Check your filenames for: \\ / : * ? \" < > |\n+\n+If you know what you are doing you can disable this check using:\n+\n+  git config hooks.allownonwindowschars true\n+EOF\n+\texit 2\n fi\n \n # If there are whitespace errors, print the offending file names and fail.\n\n--\nhttps://github.com/git/git/pull/252\n"},{"id":"289286","messageId":"5c02cc24-f68d-6eb3-9759-ffff328a0c2f@virtuell-zuhause.de","threadId":"42614","inReplyTo":"0102015553154cde-5c798c87-87c1-4acf-919a-c824dce01fae-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] hooks--pre-commit.sample: check for chars, that are not allowed for a windows file name","fromName":"Thomas Braun","fromEmail":"thomas.braun@virtuell-zuhause.de","sentAt":"2016-06-15T11:15:36Z","receivedAt":"2016-06-16T06:55:53Z","isPatch":true,"sender":{"key":"thomas.braun@virtuell-zuhause.de","avatar":"https://avatars.githubusercontent.com/u/1185677?v=4"},"body":"Am 15.06.2016 um 10:02 schrieb dexteritas:\n> After the ASCII-check, test the windows compatibility of file names.\n> Can be disabled by:\n> git config hooks.allownonwindowschars true\n> ---\n>  templates/hooks--pre-commit.sample | 22 ++++++++++++++++++++++\n>  1 file changed, 22 insertions(+)\n> \n> diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\n> index 68d62d5..120daf1 100755\n> --- a/templates/hooks--pre-commit.sample\n> +++ b/templates/hooks--pre-commit.sample\n> @@ -17,6 +17,7 @@ fi\n>  \n>  # If you want to allow non-ASCII filenames set this variable to true.\n>  allownonascii=$(git config --bool hooks.allownonascii)\n> +allownonwindowschars=$(git config --bool hooks.allownonwindowschars)\n>  \n>  # Redirect output to stderr.\n>  exec 1>&2\n> @@ -43,6 +44,27 @@ If you know what you are doing you can disable this check using:\n>    git config hooks.allownonascii true\n>  EOF\n>  \texit 1\n> +elif [ \"$allownonwindowschars\" != \"true\" ] &&\n> +\t# If you work with linux and windows, there is a problem, if you use\n> +\t# chars like \\ / : * ? \" < > |\n> +\t# Check if there are used only windows compatible chars\n> +\ttest $(git diff --cached --name-only --diff-filter=A -z $against |\n> +\t  LC_ALL=C tr -d '[0-9A-Za-z\\[\\]\\{\\}_ -)+-.]\\0' | wc -c) != 0\n> +then\n> +\tcat <<\\EOF\n> +Error: Attempt to add a chars that are not allowed for a windows file name.\n> +\n> +This can cause problems if you want to work with people on other platforms.\n> +\n> +To be portable it is advisable to rename the file.\n> +\n> +Check your filenames for: \\ / : * ? \" < > |\n> +\n> +If you know what you are doing you can disable this check using:\n> +\n> +  git config hooks.allownonwindowschars true\n> +EOF\n> +\texit 2\n>  fi\n>  \n>  # If there are whitespace errors, print the offending file names and fail.\n\nThere are some cases of illegal file names missing. E.g. reserved names,\ntrailing period and space. My trial with a precommit hook for avoiding\nillegal filenames on windows can be found at [1]. Feel free to loot my\nversion for a reroll.\n\n[1]:\nhttps://github.com/t-b/git-pre-commit-hook-windows-filenames/blob/master/pre-commit\n"},{"id":"289302","messageId":"xmqqlh2672yp.fsf@gitster.mtv.corp.google.com","threadId":"42614","inReplyTo":"0102015553154cde-5c798c87-87c1-4acf-919a-c824dce01fae-000000@eu-west-1.amazonses.com","subject":"Re: [PATCH] hooks--pre-commit.sample: check for chars, that are not allowed for a windows file name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-15T17:54:06Z","receivedAt":"2016-06-16T06:55:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"dexteritas <dexteritas1@gmx.de> writes:\n\n> After the ASCII-check, test the windows compatibility of file names.\n> Can be disabled by:\n> git config hooks.allownonwindowschars true\n> ---\n\nMissing sign off.\n\n>  templates/hooks--pre-commit.sample | 22 ++++++++++++++++++++++\n>  1 file changed, 22 insertions(+)\n>\n> diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\n> index 68d62d5..120daf1 100755\n> --- a/templates/hooks--pre-commit.sample\n> +++ b/templates/hooks--pre-commit.sample\n> @@ -17,6 +17,7 @@ fi\n>  \n>  # If you want to allow non-ASCII filenames set this variable to true.\n>  allownonascii=$(git config --bool hooks.allownonascii)\n> +allownonwindowschars=$(git config --bool hooks.allownonwindowschars)\n>  \n>  # Redirect output to stderr.\n>  exec 1>&2\n> @@ -43,6 +44,27 @@ If you know what you are doing you can disable this check using:\n>    git config hooks.allownonascii true\n>  EOF\n>  \texit 1\n> +elif [ \"$allownonwindowschars\" != \"true\" ] &&\n\nThis line is doubly irritating because (1) the double negation is\nsomewhat hard to grok, and (2) [] is not part of our CodingStyle.\n\nBecause you inherited this from the existing \"allow-non-ascii\" one,\nhowever, I do not want to see you change this line, if you need to\nreroll.\n\n> +\t# If you work with linux and windows, there is a problem, if you use\n> +\t# chars like \\ / : * ? \" < > |\n\nThere is no reason to single out Linux, is there?\n\nThis new check is only about Windows and because people on other\nplatforms, not limited to Linux, may not be aware of some characters\nthat are not usable on Windows, you are trying to help them, no?\n\n> +\t# Check if there are used only windows compatible chars\n> +\ttest $(git diff --cached --name-only --diff-filter=A -z $against |\n> +\t  LC_ALL=C tr -d '[0-9A-Za-z\\[\\]\\{\\}_ -)+-.]\\0' | wc -c) != 0\n\nBecause this is in \"elif\", we know we are allowing non-ascii\ncharacters when we come here.  So you need to do a quite similar\ncheck from scratch, which is sensible.  I do not offhand know if\nthis covers all the characters that Windows users cannot use,\nthough.\n\n> +then\n> +\tcat <<\\EOF\n> +Error: Attempt to add a chars that are not allowed for a windows file name.\n> +\n> +This can cause problems if you want to work with people on other platforms.\n> +\n> +To be portable it is advisable to rename the file.\n> +\n> +Check your filenames for: \\ / : * ? \" < > |\n> +\n> +If you know what you are doing you can disable this check using:\n> +\n> +  git config hooks.allownonwindowschars true\n> +EOF\n> +\texit 2\n\nWhy 2?\n\n>  fi\n>  \n>  # If there are whitespace errors, print the offending file names and fail.\n\nWhen the user says\n\n\t[hooks]\n            allownonascii = false\n\t    allownonwindowschars = false\n\nwhat happens?\n\nThe user's intention clearly is that the project wants to be usable\non Windows and also wants to exclude characters from codepages that\nare not ASCII.  I however suspect that the hook with your patch will\nallow people to create a \"path>like?this.txt\" happily.\n"},{"id":"289524","messageId":"0Lyj4F-1bQz0I1R2N-016Asy@mail.gmx.com","threadId":"42614","inReplyTo":"5c02cc24-f68d-6eb3-9759-ffff328a0c2f@virtuell-zuhause.de","subject":"Re: [PATCH] hooks--pre-commit.sample: check for chars, that are not allowed for a windows file name","fromName":"dex teritas","fromEmail":"dexteritas1@gmx.de","sentAt":"2016-06-17T22:24:04Z","receivedAt":"2016-06-17T22:24:23Z","isPatch":true,"sender":{"key":"dexteritas1@gmx.de","avatar":null},"body":"Am 15.06.2016 um 13:15 schrieb Thomas Braun:\n> Am 15.06.2016 um 10:02 schrieb dexteritas:\n>> After the ASCII-check, test the windows compatibility of file names.\n>> Can be disabled by:\n>> git config hooks.allownonwindowschars true\n>> ---\n>>  templates/hooks--pre-commit.sample | 22 ++++++++++++++++++++++\n>>  1 file changed, 22 insertions(+)\n>>\n>> diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\n>> index 68d62d5..120daf1 100755\n>> --- a/templates/hooks--pre-commit.sample\n>> +++ b/templates/hooks--pre-commit.sample\n>> @@ -17,6 +17,7 @@ fi\n>>  \n>>  # If you want to allow non-ASCII filenames set this variable to true.\n>>  allownonascii=$(git config --bool hooks.allownonascii)\n>> +allownonwindowschars=$(git config --bool hooks.allownonwindowschars)\n>>  \n>>  # Redirect output to stderr.\n>>  exec 1>&2\n>> @@ -43,6 +44,27 @@ If you know what you are doing you can disable this check using:\n>>    git config hooks.allownonascii true\n>>  EOF\n>>  \texit 1\n>> +elif [ \"$allownonwindowschars\" != \"true\" ] &&\n>> +\t# If you work with linux and windows, there is a problem, if you use\n>> +\t# chars like \\ / : * ? \" < > |\n>> +\t# Check if there are used only windows compatible chars\n>> +\ttest $(git diff --cached --name-only --diff-filter=A -z $against |\n>> +\t  LC_ALL=C tr -d '[0-9A-Za-z\\[\\]\\{\\}_ -)+-.]\\0' | wc -c) != 0\n>> +then\n>> +\tcat <<\\EOF\n>> +Error: Attempt to add a chars that are not allowed for a windows file name.\n>> +\n>> +This can cause problems if you want to work with people on other platforms.\n>> +\n>> +To be portable it is advisable to rename the file.\n>> +\n>> +Check your filenames for: \\ / : * ? \" < > |\n>> +\n>> +If you know what you are doing you can disable this check using:\n>> +\n>> +  git config hooks.allownonwindowschars true\n>> +EOF\n>> +\texit 2\n>>  fi\n>>  \n>>  # If there are whitespace errors, print the offending file names and fail.\n> There are some cases of illegal file names missing. E.g. reserved names,\n> trailing period and space. My trial with a precommit hook for avoiding\n> illegal filenames on windows can be found at [1]. Feel free to loot my\n> version for a reroll.\n>\n> [1]:\n> https://github.com/t-b/git-pre-commit-hook-windows-filenames/blob/master/pre-commit\n>\nYou're right. Thanks for the example.\n"}]}