* Getting diff in commit-msg hook?
@ 2009-02-22 21:03 Gerd Knops
2009-02-23 2:35 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Gerd Knops @ 2009-02-22 21:03 UTC (permalink / raw)
To: git
When I commit certain files, I would like to send a diff via email to
interested parties.
So I added a commit-msg hook, which checks the list of files for that commit.
That part works fine. However in the email I would like to include a
diff of the file(s) in question.
Now when I run "git diff -- '$file'", I get no output, probably because the
file is in some semi-committed state.
So how can I obtain a diff for a file in a commit-msg hook?
Thanks
Gerd
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Getting diff in commit-msg hook?
2009-02-22 21:03 Getting diff in commit-msg hook? Gerd Knops
@ 2009-02-23 2:35 ` Junio C Hamano
2009-02-23 18:58 ` Gerd Knops
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2009-02-23 2:35 UTC (permalink / raw)
To: Gerd Knops; +Cc: git
Gerd Knops <gerti-git@bitart.com> writes:
> When I commit certain files, I would like to send a diff via email to
> interested parties.
>
> So I added a commit-msg hook, which checks the list of files for that commit.
> That part works fine. However in the email I would like to include a
> diff of the file(s) in question.
>
> Now when I run "git diff -- '$file'", I get no output, probably because the
> file is in some semi-committed state.
>
> So how can I obtain a diff for a file in a commit-msg hook?
How are you getting the list of files for the commit in that commit-msg
hook? I think you are doing something like
"git diff --cached --name-only"
The new state you are committing is in the index, and "the diff for the
commit" is "what is the difference between the state of the previous
commit and the state of this commit records", so
" git diff --cached"
should give you what you want (and you do not need to do that per path.
Having said all that, I imagine you would realize that you do not want to
do this inside any of the hooks triggered by "git commit", as you learn to
work with git more. I suspect you would probably find a hook triggered
when you push into another repository is more appropriate place for doing
this kind of thing.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Getting diff in commit-msg hook?
2009-02-23 2:35 ` Junio C Hamano
@ 2009-02-23 18:58 ` Gerd Knops
0 siblings, 0 replies; 3+ messages in thread
From: Gerd Knops @ 2009-02-23 18:58 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Feb 22, 2009, at 8:35 PM, Junio C Hamano wrote:
> Gerd Knops <gerti-git@bitart.com> writes:
>
>> When I commit certain files, I would like to send a diff via email to
>> interested parties.
>>
>> So I added a commit-msg hook, which checks the list of files for
>> that commit.
>> That part works fine. However in the email I would like to include a
>> diff of the file(s) in question.
>>
>> Now when I run "git diff -- '$file'", I get no output, probably
>> because the
>> file is in some semi-committed state.
>>
>> So how can I obtain a diff for a file in a commit-msg hook?
>
> How are you getting the list of files for the commit in that commit-
> msg
> hook? I think you are doing something like
>
> "git diff --cached --name-only"
>
Actually I was parsing the comments from the proposed log message, but
that
was a bad idea as there are no comments when using "git commit -m
msg". The
above command works much better, thanks!
> The new state you are committing is in the index, and "the diff for
> the
> commit" is "what is the difference between the state of the previous
> commit and the state of this commit records", so
>
> " git diff --cached"
>
> should give you what you want (and you do not need to do that per
> path.
>
I could swear I tried that... Anyhow, working as advertised. Thanks
again!
> Having said all that, I imagine you would realize that you do not
> want to
> do this inside any of the hooks triggered by "git commit", as you
> learn to
> work with git more. I suspect you would probably find a hook
> triggered
> when you push into another repository is more appropriate place for
> doing
> this kind of thing.
You are right, it would make more sense to have a hook on the remote
(subversion) repository, but for various reasons it is much easier for
me to add a hook on my end. Ideally I'd have a local hook for
"git svn dcommit" that would let me get the list of committed files,
filter for the ones I am interested in and email the diff. But I was
not able to find such a hook.
Thanks for your help!
Gerd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-02-23 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-22 21:03 Getting diff in commit-msg hook? Gerd Knops
2009-02-23 2:35 ` Junio C Hamano
2009-02-23 18:58 ` Gerd Knops
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).