svn 预提交挂钩禁止在非根目录上使用 svn:mergeinfo

发布于 2024-09-10 13:42:00 字数 371 浏览 7 评论 0原文

我想使用预提交挂钩来防止开发人员在非根目录上设置 svn:mergeinfo 。也就是说,我想强制 svn:mergeinfo 只能在“trunk”或“branches/branchName”等目录上设置。有时需要“提醒”开发人员,使用根目录的子目录作为合并目标并不是一个好的做法(根据列出的最佳实践此处)。有谁有这样的钩子脚本或者知道我在哪里可以找到一个?我在 Windows 环境中,所以批处理或 powershell 会更好,但任何东西肯定会有帮助。

I would like to use a pre-commit hook that prevents developers from setting svn:mergeinfo on non-root directories. That is, I want to enforce that svn:mergeinfo can only be set on directories like "trunk" or "branches/branchName". Developers sometimes need to be "reminded" that it's not good practice to use a subdirectory of the root as a merge target (per the best practices listed here). Does anyone have such a hook script or know where I could find one? I am in a windows environment, so batch or powershell would be preferable, but anything would certainly be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2024-09-17 13:42:00

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

您可以使用 http://svn.apache 中的一些示例脚本.org/repos/asf/subversion/trunk/tools/hook-scripts/ 开始。例如,verify-po.py 脚本检查文件编码,commit-access-control.pl.in 检查作者是否具有提交权限。您可能会在脚本中使用 svnlook diff (如后一个)来获取目录的更改属性,并使用正则表达式遍历相应的路径,无论它们是分支还是标记。

更新

找到 enforcer 预提交挂钩脚本 这似乎就是您正在寻找的内容。

这个脚本的作用是使用
svnlook 查看事务
是进步。当它筛选
事务,它调用一组
允许存储库的钩子
管理员检查发生了什么
并决定是否是
可以接受。

它包含多个方法,其中包括 verify_property_line_added(),因为它会为添加到文件属性的每一行调用

First of all, I'd recommend using perl or python to do the task, windows batch leaves much to be desired.

You can use some example script from http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ to start from. For example, verify-po.py script checks file encodings and commit-access-control.pl.in checks whether author has permissions to commit. You'd probably employ svnlook diff in your script (as in the latter one) to get changed properties for directories and go through the corresponding paths whether they're branches or tags using regular expression.

Update

Found enforcer pre-commit hook script which seems to be what you're looking for.

What this script does is it uses
svnlook to peek into the transaction
is progress. As it sifts through the
transaction, it calls out to a set of
hooks which allow the repository
administrator to examine what is going
on and decide whether it is
acceptable.

It contains several methods and verify_property_line_added() among them, since it's called for each line that is added to a property on a file.

东走西顾 2024-09-17 13:42:00

如果您可以在服务器上进行 CPAN:

https://github .com/gnustavo/SVN-Hooks/blob/master/examples/check-mergeinfo.pl

如果没有(基于 http://comments.gmane.org/gmane.comp.version-control.subversion.user/118969):

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

If you can CPAN on the server:

https://github.com/gnustavo/SVN-Hooks/blob/master/examples/check-mergeinfo.pl

If not (based on http://comments.gmane.org/gmane.comp.version-control.subversion.user/118969):

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文