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!

mhagger
  • 2,687
  • 18
  • 13

6 Answers6

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.

Bombe
  • 81,643
  • 20
  • 123
  • 127
  • Bombe, I've tried setting the following on the command line without any luck. # git config --global hooks.showrev "git show -C %s; echo" –  Apr 30 '09 at 14:27
  • Never mind, you can't add it to --global, it has to be just git config, otherwise your solution is right, thanks! –  Apr 30 '09 at 14:31
  • I had no problems setting all necessary configuration values in the global settings. – Bombe May 06 '09 at 08:26
  • 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. – Phillip Oct 12 '13 at 23:07
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?

Community
  • 1
  • 1
HiQ CJ
  • 3,406
  • 3
  • 17
  • 11
1

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

nacho
  • 11
  • 1
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

Yang
  • 16,037
  • 15
  • 100
  • 142
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:

Dustin
  • 89,080
  • 21
  • 111
  • 133
  • Hi Dustin. Do you happen to have your modifications that made the output look similar to that of the screenshots above? –  Apr 30 '09 at 01:20
  • I'm pretty sure that's what the gist link in my first sentence is. If not, then no. :( – Dustin Apr 30 '09 at 03:16
  • 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. – Tobias Feil Dec 15 '18 at 11:45
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
robinr
  • 4,376
  • 2
  • 20
  • 18