[MDEV-6278] Create post-commit git hook to send commit emails Created: 2014-05-28  Updated: 2014-10-28  Resolved: 2014-10-28

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Elena Stepanova Assignee: Elena Stepanova
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-5240 Create 10.1 on github Closed

 Description   

There is a post-commit hook in git, all that's needed is a script that would send an email including the commit diff.

Contents of the README file:

Commit notification e-mail
--------------------------
 
To configure commit notification e-mails for the first time, do the following:
 
- the following should be done regardless commit notification:
  = install git;
  = run git config --global user.name "<Your Name>"
  = run git config --global user.email "<your email>"
- clone/pull this tree (further it's location is <this tree>);
- create a folder <git templates>;
- symlink <this tree>/git_template/hooks to <git templates path>/hooks;
- configure git templates location globally:
  = for git versions >= 1.7.1, run 
    git config --global init.templatedir <git templates path>
  = for older git versions, set the environmemnt variable 
    GIT_TEMPLATE_DIR=<git templates path> 
    and make sure it is always set whenever you work with git;
- run git config --global hooks.postcommitrecipients "<comma-separated list of addresses to send emails to>;
- run git config --global hooks.postcommitbranches "<space-separated list of branches> (* wildcard is allowed)
- optionally:
  = run git config --global hooks.postcommitsender <e-mail to send notifications from> 
  = run git config --global hooks.postcommitmailer <path to mailer> 
    if anything other than /usr/sbin/sendmail is to be used
- make sure <this tree>/git_template/hooks/post-commit-email is executable;
 
Example (most common set of commands):
 
bzr branch lp:mariadb-tools 
mkdir $HOME/.git_template/
ln -s `pwd`/mariadb-tools/git_template/hooks $HOME/.git_template/hooks
git config --global init.templatedir $HOME/.git_template
git config --global hooks.postcommitrecipients "commits@mariadb.org"
git config --global hooks.postcommitbranches "*"
 
From now on, for all new clones of branches listed in hooks/postcommitbranches, 
commit notifications should be sent. 
 
If you had already cloned some trees before enabling commit notifications, 
you will need to amend those trees:
 
cd <cloned folder>
rm -rf .git/hooks
ln -s <this tree>/git_template/hooks .git/hooks
 
 
To disable commit notification(s), set SKIP_COMMIT_EMAIL environment variable 
to a non-empty value or set hooks.postcommitbranches to an empty value.
 
 
Notes:
 
- hooks/postcommitrecipients is a *comma-separated* list of e-mails. Normally, 
  it is expected to contain the commit mailing list, but you can add some other
  address(es) or change it if you wish;
- hooks/postcommitbranches is a *space-separated* list of branches affected 
  by the post-commit hook. Asterisk wildcard is allowed. 
  Please note that these are *real* git branches, as opposed to branch nicknames. 
 
Examples:
 
Assuming you did the following
  git clone https://github.com/MariaDB/server 10.1-mdev1234
  ...
  git branch
  # * 10.1
  git commit -a
 
 Example 1:
  postcommitbranches = 10.0 10.1 10.2
  # The commit e-mail will be sent because the current branch is 10.1, 
  # it's on the list
 
  Example 2:
  postcommitbranches = 10.0-* 10.1-* 10.2-*
  # The commit e-mail won't be sent because the current branch is 10.1, 
  # it does not match the pattern 10.1-*
 
  Example 3:
  postcommitbranches = 10*
  # The commit e-mail will be sent
 



 Comments   
Comment by Elena Stepanova [ 2014-06-04 ]

Hi Kristian,

Could you please do a quick review?
The commit email was sent to the list, otherwise the code can be found here:
https://github.com/elenst/mariadb-toolbox/tree/master/git_template

Comment by Kristian Nielsen [ 2014-06-04 ]

I've mailed a review. I think it looks good as is, just had a couple suggestions for more verbose messages when the commit mail is skipped.

Comment by Elena Stepanova [ 2014-06-04 ]

Pushed to mariadb-tools at launchpad:
http://bazaar.launchpad.net/~maria-captains/mariadb-tools/trunk/files/head:/git_template/
http://bazaar.launchpad.net/~maria-captains/mariadb-tools/trunk/revision/259

and to elenst/mariadb-toolbox at github:
https://github.com/elenst/mariadb-toolbox/tree/master/git_template

Comment by Elena Stepanova [ 2014-09-20 ]

The official tree for the hook is currently on mariadb-tools on lp: http://bazaar.launchpad.net/~maria-captains/mariadb-tools
The script: http://bazaar.launchpad.net/~maria-captains/mariadb-tools/trunk/view/head:/git_template/hooks/post-commit
README file: http://bazaar.launchpad.net/~maria-captains/mariadb-tools/trunk/view/head:/git_template/README

Generated at Thu Feb 08 07:10:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.