如何防止SVN中包含中文字符的日志消息的提交?

时间:2014-12-30 16:56:43

标签: svn

我可以访问SVN服务器,并在目录 /home/.svn1/hooks

找到 pre-commit.tmpl

我相信这是我要更改的文件,禁止使用中文消息进行提交

文件内容为:

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

# Make sure that the log message contains some text.
SVNLOOK=/usr/local/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
   grep "[a-zA-Z0-9]" > /dev/null || exit 1

# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1

# All checks passed, so allow the commit.
exit 0

如何过滤掉中文字符?

1 个答案:

答案 0 :(得分:1)

不要更改提交消息。如果可能,您可能会改变消息的含义。 更好的方法是防止任何违反规则的提交消息,在您的情况下使用中文字符。

如果有人使用禁用字符,用户将看到一条消息,提交将被拒绝。

这可以通过预提交挂钩轻松完成。

因此,在 .svn / hooks文件夹中创建预提交文件。 使用svnlook检查提交的不同参数。 做一个svnlook -h来看看还能做些什么。

一个简单的例子,检查是否有任何字符不在ASCII范围内:

#!/bin/sh

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

FOUND=$(svnlook log -t "$TXN" "$REPOS" | tr -d '\n' | grep  "[^\x00-\x7F]" )

if [ "$FOUND" != "" ]
then
    exit 0
else 
    echo "Reject commit! Do not use non ASCCI in commit messages!" 1>&2 && exit 1
fi