【问题标题】:SVN pre-commit hook linuxSVN 预提交钩子 linux
【发布时间】:2018-05-23 18:37:13
【问题描述】:

我正在尝试创建一个预提交挂钩,它将搜索正在提交的文件与预先确定的字符串,如果它包含它,那么它会在提交之前出错。

尝试在线搜索后出现以下情况:

#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook 
$SVNLOOK diff "$REPOS" -t "$TXN" | [[ grep "^+builder_group">/dev/null exit 0 ]]  ||     
echo "File contains builder_group commit failed"  >&2
exit 1

这是我得到的错误:

svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 2) with output:
/etc/svn/testrepo/hooks/pre-commit: line 7: conditional binary operator expected 
/etc/svn/testrepo/hooks/pre-commit: line 7: syntax error near `"^+cod_bank">'
/etc/svn/testrepo/hooks/pre-commit: line 7: `$SVNLOOK diff "$REPOS" -t "$TXN" | [[ grep "^+builder_group">/dev/null exit 0 ]]  ||'

你能明白为什么它会像现在这样显示错误吗?谢谢你。

【问题讨论】:

    标签: svn tortoisesvn hook pre-commit-hook pre-commit


    【解决方案1】:

    这是我最终不得不将其更改为使其正常工作的内容。

        $SVNLOOK diff -t "$TXN" "$REPOS" | grep -i "builder_group" > /dev/null && { echo "File contains builder_group commit failed." 1>&2; exit 1; }
        exit 0;
    

    根据您在 grep -i "abc123" 之后的字段中的内容,它将搜索文件,如果匹配或包含相同的字母路径,则会导致提交错误。

    例如:如果文件包含 aabc123,它仍然会出错。

    【讨论】:

    • 这是我需要更改的内容,以查找多个字符串值。 $SVNLOOK diff -t "$TXN" "$REPOS" | egrep 'builder_group|test_group|damaged_group' > /dev/null && { echo "文件包含禁止字符串。" 1>&2; 1号出口; } 退出 0;
    猜你喜欢
    • 2014-03-22
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多