Search code examples
gitdiffhookgitolite

How to get a git diff for a file in a pre-receive hook between the current HEAD and the newest file from the push?


How do I get a git diff in a pre-receive hook between A and B?

  • A. (newest version of somefile.ext as viewed in) current HEAD on server
  • B. (newest version of somefile.ext as viewed in) received tree from pre-receive hook

I need this, because when some files change (on a Gitolite server), we like to be notified and see the difference between A and B by e-mail.

Environment: Ubuntu server 11 + Gitolite + pre-receive hook


Solution

  • I think you actually want to use post-receive, as pre-receive is mostly used to reject updates and post-receive for notifications (which seems what you want to do).

    Both get the same input (through stdin) and it's documented in githooks(5)
    The input is a list of updated refs and their old and new commit hashes.
    You could use this data to do your git diff