我是Linux和Subversion的新手。我有一项任务是检查提交消息的语法以包含PRODUCT ID。如果它不存在,我已经使用SHELL SCRIPT向用户传递了一个无效格式的消息 以下是我在google中进行大量搜索后遵循的步骤, 对于PRE-COMMIT钩子,代码是:
#!/bin/sh
set -e
/PATH-TO-REPOSITORY/hooks/CommentSyntax.sh "$1" "$2"
我的CommentSyntax.sh脚本是,
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
regex="PRODUCT-[0-9]*"
if [ `"$SVNLOOK" log -t "$TXN" "$REPOS"` =~ ${regex} ]; then
exit 0
else
echo "" 1>&2
echo "Please make your commit comment start with PRODUCT-XXX" 1>&2
exit 1
fi
每当我尝试签入代码时,都会收到以下错误,
srikanth:~/testing$ svn ci -m "PRODUCT-123"
Sending two.java
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
[: 22: PRODUCT-123: unexpected operator
Please make your commit comment start with PRODUCT-XXX
我不确定我哪里出错了。请求您提出宝贵意见。
答案 0 :(得分:0)
test命令不知道=~
运算符。替换
if [ `"$SVNLOOK" log -t "$TXN" "$REPOS"` =~ ${regex} ]; then
排队
if "$SVNLOOK" log -t "$TXN" "$REPOS" | head -n1 | grep -q '^PRODUCT-[0-9][0-9]*' ; then
head -n1
选择提交的第一行,grep
检查正则表达式。