{"thread":{"id":"50466","subject":"git commit --verbose shows incorrect diff when pre-commit hook is used to modify files","startedAt":"2019-02-11T21:28:12Z","lastAt":"2019-03-03T01:18:56Z","messageCount":4,"participants":["Fernando Chorney","Sergey Lukashev","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"369039","messageId":"CANFDZM5=ffu-=H=vrO3Kr0t2km-3Zg4=msYUWqqJQKGxGojnqA@mail.gmail.com","threadId":"50466","inReplyTo":"CANFDZM7fsbwwqhyWTzfivm4L=GgtCMfCi+DekZurs+SFGqaOjw@mail.gmail.com","subject":"git commit --verbose shows incorrect diff when pre-commit hook is used to modify files","fromName":"Fernando Chorney","fromEmail":"djsbx@djsbx.com","sentAt":"2019-02-11T21:27:59Z","receivedAt":"2019-02-11T21:28:12Z","isPatch":false,"sender":{"key":"djsbx@djsbx.com","avatar":null},"body":"Hi,\n\nI am trying to use a pre-commit hook to modify files before they are\nto be committed. The problem I am running into is that if I use \"git\ncommit --verbose\", which I often do so that I can see the diff, the\ndiff it displays in the editor is the diff before the pre-commit hook\nwas run rather than what the diff would be after the pre-commit was\nrun.\n\nI would like to note, that the pre-commit hook is definitely running,\nbut when git grabs the diff seems to be in the wrong place.\n\nI have set up a simple example on my github to show the problem.\nhttps://github.com/fchorney/pre-commit-example\n\nIs this intended behaviour, or perhaps an issue?\n\n Thanks,\n Fernando Chorney\n"},{"id":"369046","messageId":"31924311549922691@sas1-d856b3d759c7.qloud-c.yandex.net","threadId":"50466","inReplyTo":"CANFDZM5=ffu-=H=vrO3Kr0t2km-3Zg4=msYUWqqJQKGxGojnqA@mail.gmail.com","subject":"Re: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files","fromName":"Sergey Lukashev","fromEmail":"lukashev.s@ya.ru","sentAt":"2019-02-11T22:04:51Z","receivedAt":"2019-02-11T22:04:55Z","isPatch":false,"sender":{"key":"lukashev.s@ya.ru","avatar":null},"body":"At the time you see the diff the committing of changes has not yet been initiated. It's only after you type in the message that the ACTUAL committing starts and the hook runs.\n\nYou can print the diff of what your hook has changed by running \"git diff\" in it before adding changes.\n\n12.02.2019, 00:28, \"Fernando Chorney\" <djsbx@djsbx.com>:\n> Hi,\n>\n> I am trying to use a pre-commit hook to modify files before they are\n> to be committed. The problem I am running into is that if I use \"git\n> commit --verbose\", which I often do so that I can see the diff, the\n> diff it displays in the editor is the diff before the pre-commit hook\n> was run rather than what the diff would be after the pre-commit was\n> run.\n>\n> I would like to note, that the pre-commit hook is definitely running,\n> but when git grabs the diff seems to be in the wrong place.\n>\n> I have set up a simple example on my github to show the problem.\n> https://github.com/fchorney/pre-commit-example\n>\n> Is this intended behaviour, or perhaps an issue?\n>\n>  Thanks,\n>  Fernando Chorney\n\n"},{"id":"370241","messageId":"CANFDZM68A96YprMKhaHNfPRAtK18ad6Bo9=uesxHN=-tLONn=g@mail.gmail.com","threadId":"50466","inReplyTo":"31924311549922691@sas1-d856b3d759c7.qloud-c.yandex.net","subject":"Re: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files","fromName":"Fernando Chorney","fromEmail":"djsbx@djsbx.com","sentAt":"2019-02-26T15:32:06Z","receivedAt":"2019-02-26T15:32:20Z","isPatch":false,"sender":{"key":"djsbx@djsbx.com","avatar":null},"body":"Hmm looks like I forgot to send my reply to this back to the mailing list.\n\n\"Hmm, so I currently have it set to run vim as my commit editor, and\nenter the message in there most of the time. I can definitely see\noutput from the hook into the shell before my vim editor loads up that\nshows me the diff and lets me add in the commit message. This leads me\nto believe that the pre-commit hook is being run before the editor\n(with the diff) pops up.\"\n\nDoes anybody else have any insight to this issue?\n\nOn Mon, Feb 11, 2019 at 4:04 PM Sergey Lukashev <lukashev.s@ya.ru> wrote:\n>\n> At the time you see the diff the committing of changes has not yet been initiated. It's only after you type in the message that the ACTUAL committing starts and the hook runs.\n>\n> You can print the diff of what your hook has changed by running \"git diff\" in it before adding changes.\n>\n> 12.02.2019, 00:28, \"Fernando Chorney\" <djsbx@djsbx.com>:\n> > Hi,\n> >\n> > I am trying to use a pre-commit hook to modify files before they are\n> > to be committed. The problem I am running into is that if I use \"git\n> > commit --verbose\", which I often do so that I can see the diff, the\n> > diff it displays in the editor is the diff before the pre-commit hook\n> > was run rather than what the diff would be after the pre-commit was\n> > run.\n> >\n> > I would like to note, that the pre-commit hook is definitely running,\n> > but when git grabs the diff seems to be in the wrong place.\n> >\n> > I have set up a simple example on my github to show the problem.\n> > https://github.com/fchorney/pre-commit-example\n> >\n> > Is this intended behaviour, or perhaps an issue?\n> >\n> >  Thanks,\n> >  Fernando Chorney\n>\n"},{"id":"370483","messageId":"xmqqmumc69hf.fsf@gitster-ct.c.googlers.com","threadId":"50466","inReplyTo":"CANFDZM68A96YprMKhaHNfPRAtK18ad6Bo9=uesxHN=-tLONn=g@mail.gmail.com","subject":"Re: git commit --verbose shows incorrect diff when pre-commit hook is used to modify files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-03-03T01:18:52Z","receivedAt":"2019-03-03T01:18:56Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Chorney <djsbx@djsbx.com> writes:\n\n> Hmm looks like I forgot to send my reply to this back to the mailing list.\n>\n> \"Hmm, so I currently have it set to run vim as my commit editor, and\n> enter the message in there most of the time. I can definitely see\n> output from the hook into the shell before my vim editor loads up that\n> shows me the diff and lets me add in the commit message. This leads me\n> to believe that the pre-commit hook is being run before the editor\n> (with the diff) pops up.\"\n>\n> Does anybody else have any insight to this issue?\n\nI do not know if it counts as an insight, but the pre-* hooks, not\nlimited to pre-commit, were invented for the purpose of validating\nthe input to an operation so that the hooks can _reject_ if the\noutcome anticipated does not satisfy project's conventions; the\npurpose they were invented was not because the operations wanted to\nallow the input to them.  So attempting to modify the tree in\npre-commit hook, for example, is outside the scope of its design and\nI wouldn't be surprised if you get an unexpected result.\n"}]}