Reputation: 3428
The post-receive
hook is a well-known mechanism for generating notification e-mails summarising Git commits. However, as far as I know, this hook is only called when commits are git push
-ed into a remote repository.
How do I get Git to send notification e-mails in response to commits made to a local repository, without any pushing to a remote?
I know there is a post-commit
hook, but my impression is that it's used for something else--perhaps validation? Moreover, the stock script is bare, without any obvious linkage to an e-mail script. I doubt one can just copy the standard post-receive
script in its place, as the arguments passed to the post-commit
hook seem to be different than the ones passed to post-receive
.
I'm sure one can come up with some custom script to do this, based solely on the commit ID (presumably available in the internal hook arguments). I'm interested in a simple solution that relies on more or less stock/packaged Git scripts; a small and relatively universal shim. Does such a thing exist?
Upvotes: 1
Views: 60
Reputation: 165416
Pro Git's chapter on Git Hooks covers how to deal with this.
After the entire commit process is completed, the post-commit hook runs. It doesn’t take any parameters, but you can easily get the last commit by running
git log -1 HEAD
. Generally, this script is used for notification or something similar.
Once you've gotten the information you need from HEAD
, you're writing a script that sends email. You may want to fork the process of sending the email else git commit
will wait for it to send slowing the development process. Just be sure to get all your data about HEAD
before you fork and exit else another commit could happen and change HEAD
.
Upvotes: 1
Reputation: 489638
There are no arguments to post-commit
, but it does not need any since the (single) commit that was made, was made wherever HEAD
points now that the commit is done. Read HEAD
: if it's a symbolic ref for a branch, there was one commit made to that branch; if it's a raw SHA-1, there was one commit made with a detached HEAD
; if it's anything else, that's weird. :-)
This is far simpler than post-receive
which may have received a large number of commits, a number of tag objects, and/or multiple reference updates. The post-receive hook email generator must account for a lot more possible cases.
Upvotes: 3