svn提交以不允许svn:mergeinfo在非根目录上?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (34)

想使用一个预提交钩子来阻止开发人员在非根目录上设置svn:mergeinfo。也就是说,想强制执行svn:mergeinfo

提问于
用户回答回答于

可以在服务器上使用CPAN:

REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook

if !($SVNLOOK log -t "$TXN" "$REPOS" | grep -q '\[override] ';) then

    # Get list of paths which have changed      
    TXN_PATHS=$($SVNLOOK changed -t "$TXN" "$REPOS")

    # Filter those which are allowed: /trunk, /branches/*,...
    TXN_PATHS=$(echo "$TXN_PATHS" | grep -Ev "^....(trunk/|branches/[^/]+/)$")

    # Iterate over all paths, which are not allowed to have mergeinfo
    while IFS= read -r TXN_PATH; do
      ELEM_PATH=$(echo "$TXN_PATH" | cut -c 5-)

      MERGEINFO=$($SVNLOOK propget "$REPOS" svn:mergeinfo -t "$TXN" "$ELEM_PATH" 2>/dev/null)
      if [ ! "$MERGEINFO" = "" ]; then 
        echo "  Cannot merge into directory that is not trunk or a branch:" >&2;
        echo "  $ELEM_PATH" >&2;
        echo "  Override by using [override]." >&2;
        exit 1;
      fi      
    done <<< "$TXN_PATHS"

    # echo "Merge info check: OK"
fi
用户回答回答于

首先,建议使用perl或python来完成这个任务,windows批处理还有很多不足之处。

可以使用http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/一些示例脚本开始。例如,verify-po.py脚本检查文件编码,commit-access-control.pl.in检查作者是否有权提交。

扫码关注云+社区