{"thread":{"id":"3711","subject":"Bug encountered while comitting","startedAt":"2006-03-24T18:39:51Z","lastAt":"2006-03-25T10:23:15Z","messageCount":7,"participants":["Matthias Kestenholz","Andreas Ericsson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"17886","messageId":"20060324183951.GA23193@spinlock.ch","threadId":"3711","inReplyTo":null,"subject":"Bug encountered while comitting","fromName":"Matthias Kestenholz","fromEmail":"lists@irregular.ch","sentAt":"2006-03-24T18:39:51Z","receivedAt":"2006-03-24T18:39:51Z","isPatch":false,"sender":{"key":"lists@irregular.ch","avatar":null},"body":"Hello list,\n\nI don't know if this is the right place to report a bug, but I'll\njust try and see what comes back.\n\nI am trying to build a Wiki [1] using PHP, a hacked version of Markdown,\nand git for content tracking. I use the git core plumbing to do the\nhistory work.\n\nThe PHP script created directories under .git/objects which were\nonly writable by www-data. There were other directories which were\nowned by user mk and group www-data, and they were group writable.\n\nSo, I had write access to only a part of the .git directory.\n\nWhen I tried to commit, I got a message saying \"Unable to write sha1\nfilename\".\n\nThe result was, that only part of the commit was recorded and that I\nexperienced repository corruption. refs/heads/master pointed to a\nnon-existant object.\n\nThe expected behavior would have been an error message telling me I\nhad insufficient write privileges and surely no repository\ncorruption.\n\n\n\nThanks,\nMatthias\n\n\n[1]: http://spinlock.ch/cgi-bin/gitweb.pl?p=swisdk2/bugs.git;a=tree\n(See Wiki_ctrl.php for source)\n\n\n-- \n:wq\n"},{"id":"17892","messageId":"442449E1.5060007@op5.se","threadId":"3711","inReplyTo":"20060324183951.GA23193@spinlock.ch","subject":"Re: Bug encountered while comitting","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-03-24T19:34:57Z","receivedAt":"2006-03-24T19:34:57Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Matthias Kestenholz wrote:\n> Hello list,\n> \n> I don't know if this is the right place to report a bug, but I'll\n> just try and see what comes back.\n> \n> I am trying to build a Wiki [1] using PHP, a hacked version of Markdown,\n> and git for content tracking. I use the git core plumbing to do the\n> history work.\n> \n> The PHP script created directories under .git/objects\n\n\nOuch... You're not really supposed to do that. The proper thing to do is \nto do things in the working tree and commit them to git later.\n\n\n> which were\n> only writable by www-data. There were other directories which were\n> owned by user mk and group www-data, and they were group writable.\n> \n> So, I had write access to only a part of the .git directory.\n> \n\nUnless you're using the git tools (or things hooking in to the git core \nC functions somehow), don't touch the .git directory.\n\n(this merits an exclamation marks, so brace yourselves) !\n\n\n> When I tried to commit, I got a message saying \"Unable to write sha1\n> filename\".\n> \n\nWhat file were you trying to write?\n\n> The result was, that only part of the commit was recorded and that I\n> experienced repository corruption. refs/heads/master pointed to a\n> non-existant object.\n> \n\nDid you use git tools to update .git/refs/heads/master ?\n\n\n> The expected behavior would have been an error message telling me I\n> had insufficient write privileges and surely no repository\n> corruption.\n> \n\nDidn't you get the strerror(3) message from that? If so, I'd consider it \na bug.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"17895","messageId":"7vacbfzc3u.fsf@assigned-by-dhcp.cox.net","threadId":"3711","inReplyTo":"20060324183951.GA23193@spinlock.ch","subject":"Re: Bug encountered while comitting","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-03-24T22:55:49Z","receivedAt":"2006-03-24T22:55:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Kestenholz <lists@irregular.ch> writes:\n\n> The PHP script created directories under .git/objects which were\n> only writable by www-data. There were other directories which were\n> owned by user mk and group www-data, and they were group writable.\n>\n> So, I had write access to only a part of the .git directory.\n\ncore.sharedrepository perhaps?\n\nWhile it probably is not a good idea to have you in www-data, it\nappears that is essentially you will end up doing, because PHP\nscripts that may _create_ new directories better not to have\nprivilege to give newly created directories away to you (busting\nyour quota), so they will be owned by www-data.www-data and for\nyou to be able to write into it you either need to be www-data\nuser or in www-data group, with core.sharedrepostiory set.\n"},{"id":"17898","messageId":"20060325011527.GA23600@spinlock.ch","threadId":"3711","inReplyTo":"7vacbfzc3u.fsf@assigned-by-dhcp.cox.net","subject":"Re: Bug encountered while comitting","fromName":"Matthias Kestenholz","fromEmail":"lists@irregular.ch","sentAt":"2006-03-25T01:15:27Z","receivedAt":"2006-03-25T01:15:27Z","isPatch":false,"sender":{"key":"lists@irregular.ch","avatar":null},"body":"* Junio C Hamano (junkio@cox.net) wrote:\n> Matthias Kestenholz <lists@irregular.ch> writes:\n> \n> > The PHP script created directories under .git/objects which were\n> > only writable by www-data. There were other directories which were\n> > owned by user mk and group www-data, and they were group writable.\n> >\n> > So, I had write access to only a part of the .git directory.\n> \n> core.sharedrepository perhaps?\n> \n> While it probably is not a good idea to have you in www-data, it\n> appears that is essentially you will end up doing, because PHP\n> scripts that may _create_ new directories better not to have\n> privilege to give newly created directories away to you (busting\n> your quota), so they will be owned by www-data.www-data and for\n> you to be able to write into it you either need to be www-data\n> user or in www-data group, with core.sharedrepostiory set.\n> \n\nThanks for your answer; I did not know about this option (I should\nprobably re-read all the docs).\n\nAnyway, I think git should never corrupt a repository, even if it\ndoes not have the write permissions it needs.\n\nThe following commands were sufficient to create a corrupt\nrepository with git (v1.2.4-1, debian package):\n\n$ git-init-db\n$ echo test > file\n$ git-update-index --add file ; git commit -m 'message'\n\nrepeat (f.e. 10 times):\n$ echo test >> file\n$ git-update-index file ; git commit -m 'message'\n\n$ sudo chown root .git/objects/*\n\nrepeat the modification and commit commands until you get a message\nsimilar to the following:\n\nunable to write sha1 filename .git/objects/90/b33..: Permission denied\nfatal: 90b33... is not a valid 'tree' object\nunable to write sha1 filename .git/objects/ba/fe4..: Permission denied\nerror: file: failed to insert into database\nfatal: Unable to process file file\netc...\n\nThe result of this all is: refs/heads/master might now point to a\nnon-existant commit object. Every git command now errors out with:\n\nfatal: bad tree object HEAD\n\nand git-log shows no output (probably since it does not find a\ncommit to begin with)\n\n\ngit-commit should abort as soon as it encounters an error and not\nupdate HEAD.\n\nThanks,\nMatthias\n\n(Note: To find the last valid commit object, I could just scan the\nobjects directory for the recently modified files and write the sha1\nvalue to refs/heads/master, so I had no data loss.)\n\n\n\n-- \n:wq\n"},{"id":"17897","messageId":"20060325011530.GA25951@spinlock.ch","threadId":"3711","inReplyTo":"442449E1.5060007@op5.se","subject":"Re: Bug encountered while comitting","fromName":"Matthias Kestenholz","fromEmail":"lists@irregular.ch","sentAt":"2006-03-25T01:15:30Z","receivedAt":"2006-03-25T01:15:30Z","isPatch":false,"sender":{"key":"lists@irregular.ch","avatar":null},"body":"* Andreas Ericsson (ae@op5.se) wrote:\n> Matthias Kestenholz wrote:\n> >\n> >The PHP script created directories under .git/objects\n> \n> \n> Ouch... You're not really supposed to do that. The proper thing to do is \n> to do things in the working tree and commit them to git later.\n> \n\nI think I did not express myself clearly. The PHP Script executes\ngit commands which in turn create or modify the mentioned\ndirectories. I do not create them myself by hand.\n\n> >When I tried to commit, I got a message saying \"Unable to write sha1\n> >filename\".\n> >\n> \n> What file were you trying to write?\n> \n\nSome file I was updating (in this case, a file holding some wiki\ncontent)\n\n> >The result was, that only part of the commit was recorded and that I\n> >experienced repository corruption. refs/heads/master pointed to a\n> >non-existant object.\n> >\n> \n> Did you use git tools to update .git/refs/heads/master ?\n> \n\nYes.\n\n> \n> >The expected behavior would have been an error message telling me I\n> >had insufficient write privileges and surely no repository\n> >corruption.\n> >\n> \n> Didn't you get the strerror(3) message from that? If so, I'd consider it \n> a bug.\n\nAs I (only now) wrote in the other email, I got the\n\"Permission denied\" message, and that was a sufficient hint what was\nwrong.\n\n-- \n:wq\n"},{"id":"17908","messageId":"7vwtejxd3u.fsf@assigned-by-dhcp.cox.net","threadId":"3711","inReplyTo":"20060325011527.GA23600@spinlock.ch","subject":"Re: Bug encountered while comitting","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-03-25T06:17:09Z","receivedAt":"2006-03-25T06:17:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthias Kestenholz <lists@irregular.ch> writes:\n\n> $ sudo chown root .git/objects/*\n>\n> repeat the modification and commit commands until you get a message\n> similar to the following:\n>\n> unable to write sha1 filename .git/objects/90/b33..: Permission denied\n> fatal: 90b33... is not a valid 'tree' object\n> unable to write sha1 filename .git/objects/ba/fe4..: Permission denied\n> error: file: failed to insert into database\n> fatal: Unable to process file file\n> etc...\n>\n> The result of this all is: refs/heads/master might now point to a\n> non-existant commit object. Every git command now errors out with:\n>\n> fatal: bad tree object HEAD\n>\n> and git-log shows no output (probably since it does not find a\n> commit to begin with)\n\nYou are right.  commit-tree does not seem to check if it\nsuccessfully wrote the commit object.  How about this?\n\n-- >8 --\ndiff --git a/commit-tree.c b/commit-tree.c\nindex 88871b0..16c1787 100644\n--- a/commit-tree.c\n+++ b/commit-tree.c\n@@ -125,7 +125,10 @@ int main(int argc, char **argv)\n \twhile (fgets(comment, sizeof(comment), stdin) != NULL)\n \t\tadd_buffer(&buffer, &size, \"%s\", comment);\n \n-\twrite_sha1_file(buffer, size, \"commit\", commit_sha1);\n-\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n-\treturn 0;\n+\tif (!write_sha1_file(buffer, size, \"commit\", commit_sha1)) {\n+\t\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n+\t\treturn 0;\n+\t}\n+\telse\n+\t\treturn 1;\n }\n"},{"id":"17924","messageId":"20060325102314.GA3825@spinlock.ch","threadId":"3711","inReplyTo":"7vwtejxd3u.fsf@assigned-by-dhcp.cox.net","subject":"Re: Bug encountered while comitting","fromName":"Matthias Kestenholz","fromEmail":"lists@irregular.ch","sentAt":"2006-03-25T10:23:15Z","receivedAt":"2006-03-25T10:23:15Z","isPatch":false,"sender":{"key":"lists@irregular.ch","avatar":null},"body":"* Junio C Hamano (junkio@cox.net) wrote:\n> You are right.  commit-tree does not seem to check if it\n> successfully wrote the commit object.  How about this?\n> \n> -- >8 --\n> diff --git a/commit-tree.c b/commit-tree.c\n> index 88871b0..16c1787 100644\n> --- a/commit-tree.c\n> +++ b/commit-tree.c\n> @@ -125,7 +125,10 @@ int main(int argc, char **argv)\n>  \twhile (fgets(comment, sizeof(comment), stdin) != NULL)\n>  \t\tadd_buffer(&buffer, &size, \"%s\", comment);\n>  \n> -\twrite_sha1_file(buffer, size, \"commit\", commit_sha1);\n> -\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n> -\treturn 0;\n> +\tif (!write_sha1_file(buffer, size, \"commit\", commit_sha1)) {\n> +\t\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n> +\t\treturn 0;\n> +\t}\n> +\telse\n> +\t\treturn 1;\n>  }\n\nThis patch fixes the problem I was encountering (git-update-ref is\nnot executed anymore).\n\nThank you all for this really great tool!\n\n\n-- \n:wq\n"}]}