{"thread":{"id":"21487","subject":"[PATCH] pre-commit.sample: Diff against the empty tree when HEAD is invalid","startedAt":"2009-11-05T10:57:57Z","lastAt":"2009-11-06T17:11:35Z","messageCount":2,"participants":["Björn Steinbrink","Heiko Voigt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"126902","messageId":"20091105105757.GA31787@atjola.homenet","threadId":"21487","inReplyTo":null,"subject":"[PATCH] pre-commit.sample: Diff against the empty tree when HEAD is invalid","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-11-05T10:57:57Z","receivedAt":"2009-11-05T10:57:57Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"This was already the case for the old \"diff --check\" call, but the new\none that checks whether there are any non-ascii file names was missing\nit, making that check fail for root commits.\n\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\n templates/hooks--pre-commit.sample |   18 +++++++++---------\n 1 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\nindex 043970a..439eefd 100755\n--- a/templates/hooks--pre-commit.sample\n+++ b/templates/hooks--pre-commit.sample\n@@ -7,6 +7,14 @@\n #\n # To enable this hook, rename this file to \"pre-commit\".\n \n+if git-rev-parse --verify HEAD >/dev/null 2>&1\n+then\n+\tagainst=HEAD\n+else\n+\t# Initial commit: diff against an empty tree object\n+\tagainst=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n+fi\n+\n # If you want to allow non-ascii filenames set this variable to true.\n allownonascii=$(git config hooks.allownonascii)\n \n@@ -17,7 +25,7 @@ if [ \"$allownonascii\" != \"true\" ] &&\n \t# Note that the use of brackets around a tr range is ok here, (it's\n \t# even required, for portability to Solaris 10's /usr/bin/tr), since\n \t# the square bracket bytes happen to fall in the designated range.\n-\ttest \"$(git diff --cached --name-only --diff-filter=A -z |\n+\ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n \t  LC_ALL=C tr -d '[ -~]\\0')\"\n then\n \techo \"Error: Attempt to add a non-ascii file name.\"\n@@ -35,12 +43,4 @@ then\n \texit 1\n fi\n \n-if git-rev-parse --verify HEAD >/dev/null 2>&1\n-then\n-\tagainst=HEAD\n-else\n-\t# Initial commit: diff against an empty tree object\n-\tagainst=4b825dc642cb6eb9a060e54bf8d69288fbee4904\n-fi\n-\n exec git diff-index --check --cached $against --\n-- \n1.6.5.2.143.g8cc62\n"},{"id":"126990","messageId":"20091106171126.GA42592@book.hvoigt.net","threadId":"21487","inReplyTo":"20091105105757.GA31787@atjola.homenet","subject":"Re: [PATCH] pre-commit.sample: Diff against the empty tree when HEAD is invalid","fromName":"Heiko Voigt","fromEmail":"hvoigt@hvoigt.net","sentAt":"2009-11-06T17:11:35Z","receivedAt":"2009-11-06T17:11:35Z","isPatch":true,"sender":{"key":"hvoigt@hvoigt.net","avatar":"https://avatars.githubusercontent.com/u/184958?v=4"},"body":"Hallo,\n\nOn Thu, Nov 05, 2009 at 11:57:57AM +0100, Björn Steinbrink wrote:\n> This was already the case for the old \"diff --check\" call, but the new\n> one that checks whether there are any non-ascii file names was missing\n> it, making that check fail for root commits.\n> \n> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n\n[...]\n> -\ttest \"$(git diff --cached --name-only --diff-filter=A -z |\n> +\ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n\nLooks sensible to me. Thanks for that fix.\n\nAs this went unnoticed for quite some time it seems as either not many\nare actually using our example hook or at least not starting new\nprojects with it. I fit in the latter group I suppose.\n\ncheers Heiko\n"}]}