A hook script is a program triggered by some repository event, such as the creation of a new revision or the modification of an unversioned property. Each hook is handed enough information to tell what that event is, what target(s) it's operating on, and the username of the person who triggered the event. Depending on the hook's output or return status, the hook program may continue the action, stop it, or suspend it in some way. Please refer to the chapter on Hook Scripts in the Subversion Book for full details about the hooks which are implemented.
这些钩子脚本被版本库所在的服务器执行。TortoiseSVN 也允许你配置由确定事件触发,在本地执行的客户端脚本。请参看 “客户端钩子脚本”一节 以获得更多信息。
版本库的hooks目录中有一些钩子的例子脚本,这些例子脚本适合于Unix/Linux服务器,在Windows下需要修改。钩子可以是批处理文件或可执行文件,下面是用来实现pre-revprop-change钩子的例子。
rem Only allow log messages to be changed. if "%4" == "svn:log" exit 0 echo Property '%4' cannot be changed >&2 exit 1
请注意所有发送到标准输出的东西都会被忽略,如果你希望信息出现在拒绝提交对话框中,你需要将这些信息发送到标准错误,在一个批处理文件中使用>&2实现。
If a hook script rejects your commit then its decision is final. But you can build an override mechanism into the script itself using the Magic Word technique. If the script wants to reject the operation it first scans the log message for a special pass phrase, either a fixed phrase or perhaps the filename with a prefix. If it finds the magic word then it allows the commit to proceed. If the phrase is not found then it can block the commit with a message like “You didn't say the magic word” :-)