Wim*_*uwe 40 svn tags pre-commit svn-hooks
有没有人有关于如何添加预提交钩子的明确说明,以避免更改标签子目录?
我已经在互联网上搜索了一下.我发现这个链接:SVN :: Hooks :: DenyChanges,但我似乎无法编译.
api*_*ein 39
我没有足够的声誉对Raim上面的答案进行"评论",但是他的表现很好,除了一个例外,他的grep模式是错误的.
我只是使用下面作为我的预提交钩子(我没有现有的,在这种情况下你需要合并):
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/opt/local/bin/svnlook
# Committing to tags is not allowed
$SVNLOOK changed -t "$TXN" "$REPOS" | grep "^U\W.*\/tags\/" && /bin/echo "Cannot commit to tags!" 1>&2 && exit 1
# All checks passed, so allow the commit.
exit 0
Run Code Online (Sandbox Code Playgroud)
Raim的grep模式唯一的问题是它只匹配"标签",如果它位于你的回购的"根".由于我在repo中有几个项目,因此编写脚本时允许在标记分支上进行提交.
另外,请确保按照指示chmod + x,否则你会认为b/c提交失败,但它失败b/c它无法执行预提交钩子,而不是因为钩子工作.
这非常棒,感谢Raim.比所有其他建议更好,更轻的重量,因为它没有依赖!
rai*_*mue 16
这是一个简短的shell脚本,用于防止在创建标记后提交标记:
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
# Committing to tags is not allowed
$SVNLOOK changed -t "$TXN" "$REPOS" | grep "^U\W*tags" && /bin/echo "Cannot commit to tags!" 1>&2 && exit 1
# All checks passed, so allow the commit.
exit 0
Run Code Online (Sandbox Code Playgroud)
将此保存hooks/pre-commit为您的Subversion存储库并使其可执行chmod +x.
这是我的Windows批处理文件预提交钩子.如果用户是管理员,则将跳过其他检查.它检查提交消息是否为空,以及提交是否为标记.注意:findstr是其他平台上grep的替代品.
它检查提交是否为标记的方式,首先检查svnlook是否包含"tags /".然后检查svnlook是否更改匹配"^ A.tags / [^ /]/$",这意味着它将检查您是否在tags /下添加新文件夹.
允许用户创建新项目.预提交钩子允许用户创建文件夹trunk/tags /和branches /.不允许用户删除文件夹trunk/tags /和branches /.这适用于单个或多个项目存储库.
@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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
53350 次 |
| 最近记录: |