问题
I would like to add a post commit hook so that if a user commits changes to a particular file, I will be notified by email.
Has anyone seen an example of this, or is it possible?
I have set up a pre commit hook before, but that's limit of my knowledge.
回答1:
I have a post-commit hook on github that does exactly this, and it allows the users (instead of the administrator to say what files they're watching for changes, and what email addresses these changes should be sent to.
You can combine this with my pre-commit-kitchen-sink hook to make sure that users can only edit their own watch files. The hook scripts use Perl, but they don't require any non-standard modules, so they're pretty easy to use.
Each user gets their own watch file, the syntax is pretty easy:
mail = david@gmail.com
file =**/build.xml
match = [Mm]akefile
The mail
line is where I want to email the notice. I can have multiple ones. The file
is a glob expression (anchored at the front and back of the expression) of what files I'm watching. The match
line is similar, and uses a Perl regular expression which is unanchored.
The watch files are stored in the Subversion repository in a directory you specify. This means that the users can set their own watches. You can use my pre-commit-kitchen-sink hook to prevent users from changing other users' watch files:
[file You are only allowed to change their own watch files]
file =/watchfiles/**
permission = read-only
users = @ALL
[file You are only allowed to change their own watch files]
file = /watchfiles/<USER>.cfg
permission = read-write
users = @ALL
The <USER>
string is interpreted as the user's ID.
Example
If I want to set post commit hook to more than one files, so can I set? like file = ab/build.xml, bb/cs.txt, cc/. etc I want notification by email of these files only
You can put a line in for each pattern:
email = my@email.com
file = **/ab/build.xml
file = **/bb/cs.txt
file = **/cc/*.*
Remember that file
glob pattern is anchored to the root of the repository (using /
as the root) so you need to specify the full path, or use the **/
to specify any path to that file.
回答2:
In the subversion distribution are several hook scripts which send email. Look in the directories
tools/hook-scripts
contrib/hook-scripts
回答3:
i setup a PHP script to execute with post-commit. You could edit the PHP script to be pretty smart, and depending on which files were udpated do certain actions.
/subversion/hooks/post-commit:
REPOS="$1"
REV="$2"
MESSAGE=$(svnlook propget --revprop -r $REV $REPOS svn:log)
CHANGES=$(svnlook changed -r $REV $REPOS)
php /usr/share/subversion/hook-scripts/commit-email.php "$REPOS" "$REV" "$MESSAGE" "$CHANGES"
/usr/share/subversion/hook-scripts/commit-email.php:
<?php
//files updated will be in $_SERVER['argv'][4], you could expand it in to an a
//array and search for what you need, and depending on what's found, send emails accordingly.
?>
来源:https://stackoverflow.com/questions/7473842/svn-post-commit-hook-to-email-user-when-a-particular-file-is-changed