{"thread":{"id":"17960","subject":"Getting diff in commit-msg hook?","startedAt":"2009-02-22T21:03:45Z","lastAt":"2009-02-23T18:58:59Z","messageCount":3,"participants":["Gerd Knops","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"105826","messageId":"loom.20090222T205429-30@post.gmane.org","threadId":"17960","inReplyTo":null,"subject":"Getting diff in commit-msg hook?","fromName":"Gerd Knops","fromEmail":"gerti-git@bitart.com","sentAt":"2009-02-22T21:03:45Z","receivedAt":"2009-02-22T21:03:45Z","isPatch":false,"sender":{"key":"gerti-git@bitart.com","avatar":null},"body":"When I commit certain files, I would like to send a diff via email to\ninterested parties.\n\nSo I added a commit-msg hook, which checks the list of files for that commit.\nThat part works fine. However in the email I would like to include a\ndiff of the file(s) in question.\n\nNow when I run \"git diff -- '$file'\", I get no output, probably because the\nfile is in some semi-committed state.\n\nSo how can I obtain a diff for a file in a commit-msg hook?\n\nThanks\n\nGerd\n"},{"id":"105837","messageId":"7vhc2lx4mc.fsf@gitster.siamese.dyndns.org","threadId":"17960","inReplyTo":"loom.20090222T205429-30@post.gmane.org","subject":"Re: Getting diff in commit-msg hook?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-23T02:35:07Z","receivedAt":"2009-02-23T02:35:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Gerd Knops <gerti-git@bitart.com> writes:\n\n> When I commit certain files, I would like to send a diff via email to\n> interested parties.\n>\n> So I added a commit-msg hook, which checks the list of files for that commit.\n> That part works fine. However in the email I would like to include a\n> diff of the file(s) in question.\n>\n> Now when I run \"git diff -- '$file'\", I get no output, probably because the\n> file is in some semi-committed state.\n>\n> So how can I obtain a diff for a file in a commit-msg hook?\n\nHow are you getting the list of files for the commit in that commit-msg\nhook?  I think you are doing something like\n\n\t\"git diff --cached --name-only\"\n\nThe new state you are committing is in the index, and \"the diff for the\ncommit\" is \"what is the difference between the state of the previous\ncommit and the state of this commit records\", so\n\n\t\" git diff --cached\"\n\nshould give you what you want (and you do not need to do that per path.\n\nHaving said all that, I imagine you would realize that you do not want to\ndo this inside any of the hooks triggered by \"git commit\", as you learn to\nwork with git more.  I suspect you would probably find a hook triggered\nwhen you push into another repository is more appropriate place for doing\nthis kind of thing.\n"},{"id":"105934","messageId":"D857B1FF-A49F-4158-852A-FCCB19FFD06C@bitart.com","threadId":"17960","inReplyTo":"7vhc2lx4mc.fsf@gitster.siamese.dyndns.org","subject":"Re: Getting diff in commit-msg hook?","fromName":"Gerd Knops","fromEmail":"gerti-git@bitart.com","sentAt":"2009-02-23T18:58:59Z","receivedAt":"2009-02-23T18:58:59Z","isPatch":false,"sender":{"key":"gerti-git@bitart.com","avatar":null},"body":"\nOn Feb 22, 2009, at 8:35 PM, Junio C Hamano wrote:\n\n> Gerd Knops <gerti-git@bitart.com> writes:\n>\n>> When I commit certain files, I would like to send a diff via email to\n>> interested parties.\n>>\n>> So I added a commit-msg hook, which checks the list of files for  \n>> that commit.\n>> That part works fine. However in the email I would like to include a\n>> diff of the file(s) in question.\n>>\n>> Now when I run \"git diff -- '$file'\", I get no output, probably  \n>> because the\n>> file is in some semi-committed state.\n>>\n>> So how can I obtain a diff for a file in a commit-msg hook?\n>\n> How are you getting the list of files for the commit in that commit- \n> msg\n> hook?  I think you are doing something like\n>\n> \t\"git diff --cached --name-only\"\n>\nActually I was parsing the comments from the proposed log message, but  \nthat\nwas a bad idea as there are no comments when using \"git commit -m  \nmsg\". The\nabove command works much better, thanks!\n\n> The new state you are committing is in the index, and \"the diff for  \n> the\n> commit\" is \"what is the difference between the state of the previous\n> commit and the state of this commit records\", so\n>\n> \t\" git diff --cached\"\n>\n> should give you what you want (and you do not need to do that per  \n> path.\n>\nI could swear I tried that... Anyhow, working as advertised. Thanks  \nagain!\n\n\n> Having said all that, I imagine you would realize that you do not  \n> want to\n> do this inside any of the hooks triggered by \"git commit\", as you  \n> learn to\n> work with git more.  I suspect you would probably find a hook  \n> triggered\n> when you push into another repository is more appropriate place for  \n> doing\n> this kind of thing.\n\nYou are right, it would make more sense to have a hook on the remote\n(subversion) repository, but for various reasons it is much easier for\nme to add a hook on my end. Ideally I'd have a local hook for\n\"git svn dcommit\" that would let me get the list of committed files,\nfilter for the ones I am interested in and email the diff. But I was\nnot able to find such a hook.\n\nThanks for your help!\n\nGerd\n"}]}