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.
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 = [email protected]
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.
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 = [email protected]
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.