简体   繁体   English

尝试创建一个预提交的挂钩来验证外部

[英]Trying to create a pre-commit hook that verify externals

I am currently trying to create a pre-commit hook that prevent user to tag a version of code with external that are not tags. 我目前正在尝试创建一个预提交的挂钩,以防止用户使用外部而非标签来标记版本的代码。

I am just trying to figure out a way to get the external that are specify in a transaction but cant figure out how. 我只是想找出一种方法来获取在事务中指定的外部,但无法弄清楚如何。 The command svnlook dont seem to be able to return anything that remotely look like externals modification. svnlook命令似乎无法返回任何看起来像外部修改的内容。 And with the svn command it seem to be the transaction that I am unable to specify. 使用svn命令似乎是我无法指定的事务。 I have no idea what command to use in my pre-commit hook. 我不知道在预提交挂钩中使用什么命令。 I am currently in windows but making a python script to be able to test this on our linux server. 我目前在Windows中,但是正在制作python脚本,以便能够在我们的linux服务器上对其进行测试。

What I tested so far is the following : 到目前为止,我测试了以下内容:

svnlook propget C:\TestReposLocal svn:externals <== Give me error something is missing

svn propget svn:externals C:\Test    <== Give me externals but I cant figure out how to get this from a transaction to place in a pre-commit hook.

In my repository (C:\\TestReposLocal) I have one external that is the trunk of another repository. 在我的存储库(C:\\ TestReposLocal)中,我有一个外部存储库,它是另一个存储库的主干。 This repository is displayed with the svn propget command but I need to know with the current transaction in a pre-commit if this external is something else than a Tag. 该存储库与svn propget命令一起显示,但是我需要在预提交中了解当前事务,如果此外部不是Tag之外。

Any help would be gladly receive. 任何帮助将很高兴得到。

Tnx TNX

Well, I can't see really your trouble-point here 好吧,我真的看不到你的麻烦点

  • Any (almost any) operation in pre-commit hook with transaction (and local repo) can be performed with svnlook 可以使用svnlook执行带有事务(和本地回购)的预提交挂钩中的任何(几乎任何)操作
  • svnlook have subcommand propget, with can operate on transaction level and extract any property from any path inside repo (transaction in this case), and you must already know, there you can meet externals inside repo-tree svnlook具有子命令propget,具有可以在事务级别操作并从repo内的任何路径(在这种情况下为事务处理)中提取任何属性的方法,并且您必须已经知道,在那里可以在repo-tree内遇到外部对象
  • you can identify correct|needed format of externals from any previous revision inside repo 您可以从repo内的任何先前版本中识别出正确的外部格式。

Edit 编辑

OK, I see: additional details is needed here. 好的,我知道了:这里需要其他详细信息。 For tests and experimenting I used open repository Proving Ground for externals on Assembla , which have PEG-ed revision in tags and not PEG-ed in trunk. 为了进行测试和实验,我在Assembla上使用了开放式存储库Provision Ground for Externals ,该外部存储库在标签中进行了PEG版本的修改,而在主干中未进行PEG版本的修改。 In order to use svnlook locally I just svnrdump'ed it into local repository. 为了在本地使用svnlook,我只是将其svnrdump's到了本地存储库中。

  • Nearest equivalent to getting property from transaction is getting it from committed revision. 与从事务中获取属性最接近的是从已提交的修订中获取属性。

Tag 1.0.1 was created with r7 标记1.0.1是使用r7创建的

>svnlook pg rep svn:externals tags/1.0.1/ -r 7
-r 2 https://subversion.assembla.com/svn/subversion-trouble-shooting/trunk/lib@2 lib

where: 哪里:

  1. rep is relative path to repository on local filesystem rep是本地文件系统上存储库的相对路径
  2. tags/1.0.1/ is path inside repository, for which I previously know, that it should have definition tags/1.0.1/是存储库中的路径,我之前知道它应该具有定义
  3. -r 7 is revision, which I want to test -r 7是修订,我要测试

Tag was created from trunk, in which external is not binded to specific revision 标签是从主干创建的,其中外部未绑定到特定版本

>svnlook pg rep svn:externals trunk/ -r 6
https://subversion.assembla.com/svn/subversion-trouble-shooting/trunk/lib lib

You'll have to see difference in specification now 您现在必须看到规格差异

WARNING : format of externals-definition will be different in case of using ancient (pre 1.4) SVN-clients and can be slightly different (can't recall exact details) in case of using CLI-version of SVN or SVN-integration from IDE (definitions above I created with TortoiseSVN), but it will be your part of job 警告 :如果使用旧版(1.4版之前)的SVN客户端, 外部定义的格式将有所不同;如果使用CLI版本的SVN或IDE中的SVN集成,则外部定义的格式可能会稍有不同(无法回忆确切的细节) (以上是我用TortoiseSVN创建的定义),但这将是您工作的一部分

  • I order to apply business logic of hook only when it needed (for commits in /tags only) and finish commits faster, you have also check in hook (at early stages) additional condition - is this commit tag-related or not. 我命令仅在需要钩子时才应用钩子的业务逻辑(仅适用于/ tags中的提交),并更快地完成提交,您还需要签入钩子(在早期阶段)其他条件-此提交标记是否相关。 It's again svnlook and dirs-changed subcommand 再次是svnlook和dirs-changed子命令

dirs-changed for commit into tags dirs-changed为提交到标签中

>svnlook dirs-changed rep -r 7
tags/
tags/1.0.1/

dirs-changed for commit into other location dirs-changed为提交到其他位置

>svnlook dirs-changed rep -r 6
trunk/

you can |grep tags in good OS, do some tricks in Windows, operate according to results 您可以在良好的操作系统上|grep tags ,在Windows中做一些技巧,并根据结果进行操作

PS: Don't forget replace -r with -t on production and store transaction-id+repo-path, which you'll get as parameters for hook PS:别忘了在生产中用-t替换-r并存储transaction-id + repo-path,您将获得它作为钩子的参数

This just work for me 这对我有用

REPOS="$1"
TXN="$2"

SVNLOOK=svnlook

Grep_In_List()
{
    EX_STATUS=1

    while read line
    do
        echo "$line" | grep "$1" > /dev/null
        if [[ $? == 0 ]]
        then
            echo "$line"
            EX_STATUS=0
        fi
    done

    exit $EX_STATUS
}


CHANGED_PATHS=$($SVNLOOK dirs-changed -t "$TXN" "$REPOS" | Grep_In_List "^tags")

if [[ $? != 0 ]]
then
# no tags
    exit 0
fi

CHANGED_SUB_PATHS=$(echo $CHANGED_PATHS | xargs -I {} $SVNLOOK tree "$REPOS" "{}" --full-paths -t "$TXN" | sort | uniq | xargs -I {} echo "{}\n")
CHANGED_EXTERNALS=$(echo $CHANGED_SUB_PATHS | xargs -I {} $SVNLOOK pg "$REPOS" svn:externals "{}" -t "$TXN" 2>/dev/null | xargs -I {} echo "{}")

while read external
do
    echo "$external" | grep ' -r' > /dev/null
    if [[ $? != 0 ]]
    then
        echo "$external does not have an explicit revision number" 1>&2
        exit 1
    fi
done <<<"$CHANGED_EXTERNALS"

# all tags correct
exit 0

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

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