git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Gerd Knops <gerti-git@bitart.com>
Cc: git@vger.kernel.org
Subject: Re: Getting diff in commit-msg hook?
Date: Sun, 22 Feb 2009 18:35:07 -0800	[thread overview]
Message-ID: <7vhc2lx4mc.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <loom.20090222T205429-30@post.gmane.org> (Gerd Knops's message of "Sun, 22 Feb 2009 21:03:45 +0000 (UTC)")

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.

  reply	other threads:[~2009-02-23  2:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-22 21:03 Getting diff in commit-msg hook? Gerd Knops
2009-02-23  2:35 ` Junio C Hamano [this message]
2009-02-23 18:58   ` Gerd Knops

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vhc2lx4mc.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=gerti-git@bitart.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).