bash SVN提交后挂钩将消息发送回客户端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8424670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:09:28  来源:igfitidea点击:

SVN post-commit hook sending a message back to client

svnbashstderrpost-commit-hook

提问by CamelBlues

I'm writing a post-commit script in bash, and I'd like to pass messages back to the client who's making a commit. However

我正在用 bash 编写提交后脚本,我想将消息传递回进行提交的客户端。然而

echo my message >&2

isn't making it back to the client. Is it even possible to send messages back with a post-commit hook?

不让它返回给客户。甚至可以使用 post-commit 钩子发回消息吗?

采纳答案by VonC

Condering a post-commit hookdoes:

承认提交后钩子会:

anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures.

钩子打印到 stderr 的任何内容都将被编组回客户端,从而更容易诊断钩子故障。

you can check if this isn't a simple quote issue:

您可以检查这是否不是一个简单的报价问题:

echo "my message" >&2

You can see in those hook examplesthat any echoto >&2includes quotes.

你可以看到那些挂钩的例子,任何echo>&2包括引号。

The bash chapter on redirectionalso includes examples with quotes.

关于重定向bash 章节还包括带引号的示例。

However, as pmoddetails in his answer, that stderr message won't be visible unless the exit status of the script differs from 0, as illustrated in "subversion post-commit hook: print an error message that the user can see?"

但是,作为pmod他的回答中的详细信息,除非脚本的退出状态不同于 0,否则该 stderr 消息将不可见,如“ subversion post-commit hook:print an error message that the user can see?”中所示。

#!/bin/bash
echo "test" >&2
exit 1

回答by pmod

Hook will show STDERR only if it fails (and as you may now, hook doesn't display STDOUT). Thus, you have to return non-zero code from your script to pass "my message" to user (just add exit 1after echo).

Hook 仅在失败时才会显示 STDERR(正如您现在可能看到的,Hook 不显示 STDOUT)。因此,您必须从脚本中返回非零代码以将“我的消息”传递给用户(只需在 echo 后添加exit 1)。

Take a look here:

看看这里

If the post-commit hook returns a nonzero exit status, the commit will not be aborted since it has already completed. However, anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures.

如果提交后挂钩返回非零退出状态,则提交不会中止,因为它已经完成。但是,钩子打印到 stderr 的任何内容都将被编组回客户端,从而更容易诊断钩子故障。

回答by Jens

I had the same problem, with Apache and mod_svn. It turned out that the marshalling fails when the text being marshalled contained &, <or >characters. After substituting them with &amp;, &lt;and &gt;the text got through.

我有同样的问题,Apache 和 mod_svn。事实证明,当被编组的文本包含&,<>字符时,编组会失败。用他们取代后&amp;&lt;&gt;文字得到了通过。