利用VBS实现pre-commit对提交注释的检查(样例实现的是对长度的检查)。
1.钩子调用脚本内容
cscript.exe d:/pre-commit.vbs %1 %2
2.钩子处理脚本内容
'必须显式声明变量 Private Args Set wshShell = WScript.CreateObject("WScript.Shell") Dim MaxArgs '调用主要处理流程 '******************************************************************************* Call ArgsErr End Sub 'Main() end sub 'ErrExit() If (Args.Count < MaxArgs) Then '在系统信息中记录此错误信息(事件查看器) '错误返回 End Sub 'ArgsErr() '******************************************************************************* Dim sReposPath, sRevision, sCommand, sLog
'*******************************************************************************
'* NAME : pre-lock.vbs
'* AUTHOR : 杨瑞(OscarYang)
'* CREATED : 2010-3-19
'*
'* PURPOSE : 实现提交日志检查
'*
'*
'* pre-commit hook arguments:
'* [1] REPOS-PATH (the path to this repository)
'* [2] TXN-NAME (the name of the txn about to be committed)
'*******************************************************************************
Option Explicit
Public wshShell,logExec
Set Args = WScript.Arguments
MaxArgs = 2
Call Main
'Main()过程定义
'*******************************************************************************
Private Sub Main()
Call CheckLog
'*******************************************************************************
'出错退出函数,统一进行资源释放
'*******************************************************************************
private sub ErrExit()
Set Args = Nothing
Set wshShell = Nothing
Set logExec =Nothing
'错误返回
WScript.Quit (1)
'*******************************************************************************
'参数出错处理
'*******************************************************************************
Private Sub ArgsErr()
wshShell.LogEvent 1, "缺少参数个数!"
'错误信息输出到客户端
WScript.StdErr.WriteLine ("缺少参数个数!")
Call ErrExit()
End If
'日志检查
'*******************************************************************************
Private Sub CheckLog()
sReposPath = cstr(Args(0))
sRevision = cstr(Args(1))
'合成svnlook 命令
sCommand = "svnlook log " + sReposPath + " -t " + sRevision
Set logExec = wshShell.Exec(sCommand)
'读取svnlook log命令返回结果
Do While Not logExec.StdOut.AtEndOfStream
sLog = logExec.StdOut.ReadAll()
loop
if len(sLog)<=10 then
WScript.StdErr.WriteLine ("日志信息不足!")
Call ErrExit()
end if
End Sub