简体   繁体   English

如何在SVN中使用预提交钩子将目录创建限制为中继,标签,分支?

[英]How to restrict directory creation to trunk, tags, branches with a pre-commit hook in SVN?

Current setup: 当前设置:

We have approximately 7 repositories in our SVN instance. SVN实例中大约有7个存储库。 Each repository has multiple applications, and each application should have a trunk, tags, and branches directory (nothing else)! 每个存储库都有多个应用程序,每个应用程序应有一个主干,标签和分支目录(别无其他)!

EG: 例如:

 REPOSITORY-1
  --> APP-1
      --> trunk
      --> tags
      --> branches
  --> APP-2
      --> trunk
      --> tags
      --> branches

Overtime I have noticed developers deviating from this process and creating all kinds of directories. 随着时间的流逝,我注意到开发人员偏离了此过程,创建了各种目录。 For example: 例如:

 REPOSITORY-1
   --> APP-1
       --> src
       --> READ-ME.txt
   --> APP-2
       --> build
       --> random-file.java
       --> build.xml

Is there a way to have a hook with a patter that restricts the pattern to reject any commits that try to create any files or directories other than trunk, tags, and branches under the application? 有没有一种方法可以使钩子有一个模式,从而限制该模式以拒绝任何尝试在应用程序下创建除主干,标记和分支以外的任何文件或目录的提交? Thank you in advance for any help! 预先感谢您的任何帮助!

Extra info: Our SVN server is on a RedHat box. 额外信息:我们的SVN服务器在RedHat盒子上。

Add the below script in pre-commit to restrict the directory creation: 在预提交中添加以下脚本以限制目录的创建:

REPOS="$1"
TXN="$2"
DIRCHAR="/"
SVNLOOK=/opt/csvn/bin/svnlook
echo $($SVNLOOK changed -t "$TXN" "$REPOS" | awk '{print $2}') > /tmp/files_$TXN.txt
sed -i 's/ /&\n/g' /tmp/files_$TXN.txt
while read line
do
LASTCHAR=`echo $line | awk '{print substr($0,length,1)}'`
if [ "$LASTCHAR" == "$DIRCHAR" ]; then
    echo -e "Cannot commit directory." 1>&2
    exit 1
fi
done < /tmp/files_$TXN.txt

在预提交的钩子中执行svnlook dirs-changed REPOS_PATH并检查输出(| grep -v ...)

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

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