简体   繁体   English

SVN预提交挂钩中的用户验证

[英]Users validation in SVN pre-commit hook

Found one of the useful SVN pre-commit hook in SVN pre-commit hook for avoiding changes to tags subdirectories by mcdon. 在SVN预提交钩子中找到了一个有用的SVN预提交钩子, 以避免 mcdon 更改标签子目录

I want to add the validation check on the user before committing. 我想在提交之前在用户上添加验证检查。 Can I do something like below? 我可以做下面的事情吗?

@echo off
REM  user1, user2, user3 are example
set VALID_USERS=user1,user2,user3

set SVNROOT="C:\Program Files\CollabNet Subversion Server\svnlook.exe"
set REPOS=%1%
set TXN=%2%

%SVNROOT% author %REPOS% -t %TXN% | findstr /r "^%VALID_USERS%$" >nul
if %errorlevel% EQU 0 (
   echo This is an invalid user 1>&2
   exit 1
) else (
   echo This is valid user 1>&2
   exit 0
)

The above pre-commit script failed as all users can commit their files. 上面的预提交脚本失败,因为所有用户都可以提交其文件。 Also, the 'echo' command not working as I don't see any echo statement above. 另外,'echo'命令不起作用,因为我在上面看不到任何echo语句。 Can anyone help? 有人可以帮忙吗?

I don't understand why you should want a pre-commit hook for that, so I give you a sketch what we are using when working on tags. 我不明白为什么要为此使用一个预先提交的钩子,所以我给您一个草图,供我们在处理标签时使用。

  1. We use the Subversion path-based authorization , and have rules like that: 我们使用基于Subversion 路径的授权 ,并且具有如下规则:

     [/tags] * = r @R_SVN_ADMINS = rw 

    so only admins are allowed to create and modify tags. 因此,仅允许管理员创建和修改标签。

  2. If necessary, we add for each tag a rule to avoid modification: 如有必要,我们为每个标签添加一条规则以避免修改:

     [/tags/r1.0] @R_SVN_ADMINS = r 
  3. An alternative solution is to modify the rules in the first point after creation, so that tags are only read-only. 一种替代解决方案是在创建后的第一点修改规则,以使标记仅是只读的。

This works for us because tags are created seldomly, and we don't have much of them. 这对我们有用,因为很少创建标签,而且我们没有太多标签。 We don't need any hooks to forbid something ... 我们不需要任何钩子来禁止某物...

Found the following solution working: 发现以下解决方案有效:

REM     Block deletion of folder/file in trunk
%SVNLOOK% changed %REPOS% -t %TXN% | findstr /r "^D.*trunk/.*$" >nul
if %errorlevel%==0 (goto DeleteInTrunkError)

REM     DeleteInTrunkError
REM ------------------------
:DeleteTrunkTagsError
echo. 1>&2
echo Trunk Delete Error: 1>&2
echo     Only Administrator can delete in the trunk folder. 1>&2
echo Commit details: 1>&2
%SVNROOT% changed %REPOS% -t %TXN% 1>&2
exit 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM