SVN提交的时候是可以在服务端做检查的,例如:
1、不允许空信息
2、不允许更改tags目录
3、不允许删除trunk
等等。它这些功能是通过操作系统的脚本实现的,例如windows里,建一个pre-commit.bat文件,放到服务端的hook目录就完成了。
基本原则是返回0表示检查通过,其他表示失败,而且还可以通过echo把错误信息反馈给客户端。其反馈语法类似于:
echo "this is a test" 1>&2 exit 1
其中 1>&2 表示输出到stderr,svn会捕获此信息并反馈到客户端。
参考网址:https://www.techtalk7.com/svn-pre-commit-hook-for-avoiding-changes-to-tags-subdirectories
Windows端的几个功能:
@echo off rem This pre-commit hook will block commits with no log messages and blocks commits on tags. rem Users may create tags, but not modify them. rem If the user is an Administrator the commit will succeed. rem Specify the username of the repository administrator rem commits by this user are not checked for comments or tags rem Recommended to change the Administrator only when an admin commit is neccessary rem then reset the Administrator after the admin commit is complete rem this way the admin user is only an administrator when neccessary set Administrator=Administrator setlocal rem Subversion sends through the path to the repository and transaction id. set REPOS=%1% set TXN=%2% :Main rem check if the user is an Administrator svnlook author %REPOS% -t %TXN% | findstr /r "^%Administrator%$" >nul if %errorlevel%==0 (exit 0) rem Check if the commit has an empty log message svnlook log %REPOS% -t %TXN% | findstr . > nul if %errorlevel% gtr 0 (goto CommentError) rem Block deletion of branches and trunk svnlook changed %REPOS% -t %TXN% | findstr /r "^D.*trunk/$ ^D.*branches/$" >nul if %errorlevel%==0 (goto DeleteBranchTrunkError) rem Check if the commit is to a tag svnlook changed %REPOS% -t %TXN% | findstr /r "^.*tags/" >nul if %errorlevel%==0 (goto TagCommit) exit 0 :DeleteBranchTrunkError echo. 1>&2 echo Trunk/Branch Delete Error: 1>&2 echo Only an Administrator may delete the branches or the trunk. 1>&2 echo Commit details: 1>&2 svnlook changed %REPOS% -t %TXN% 1>&2 exit 1 :TagCommit rem Check if the commit is creating a subdirectory under tags/ (tags/v1.0.0.1) svnlook changed %REPOS% -t %TXN% | findstr /r "^A.*tags/[^/]*/$" >nul if %errorlevel% gtr 0 (goto CheckCreatingTags) exit 0 :CheckCreatingTags rem Check if the commit is creating a tags/ directory svnlook changed %REPOS% -t %TXN% | findstr /r "^A.*tags/$" >nul if %errorlevel% == 0 (exit 0) goto TagsCommitError :CommentError echo. 1>&2 echo Comment Error: 1>&2 echo Your commit has been blocked because you didn't enter a comment. 1>&2 echo Write a log message describing your changes and try again. 1>&2 exit 1 :TagsCommitError echo. 1>&2 echo %cd% 1>&2 echo Tags Commit Error: 1>&2 echo Your commit to a tag has been blocked. 1>&2 echo You are only allowed to create tags. 1>&2 echo Tags may only be modified by an Administrator. 1>&2 echo Commit details: 1>&2 svnlook changed %REPOS% -t %TXN% 1>&2 exit 1
其实git也可以,具体大家研究,目前公司内部只用了SVN。