{"thread":{"id":"25339","subject":"[TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree","startedAt":"2010-10-04T18:54:57Z","lastAt":"2010-10-04T18:54:57Z","messageCount":1,"participants":["Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"152569","messageId":"1286218497-18036-1-git-send-email-bert.wesarg@googlemail.com","threadId":"25339","inReplyTo":null,"subject":"[TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2010-10-04T18:54:57Z","receivedAt":"2010-10-04T18:54:57Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"We currently check fo these files only in the working tree. But we should check\nwhat would be commited. We use write-tree to be able to utilize ls-tree and\ncheck the result.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\n hooks/pre-commit.sh |   36 +++++++++++++++++++++++++++++++-----\n 1 files changed, 31 insertions(+), 5 deletions(-)\n\ndiff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh\nindex 9d677e9..7f66c75 100644 hooks/pre-commit.sh\n--- a/hooks/pre-commit.sh\n+++ b/hooks/pre-commit.sh\n@@ -29,10 +29,36 @@ else\n \texit 0;\n fi\n \n-# TODO: check the index, not the working copy\n-[ -s \"$root_dir/.topdeps\" ] ||\n-\tdie \".topdeps is missing\"\n-[ -s \"$root_dir/.topmsg\" ] ||\n-\tdie \".topmsg is missing\"\n+check_topfile()\n+{\n+\tlocal tree=$1\n+\tlocal file=$2\n+\n+\tlocal ls_line=\"$(git ls-tree --long \"$tree\" \"$file\")\" ||\n+\t\tdie \"Can't ls tree for $file\"\n+\n+\t[ -n \"$ls_line\" ] ||\n+\t\tdie \"$file is missing\"\n+\n+\t# check for type and size\n+\tset -- $ls_line\n+\tlocal type=$2\n+\tlocal size=$4\n+\n+\t# check file is of type blob (file)\n+\t[ \"x$type\" = \"xblob\" ] ||\n+\t\tdie \"$file is not a file\"\n+\n+\t# check for positive size\n+\t[ \"$size\" -gt 0 ] ||\n+\t\tdie \"$file has empty size\"\n+}\n+\n+# I suspect this can't fail, but who knows\n+tree=$(git write-tree) ||\n+\tdie \"Can't write tree\"\n+\n+check_topfile \"$tree\" \".topdeps\"\n+check_topfile \"$tree\" \".topmsg\"\n \n # TODO: Verify .topdeps for valid branch names and against cycles\n-- \ntg: (ff59ac7..) bw/pre-commit-check-.top-files (depends on: master)\n"}]}