Git: post-receive email hook, including diff patches?
Asked Answered
M

6

22

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 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!

Murky answered 29/4, 2009 at 22:42 Comment(0)
S
21

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.

Softshoe answered 30/4, 2009 at 13:18 Comment(4)
Bombe, I've tried setting the following on the command line without any luck. # git config --global hooks.showrev "git show -C %s; echo"Murky
Never mind, you can't add it to --global, it has to be just git config, otherwise your solution is right, thanks!Murky
I had no problems setting all necessary configuration values in the global settings.Softshoe
Or, to configure the number of lines of context around the change: "git show -U20 -C %s; echo", where -U20 specifies, for example, twenty lines of context before and after each line diff.Dourine
S
2

I had similar issues here:

Git hook to send email notification on repo changes

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?

Saccharin answered 24/11, 2009 at 13:44 Comment(0)
G
1

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:

Genethlialogy answered 29/4, 2009 at 22:58 Comment(3)
Hi Dustin. Do you happen to have your modifications that made the output look similar to that of the screenshots above?Murky
I'm pretty sure that's what the gist link in my first sentence is. If not, then no. :(Genethlialogy
Unfortunately, not everyone can view your screenshots. When I click on one of the links, it shows me a page where you need to sign in to Evernote, and your screenshots are not visible there.Nabila
H
1

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
Henden answered 29/4, 2009 at 23:1 Comment(2)
Hi robin. I tried both of the mods above and do not get diff output still.Murky
Right, I forgot the "-p" option in both versions.Henden
S
1

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

Stylograph answered 7/8, 2010 at 3:56 Comment(0)
P
1

Here you have another in case you are interested with colors etc: https://github.com/nacho/email-hook

Pithecanthropus answered 27/9, 2012 at 21:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.