tags:

views:

2279

answers:

5

Hi all,

I found a post-receive hook for Git after some googling that I use to e-mail all commits to a remote/shared repo.

The problem with this post-receive hook (found here: http://bit.ly/19NdKG), is that it only has the capability to provide who made the commit, the log message, date, file(s) affected. I also want to see the affected file(s) generated patches in the e-mail to see what changes were made to the code. Subversion does this rather nicely.

Does anyone have a solution for perhaps an env-variable that may be passed to the post-receive hook that does this? Or even better, an example that is already cooked up?

Thanks all!

+1  A: 

I haven't run it in a while, but (I believe) the one I used to use is online. I took what used to ship with git and rearranged it more for my liking. I haven't tried running anything similar in a long time.

I've got a few screenshots of what it did:

Dustin
Hi Dustin. Do you happen to have your modifications that made the output look similar to that of the screenshots above?
I'm pretty sure that's what the gist link in my first sentence is. If not, then no. :(
Dustin
+1  A: 

See this section.

echo ""
echo "Summary of changes:"
git diff-tree --stat --summary --find-copies-harder $oldrev..$newrev

Here git is asked for the diff, but then it is also asked to summarize it. Remove the --stat and --summary flags and you will see the diff.

git diff-tree --find-copies-harder $oldrev..$newrev

Here is another way that shows all revisions including diffs from $oldrev to $newrev

git --no-pager log --find-copies-harder $oldrev..$newrev
robinr
Hi robin. I tried both of the mods above and do not get diff output still.
Right, I forgot the "-p" option in both versions.
robinr
+7  A: 

Recent Git version should install a post-receive-email script. In it, it says:

hooks.showrev

The shell command used to format each revision in the email, with "%s" replaced with the commit id. Defaults to "git rev-list -1 --pretty %s", displaying the commit id, author, date and log message. To list full patches separated by a blank line, you could set this to "git show -C %s; echo".

So just set hooks.showrev to “git show -C %s; echo” in the repository with the email hook and you’re all set.

Bombe
Bombe, I've tried setting the following on the command line without any luck. # git config --global hooks.showrev "git show -C %s; echo"
Never mind, you can't add it to --global, it has to be just git config, otherwise your solution is right, thanks!
I had no problems setting all necessary configuration values in the global settings.
Bombe
+2  A: 

I had similar issues here:

http://stackoverflow.com/questions/552360/git-push-email-notification/1728717#1728717

Actually there are different versions of the post-receive-email script - the one available on git.kernel.org informs about and respects hooks.showrev, the one I had did not.

But this discussion is cool, thanks, will definitely look at it! The other script linked above also has gitweb link feature and stuff, how are you others doing on that?

UncleCJ
+1  A: 

Even though this question already has an accepted answer, I thought this was one of the nicer post-receive mailer hooks that I've come across:

http://github.com/brasse/post_receive_email.py

Discovered via the author's blog post:

http://copypasteprogrammer.blogspot.com/2010/03/git-post-receive-hook-in-python.html

Yang