{"thread":{"id":"25701","subject":"is it kosher for pre-commit to change what's staged?","startedAt":"2010-11-10T17:08:19Z","lastAt":"2010-11-11T22:06:53Z","messageCount":9,"participants":["Joey Hess","Junio C Hamano","Jonathan Nieder","Dmitry Potapov","Jan Hudec","Kevin Ballard"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"155599","messageId":"20101110170819.GA3031@gnu.kitenet.net","threadId":"25701","inReplyTo":null,"subject":"is it kosher for pre-commit to change what's staged?","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2010-11-10T17:08:19Z","receivedAt":"2010-11-10T17:08:19Z","isPatch":false,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"I've noticed that if I make a pre-commit hook change the files that are\nstaged, those changes are not reflected in the commit message. For\nexample, if a pre-commit hook git add's somefile, the commit message\nwon't reflect that. I guess prepare-commit-msg is being run before\npre-commit for some reason?\n\n-- \nsee shy jo\n"},{"id":"155617","messageId":"7v1v6thrzc.fsf@alter.siamese.dyndns.org","threadId":"25701","inReplyTo":"20101110170819.GA3031@gnu.kitenet.net","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-10T19:57:11Z","receivedAt":"2010-11-10T19:57:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <joey@kitenet.net> writes:\n\n> I've noticed that if I make a pre-commit hook change the files that are\n> staged, those changes are not reflected in the commit message. For\n> example, if a pre-commit hook git add's somefile, the commit message\n> won't reflect that. I guess prepare-commit-msg is being run before\n> pre-commit for some reason?\n\nMy intention was that Documentation/githooks.txt would document things\nthat are allowed (e.g. \"applypatch-msg\" explicitly says \"The hook is\nallowed to edit the message\"), and anything that is not specifically\nallowed is not.\n\n\"Is it kosher\" is a difficult question to answer, as something may not be\nallowed but there may not be an enforcement mechanism to deny it, iow, it\nmay happen to work by accident.\n\nIn general, pre-anything is about checking and denying and is supposed to\nbe free of side effects.\n"},{"id":"155619","messageId":"20101110200650.GA13439@burratino","threadId":"25701","inReplyTo":"7v1v6thrzc.fsf@alter.siamese.dyndns.org","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-10T20:06:50Z","receivedAt":"2010-11-10T20:06:50Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Junio C Hamano wrote:\n> Joey Hess <joey@kitenet.net> writes:\n\n>> I've noticed that if I make a pre-commit hook change the files that are\n>> staged, those changes are not reflected in the commit message. For\n>> example, if a pre-commit hook git add's somefile, the commit message\n>> won't reflect that. I guess prepare-commit-msg is being run before\n>> pre-commit for some reason?\n\nI'm guessing it is to allow cancelling a commit before a costly\npre-commit hook runs.\n\n> My intention was that Documentation/githooks.txt would document things\n> that are allowed (e.g. \"applypatch-msg\" explicitly says \"The hook is\n> allowed to edit the message\"), and anything that is not specifically\n> allowed is not.\n> \n> \"Is it kosher\" is a difficult question to answer, as something may not be\n> allowed but there may not be an enforcement mechanism to deny it, iow, it\n> may happen to work by accident.\n\nIn this case, isn't it only a half accident?  For example, I think\nv1.5.4-rc0~78^2~12 (builtin-commit: fix partial-commit support,\n2007-11-18) taught git to support this a little better.\n\nThat said, I would be interested to hear the use case, since modifying\nstaged content on the fly for a commit sounds a little crazy. :)\n"},{"id":"155625","messageId":"20101110204542.GA11201@gnu.kitenet.net","threadId":"25701","inReplyTo":"20101110200650.GA13439@burratino","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2010-11-10T20:45:42Z","receivedAt":"2010-11-10T20:45:42Z","isPatch":false,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Jonathan Nieder wrote:\n> In this case, isn't it only a half accident?  For example, I think\n> v1.5.4-rc0~78^2~12 (builtin-commit: fix partial-commit support,\n> 2007-11-18) taught git to support this a little better.\n\nPartial commits modified by pre-commit still don't work entirely right IME.\nAfter the commit, the index is such that git wants to revert any changes\nadded to the commit by the pre-commit hook.\n\n> That said, I would be interested to hear the use case, since modifying\n> staged content on the fly for a commit sounds a little crazy. :)\n\nWell, with git-annex (which I should probably properly announce here\nsometime), large files are not committed to git, but instead a symlink\npointing at the content is committed. That symlink can temporarily be\nreplaced with a copy of the file when the user wants to modify it, and\nif the user then commits, it's nice if it can move away the large file's\ncontent, and arrange for the commit to contain an updated symlink pointing\nat the new content.\n\nThat said, since git commit stages the whole large file into the index,\nwhich is the kind of expensive operation git-annex exists to avoid,\nit's still not very practical to intercept the commit like that. What\nI ideally need is a hook that is run before git commit stages anything.\n\n\nBTW, githooks says pre-commit is \"invoked before obtaining the proposed\ncommit log message\", which is a bit confusing. I actually see\nprepare-commit-msg and commit-msg both called after pre-commit.\n\n-- \nsee shy jo\n"},{"id":"155629","messageId":"AANLkTi=W_hwU=3PTTqE4R8Cg5T=GMdMfBsKQ1YE0HWRe@mail.gmail.com","threadId":"25701","inReplyTo":"20101110204542.GA11201@gnu.kitenet.net","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2010-11-10T22:17:04Z","receivedAt":"2010-11-10T22:17:04Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"On Wed, Nov 10, 2010 at 11:45 PM, Joey Hess <joey@kitenet.net> wrote:\n>\n> That said, since git commit stages the whole large file into the index,\n> which is the kind of expensive operation git-annex exists to avoid,\n> it's still not very practical to intercept the commit like that. What\n> I ideally need is a hook that is run before git commit stages anything.\n\nThen maybe you should look at git smudge&clean filters. They perform\nconversation between the working tree and the index.  Though I am not\nsure how well they work with big files.\n\n\nDmitry\n"},{"id":"155733","messageId":"20101111192648.GE30870@efreet.light.src","threadId":"25701","inReplyTo":"AANLkTi=W_hwU=3PTTqE4R8Cg5T=GMdMfBsKQ1YE0HWRe@mail.gmail.com","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Jan Hudec","fromEmail":"bulb@ucw.cz","sentAt":"2010-11-11T19:26:49Z","receivedAt":"2010-11-11T19:26:49Z","isPatch":false,"sender":{"key":"bulb@ucw.cz","avatar":null},"body":"On Thu, Nov 11, 2010 at 01:17:04 +0300, Dmitry Potapov wrote:\n> On Wed, Nov 10, 2010 at 11:45 PM, Joey Hess <joey@kitenet.net> wrote:\n> >\n> > That said, since git commit stages the whole large file into the index,\n> > which is the kind of expensive operation git-annex exists to avoid,\n> > it's still not very practical to intercept the commit like that. What\n> > I ideally need is a hook that is run before git commit stages anything.\n> \n> Then maybe you should look at git smudge&clean filters. They perform\n> conversation between the working tree and the index.  Though I am not\n> sure how well they work with big files.\n\nThe problem point is not big files, but whether they can change the file mode\nassociated with the entry, since in this case the tree contains a file, but\nindex should contain a symlink. Looking at the documentation, there does not\nseem to be a way to do it.\n\nIt might be worth adding support for it now we have a use-case.\n\n-- \n\t\t\t\t\t\t Jan 'Bulb' Hudec <bulb@ucw.cz>\n"},{"id":"155737","messageId":"20101111204626.GA13937@gnu.kitenet.net","threadId":"25701","inReplyTo":"20101111192648.GE30870@efreet.light.src","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Joey Hess","fromEmail":"joey@kitenet.net","sentAt":"2010-11-11T20:46:26Z","receivedAt":"2010-11-11T20:46:26Z","isPatch":false,"sender":{"key":"joey@kitenet.net","avatar":"https://avatars.githubusercontent.com/u/16392?v=4"},"body":"Jan Hudec wrote:\n> The problem point is not big files, but whether they can change the file mode\n> associated with the entry, since in this case the tree contains a file, but\n> index should contain a symlink. Looking at the documentation, there does not\n> seem to be a way to do it.\n> \n> It might be worth adding support for it now we have a use-case.\n\nI suppose that if I were using smudge filters, I'd probably not need to\nuse symlinks at all. I'll think about it.\n\nIt belatedly occured to me that I already had something else modifying\nthe index in pre-commit, and smudge filters cannot handle its use case.\n\nThat is, etckeeper (http://kitenet.net/~joey/code/etckeeper). The\npre-commit script there stores some metadata about files that git\nusually doesn't track, by putting it in a dotfile, and stages that\ndotfile for commit. Which currently works fine, except for the minor\nproblem that the user doesn't see the dotfile listed in the commit\nmessage.\n\n-- \nsee shy jo\n"},{"id":"155741","messageId":"7vlj4zfrgt.fsf@alter.siamese.dyndns.org","threadId":"25701","inReplyTo":"20101111204626.GA13937@gnu.kitenet.net","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-11-11T22:03:30Z","receivedAt":"2010-11-11T22:03:30Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joey Hess <joey@kitenet.net> writes:\n\n> ... The\n> pre-commit script there stores some metadata about files that git\n> usually doesn't track, by putting it in a dotfile, and stages that\n> dotfile for commit. Which currently works fine, except for the minor\n> problem that the user doesn't see the dotfile listed in the commit\n> message.\n\nI am hearing \"list of files in the commit message\", and am getting\nconfused.  As far as I know we don't store such a list in the commit\nmessage.\n\nPuzzled.\n"},{"id":"155742","messageId":"F0C8038B-0D8C-4A50-9934-9D9CF26FF9F9@sb.org","threadId":"25701","inReplyTo":"7vlj4zfrgt.fsf@alter.siamese.dyndns.org","subject":"Re: is it kosher for pre-commit to change what's staged?","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2010-11-11T22:06:53Z","receivedAt":"2010-11-11T22:06:53Z","isPatch":false,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"On Nov 11, 2010, at 2:03 PM, Junio C Hamano wrote:\n\n> Joey Hess <joey@kitenet.net> writes:\n> \n>> ... The\n>> pre-commit script there stores some metadata about files that git\n>> usually doesn't track, by putting it in a dotfile, and stages that\n>> dotfile for commit. Which currently works fine, except for the minor\n>> problem that the user doesn't see the dotfile listed in the commit\n>> message.\n> \n> I am hearing \"list of files in the commit message\", and am getting\n> confused.  As far as I know we don't store such a list in the commit\n> message.\n> \n> Puzzled.\n\nI believe he means in the # comments at the bottom of the editor. They\ncontain the output of `git status` as a reminder of what you're\ncommitting.\n\n-Kevin Ballard\n"}]}