{"thread":{"id":"19657","subject":"Re: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree","startedAt":"2009-06-02T20:40:38Z","lastAt":"2009-06-04T21:29:15Z","messageCount":3,"participants":["Uwe Kleine-König","Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"299106","messageId":"1243975238-4807-1-git-send-email-bert.wesarg@googlemail.com","threadId":"19657","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":"2009-06-02T20:40:38Z","receivedAt":"2009-06-02T20:40:38Z","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\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: (b725fc9..) bw/pre-commit-check-.top-files (depends on: master)\n"},{"id":"115412","messageId":"20090604052716.GA24414@pengutronix.de","threadId":"19657","inReplyTo":"1243975238-4807-1-git-send-email-bert.wesarg@googlemail.com","subject":"Re: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree","fromName":"Uwe Kleine-König","fromEmail":"u.kleine-koenig@pengutronix.de","sentAt":"2009-06-04T05:27:16Z","receivedAt":"2009-06-04T05:27:16Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hi Bert,\n\nOn Tue, Jun 02, 2009 at 10:40:38PM +0200, Bert Wesarg wrote:\n> We currently check fo these files only in the working tree. But we should check\n> what would be commited. We use write-tree to be able to utilize ls-tree and\n> check the result.\n<nitpick> I prefer not speaking about \"us\" in the commit log.  Better\nuse passive voice. </nitpick>  So what about:\n\nThe pre-commit hook used to check that the working copy has the .top*\nfiles.  Instead of that assert that the tree that is about to be\ncommited has these files.\n\n> +# I suspect this can't fail, but who knows\n> +tree=$(git write-tree) ||\n> +\tdie \"Can't write tree\"\nActually you don't need to write the tree.  You can use:\n\n\tgit cat-file -t :0:.topdeps\n\t-> blob\n\n\tgit cat-file blob :0:.topdeps | grep .\n\nUp to now I only shortly looked at your patches, but they seem to be OK.\nI hope I get around to push the changes later today.\n\nBest regards\nUwe\n\n-- \nPengutronix e.K.                              | Uwe Kleine-König            |\nIndustrial Linux Solutions                    | http://www.pengutronix.de/  |\n"},{"id":"115445","messageId":"36ca99e90906041429o32dcc093sccaa2fba21fddd10@mail.gmail.com","threadId":"19657","inReplyTo":"20090604052716.GA24414@pengutronix.de","subject":"Re: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-06-04T21:29:15Z","receivedAt":"2009-06-04T21:29:15Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"2009/6/4 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:\n> Hi Bert,\nHi Uwe,\n\n>\n> On Tue, Jun 02, 2009 at 10:40:38PM +0200, Bert Wesarg wrote:\n>> We currently check fo these files only in the working tree. But we should check\n>> what would be commited. We use write-tree to be able to utilize ls-tree and\n>> check the result.\n> <nitpick> I prefer not speaking about \"us\" in the commit log.  Better\n> use passive voice. </nitpick>  So what about:\n>\n> The pre-commit hook used to check that the working copy has the .top*\n> files.  Instead of that assert that the tree that is about to be\n> commited has these files.\nYes, thats right, Your message is nice, you can use it for the commit.\n\n>\n>> +# I suspect this can't fail, but who knows\n>> +tree=$(git write-tree) ||\n>> +     die \"Can't write tree\"\n> Actually you don't need to write the tree.  You can use:\n>\n>        git cat-file -t :0:.topdeps\n>        -> blob\n>\n>        git cat-file blob :0:.topdeps | grep .\nHmm, not very nice:\n\n$ git init\nInitialized empty Git repository in /home/bertw/tmp/has-file/.git/\n$ touch .topdeps\n$ git add .topdeps\n$ git commit -m.topdeps\n[master (root-commit) 8193982] .topdeps\n 0 files changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 .topdeps\n$ git rm .topdeps\nrm '.topdeps'\n$ git cat-file -t :0:.topdeps\nfatal: Not a valid object name :0:.topdeps\n$ echo $?\n128\n$ git cat-file blob :0:.topdeps | grep .\nfatal: Not a valid object name :0:.topdeps\n$ echo $?\n1\n\nMy proposal:\n\n$ git ls-tree --long \"$(git write-tree)\" .topdeps\n$ echo $?\n0\n\nHere I know, that all git commands don't die(), they all succeed. The\n.topdeps file, I'm looking for, is not in the tree, i.e. empty output.\n\nBert\n\n> Best regards\n> Uwe\n"}]}