SVN排除结束文件扩展名预提交挂钩

时间:2018-06-06 14:37:46

标签: svn grep tortoisesvn hook pre-commit

我正在尝试编写一个挂钩来阻止提交,如果它有一个特定的字符串。我已经使用以下代码了。

#!/bin/sh

REPOS="$1"
TXN="$2"
COMPARE=`$SVNLOOK diff -t "$TXN" "$REPOS"`

if echo ${COMPARE} | grep -qw "path/to/file/*"; then
  if         echo ${COMPARE} | egrep "string1"; then
             echo "file contains invalid string string1. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string2"; then
             echo "file contains invalid string string2. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string3"; then
             echo "file contains invalid string string3. Unable to commit"  1>&2
            exit 1
  fi


fi

现在我要做的是排除以“_man.txt”结尾的文件。我知道你必须使用--exclude = * {_ man.txt},但它不会忽略文件,仍然显示我已设置的提交错误回显消息。任何人都可以看到我可能会遗漏什么,为什么?

if echo ${COMPARE} | grep -qw --exclude=\*{_man.txt} "path/to/file/*"; then
  if         echo ${COMPARE} | egrep "string1"; then
             echo "file contains invalid string string1. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string2"; then
             echo "file contains invalid string string2. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string3"; then
             echo "file contains invalid string string3. Unable to commit"  1>&2
            exit 1
  fi


fi

1 个答案:

答案 0 :(得分:0)

这是我必须做的。

for ROUTE in $COMPARE
do
 if [[ "$ROUTE" == *path/to/file* ]]; then

    if [[ "$ROUTE" == *_man.txt* ]]; then
        exit 0
    fi

    if echo ${COMPARE} | grep -qw "path/to/file/*"; then
        if  echo ${COMPARE} | egrep "string1"; then
            echo "string1 cannot be found in file." 1>&2
            exit 1
        fi

        if  echo ${COMPARE} | egrep "string2"; then
            echo "string2 cannot be found in file." 1>&2
            exit 1
        fi

        if  echo ${COMPARE} | egrep "string3"; then
            echo "string3 cannot be found in file." 1>&2
            exit 1
        fi
    fi
fi
done
#Operation 001 Completed