简体   繁体   English

SVN提交相同消息的预提交钩

[英]SVN Pre-Commit Hook For Identical Messages

My colleagues are very stubborn. 我的同事们很固执。 At the beginning they would commit with no message so I tried to educate them and put in a pre-commit script to check for empty in case they forget. 刚开始时,它们将不带任何消息地提交,因此我尝试对其进行教育,并放入预提交脚本中以检查是否为空,以防它们遗忘。 They would then put in messaged like "fixed" so I spoke to them again and updated the script to force it to link to the bug tracker. 然后,他们会输入“已修复”之类的消息,因此我再次与他们交谈,并更新了脚本以强制其链接到错误跟踪器。 Now they are putting in the same commit message 8 times in a row for the same file (Bug ID: Bug Title). 现在他们将同一文件连续提交8次相同的提交消息(错误ID:Bug标题)。

After I talk to them about how this isn't helpful, how can I make a pre-commit hook that checks that the commit message isn't identical to one of the last 20 commit messages? 在与他们讨论这无济于事之后,我如何制作一个预提交钩子来检查提交消息是否与最后20条提交消息之一不同?

You can use SVN commands or any other shell command in pre-commit hooks. 您可以在预提交挂钩中使用SVN命令或任何其他Shell命令。 You just need to provide full paths to the installed tools. 您只需要提供已安装工具的完整路径。 Remember this is running on the server so it has file:// access to the repository. 请记住,它正在服务器上运行,因此它具有对存储库的file://访问。 So do an svnlook log (preferred) or svn log and check the resulting output for a match for the current log message. 因此,请使用svnlook log (首选)或svn log并检查结果输出是否与当前日志消息匹配。

svnlook has 2 options that combined together can sort this out. svnlook有2个选项,将它们组合在一起可以解决此问题。

svnlook log http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.log.html svnlook日志http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.log.html

svnlook youngest http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.youngest.html svnlook最年轻的http://svnbook.red-bean.com/en/1.7/svn.ref.svnlook.c.youngest.html

Youngest gets the head revision. 最年轻的得到头部修订。 I then echo the last 20 commits to an temp. 然后,我将最后20次提交回显到临时。 file and use grep to search for the commit message in the temp. 文件并使用grep在临时目录中搜索提交消息。 file. 文件。

The grep options are F for using a file as input, x to match a whole line and q for quiet. grep选项为F(用于将文件用作输入),x用于匹配整行,q(用于静音)。

    #Prevent people putting in the same commit message multiple times by looking for an identical message in the last 20 commits
    ID=$(svnlook youngest $REPOS)
    COMMITS=/tmp/svncommits.txt
    rm $COMMITS
    for (( i=$ID-20; i<=$ID; i++ ))
    do
        echo $(svnlook log $REPOS -r $i) >> $COMMITS
    done

    if $(grep -Fxq "$COMMIT_MSG" "$COMMITS") ; then
        echo "Please describe what your change is, why you made it and don't use the same commit message every time." 1>&2
        exit 1
    fi

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

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