简体   繁体   English

Subversion的预提交挂钩失败

[英]Pre-commit hook for Subversion fails

I need most basic hook to prevent empty comment checkins. 我需要最基本的挂钩来防止空注释签入。 Googled, found sample bash script. 用Google搜索,找到示例bash脚本。 Made it short and here is what I have: 简而言之,这就是我所拥有的:

#!/bin/sh

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

# 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

Now I'm testing it with Tortoise SVN and here is what I see: 现在,我正在使用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. 提交失败(详细信息如下):提交被预提交钩子(退出代码1)阻止,其输出为:/ home / svn / repos / apress / hooks / pre-commit:第11行::找不到命令不允许空日志消息。 Please provide a proper log message. 请提供适当的日志消息。 This error was generated by a custom hook script on the Subversion server. 此错误是由Subversion服务器上的自定义钩子脚本生成的。 Please contact your server administrator for help with resolving this issue. 请与您的服务器管理员联系以获取解决此问题的帮助。

What is the error? 有什么错误? svnlook is in /usr/bin I'm very new to Linux, don't understand what happens.. svnlook在/ usr / bin中,我是Linux的新手,不明白会发生什么。

To debug your script you'll have to run it manually. 要调试脚本,您必须手动运行它。 To do that you'll have to get the sample values for the parameters passed to it. 为此,您必须获取传递给它的参数的样本值。 Change the beginning of your script to something like 将脚本的开头更改为

#!/bin/sh

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

echo "REPOS = $REPOS, TXN = $TXN" >/tmp/svnhookparams.txt

Do a commit and check the file /tmp/svnhookparams.txt for the values. 提交并检查文件/tmp/svnhookparams.txt中的值。

Then do another change to the script: 然后对脚本进行另一个更改:

#!/bin/sh

set -x

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

This will enable echo of all commands run by the shell. 这将启用由Shell运行的所有命令的回显。

Now run you script directly from terminal passing to it the values you got previously. 现在,直接从终端运行脚本,将先前获得的值传递给它。

Check the output for invalid commands or empty variable assignments. 检查输出中是否有无效命令或空变量分配。 If you have problems with that, post the output here. 如果您对此有疑问,请在此处发布输出。

$PATH is empty when running hook scripts. 运行挂钩脚本时, $PATH为空。 Thus you need to specify full paths for every external command. 因此,您需要为每个外部命令指定完整路径。 My guess, is that grep is not found. 我的猜测是找不到grep

I'm answering my own question. 我在回答我自己的问题。

This didn't work: 这不起作用:

$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0

It had to be 1 line: 必须是1行:

$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM