简体   繁体   中英

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. 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.

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 ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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