Hook script templates should already exist, in the /hooks directory inside your repository director. For me, I have several repos in /var/svn. Say I want to set up comment editing for a particular repo named 'svnrepo1'. My hook templates would be in /var/svn/svnrepo1/hooks.
To activate one of the template hooks, simply rename it to match whatever hook it should be with. For example, my pre-revprop-change template was named 'pre-revprop-change.tmpl' - to activate it, I copied (better idea than just moving it) it to 'pre-revprop-change'. Here's the code inside the pre-revprop-change hook:
# 5 ordered arguments are sent to pre-revprop-change:
# [1] path to repository
# [2] the revision being modified
# [3] username of the person editing the revision
# [4] the property being modified
# [5] the action; 'A'dded, 'M'odified, 'D'eleted
# assigning the arguments to named variables
REPO="$1"
REV="$2"
USER="$3"
PROPNAME="$4"
ACTION="$5"
# we only want to allow 'M'odifiying of svn:log.
# No adding or deleting,
# and no changing of other properties
if[ "$ACTION" = "M" -a "$PROPNAME" = "svn:log"]; then exit 0; fi
exit 1That's all. All the pre-revprop-change hook needs to do, is make sure people aren't doing anything they shouldn't do, and then exit 0 if they're being good little kids, and exit 1 if they're breaking the rules. This script can also be easily modified to only allow the original comment's author to change the comment. To do this, just change the "if" statement to look like this:
if [ "$ACTION = "M" -a "$PROPNAME" = "svn:log" -a `svnlook author /path/to/your/repo -r $REV` = "$USER" ]; then exit 0; fiThis uses the svnlook utility to check if the username associated with the revision ($REV) matches the person editing it ($USER)
No comments:
Post a Comment