Subversion 的预提交挂钩失败
Pre-commit hook for Subversion fails
我需要最基本的钩子来防止空评论签入。用谷歌搜索,找到示例 bash 脚本。简而言之,这就是我所拥有的:
#!/bin/sh
REPOS=""
TXN=""
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
ICONV=/usr/bin/iconv
SVNLOOKOK=1
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
if [ $SVNLOOKOK = 0 ]; then
echo "Empty log messages are not allowed. Please provide a proper log message." >&2
exit 1
fi
# Comments should have more than 5 characters
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c)
if [ "$LOGMSG" -lt 6 ]; then
echo -e "Please provide a meaningful comment when committing changes." 1>&2
exit 1
fi
现在我正在使用 Tortoise SVN 对其进行测试,这是我所看到的:
Commit failed (details follow): Commit blocked by pre-commit hook
(exit code 1) with output: /home/svn/repos/apress/hooks/pre-commit:
line 11: : command not found Empty log messages are not allowed.
Please provide a proper log message. This error was generated by a
custom hook script on the Subversion server. Please contact your
server administrator for help with resolving this issue.
错误是什么? svnlook 在 /usr/bin
我是 Linux 的新手,不明白发生了什么..
要调试您的脚本,您必须手动 运行 它。
为此,您必须获取传递给它的参数的示例值。
将脚本的开头更改为
#!/bin/sh
REPOS=""
TXN=""
echo "REPOS = $REPOS, TXN = $TXN" >/tmp/svnhookparams.txt
提交并检查文件 /tmp/svnhookparams.txt
中的值。
然后对脚本做另一个修改:
#!/bin/sh
set -x
REPOS=""
TXN=""
这将启用 shell 对所有命令 运行 的回显。
现在 运行 您可以直接从终端编写脚本,将您之前获得的值传递给它。
检查输出是否存在无效命令或空变量赋值。
如果您对此有疑问,post 此处的输出。
$PATH
当运行 钩子脚本时为空。因此,您需要为每个外部命令指定完整路径。我的猜测是未找到 grep
。
我在回答我自己的问题。
这没有用:
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
必须是 1 行:
$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
我需要最基本的钩子来防止空评论签入。用谷歌搜索,找到示例 bash 脚本。简而言之,这就是我所拥有的:
#!/bin/sh
REPOS=""
TXN=""
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
ICONV=/usr/bin/iconv
SVNLOOKOK=1
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
if [ $SVNLOOKOK = 0 ]; then
echo "Empty log messages are not allowed. Please provide a proper log message." >&2
exit 1
fi
# Comments should have more than 5 characters
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c)
if [ "$LOGMSG" -lt 6 ]; then
echo -e "Please provide a meaningful comment when committing changes." 1>&2
exit 1
fi
现在我正在使用 Tortoise SVN 对其进行测试,这是我所看到的:
Commit failed (details follow): Commit blocked by pre-commit hook (exit code 1) with output: /home/svn/repos/apress/hooks/pre-commit: line 11: : command not found Empty log messages are not allowed. Please provide a proper log message. This error was generated by a custom hook script on the Subversion server. Please contact your server administrator for help with resolving this issue.
错误是什么? svnlook 在 /usr/bin 我是 Linux 的新手,不明白发生了什么..
要调试您的脚本,您必须手动 运行 它。 为此,您必须获取传递给它的参数的示例值。 将脚本的开头更改为
#!/bin/sh
REPOS=""
TXN=""
echo "REPOS = $REPOS, TXN = $TXN" >/tmp/svnhookparams.txt
提交并检查文件 /tmp/svnhookparams.txt
中的值。
然后对脚本做另一个修改:
#!/bin/sh
set -x
REPOS=""
TXN=""
这将启用 shell 对所有命令 运行 的回显。
现在 运行 您可以直接从终端编写脚本,将您之前获得的值传递给它。
检查输出是否存在无效命令或空变量赋值。 如果您对此有疑问,post 此处的输出。
$PATH
当运行 钩子脚本时为空。因此,您需要为每个外部命令指定完整路径。我的猜测是未找到 grep
。
我在回答我自己的问题。
这没有用:
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
必须是 1 行:
$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0