bash svn:E165001:提交被预提交钩子(退出代码 255)阻止,没有输出。如何解决这个问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33789148/
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 13:54:54  来源:igfitidea点击:

svn: E165001: Commit blocked by pre-commit hook (exit code 255) with no output. How can this be solved?

linuxbashsvnphabricator

提问by foven

I am trying to configure svn with Phabricator. Everything seems to be working so far, except for commiting changes. When I try to commit any code, I get the following error message:

我正在尝试使用 Phabricator 配置 svn。到目前为止,一切似乎都在工作,除了提交更改。当我尝试提交任何代码时,我收到以下错误消息:

svn: E165001: Commit blocked by pre-commit hook (exit code 255) with no output.

Just to be clear, the error message in question is output by the svn client program. It seems to be sent from svnserve when it encounters various issues, such as not being able to run the hook for some reason. It doesn't have to be provided by the hook.

为了清楚起见,有问题的错误消息是由 svn 客户端程序输出的。好像是svnserve遇到各种问题的时候发的,比如因为某些原因不能运行hook。它不必由钩子提供。

If I delete the pre-commit hook, the commits go through as expected.

如果我删除预提交钩子,提交会按预期进行。

For testing purposes, I have created an extremely simple hook, that looks like this:

出于测试目的,我创建了一个非常简单的钩子,如下所示:

#!/bin/sh

echo "testing" >&2
exit 1

I get the same error message when using this hook as well.This being the case, there is not much sense trying to solve for a more complicated script until this one can be made to work. It could very well be that by solving for this script, the original one will work as well. I have been testing with this script and all that I have posted in this question holds true for this script. Basically, at this point in time, the script I have presented really is the script I'm trying to make work.

使用此挂钩时,我也收到相同的错误消息。在这种情况下,尝试解决更复杂的脚本没有多大意义,直到它可以工作为止。很可能通过解决这个脚本,原来的脚本也能正常工作。我一直在用这个脚本进行测试,我在这个问题中发布的所有内容都适用于这个脚本。 基本上,此时此刻,我所展示的脚本确实是我正在尝试制作的脚本。

I have disabled the Phabricator daemons, since otherwise the pre-commit script is overwritten by Phabricator.

我已经禁用了 Phabricator 守护进程,否则预提交脚本会被 Phabricator 覆盖。

The following is some information that I think may be helpful in solving this, based on what I've seen written about this error message so far:

以下是我认为可能有助于解决此问题的一些信息,基于我迄今为止所看到的有关此错误消息的内容:

  • The repository is owned by phd, the user that is running svnserve.
  • The pre-commit hook is set to be executable.
  • 该存储库由运行 svnserve 的用户 phd 所有。
  • 预提交挂钩设置为可执行。
foven@phabricator:~$ sudo ls -la /var/repo/SVN/hooks/
total 60
drwxr-xr-x. 3 phd  phd   4096 Nov 18 13:46 .
drwxr-xr-x. 6 phd  phd   4096 Nov 18 11:27 ..
-rwxr-xr-x. 1 phd  phd   2062 Oct 27 10:17 post-commit.tmpl
-rwxr-xr-x. 1 phd  phd   1638 Oct 27 10:17 post-lock.tmpl
-rwxr-xr-x. 1 phd  phd   2289 Oct 27 10:17 post-revprop-change.tmpl
-rwxr-xr-x. 1 phd  phd   1567 Oct 27 10:17 post-unlock.tmpl
-rwxr-xr-x  1 phd  phd     37 Nov 18 14:39 pre-commit
drwxr-xr-x. 2 phd  phd     19 Nov 17 17:05 pre-commit-phabricator.d
-rwxr-xr-x. 1 phd  phd   3426 Nov 12 15:59 pre-commit.tmpl
-rwxr-xr-x. 1 phd  phd   2434 Oct 27 10:17 pre-lock.tmpl
-rwxr-xr-x. 1 phd  phd   2786 Oct 27 10:17 pre-revprop-change.tmpl
-rwxr-xr-x. 1 phd  phd   2122 Oct 27 10:17 pre-unlock.tmpl
-rwxr-xr-x. 1 phd  phd   3163 Oct 27 10:17 start-commit.tmpl
  • SELinux is disabled/set to permissive:
  • SELinux 被禁用/设置为宽松:
foven@phabricator:~$ sudo getenforce
Disabled
  • I have run dos2unix on the pre-commit hook file:
  • 我在预提交钩子文件上运行了 dos2unix:
foven@phabricator:~$ sudo dos2unix /var/repo/SVN/hooks/pre-commit
dos2unix: converting file /var/repo/SVN/hooks/pre-commit to Unix format...
  • I can run the hook script from the command line as user phd:
  • 我可以以用户 phd 的身份从命令行运行钩子脚本:
[phd@phabricator ~]$ /var/repo/SVN/hooks/pre-commit
testing

Even with an empty environment, which apparently matches how svn hooks are run.

即使有一个空的环境,这显然与 svn hooks 的运行方式相匹配。

[phd@phabricator ~]$ env -i /var/repo/SVN/hooks/pre-commit
testing
  • It seems like the script's shebang is correct:
  • 脚本的shebang似乎是正确的:
[phd@phabricator ~]$ which sh
/bin/sh
[phd@phabricator ~]$ ls -la /bin/sh
lrwxrwxrwx. 1 root root 4 Aug 18 09:37 /bin/sh -> bash
[phd@phabricator ~]$ which bash
/bin/bash
  • I can commit code if the hook is deleted.
  • I can checkout code.
  • 如果钩子被删除,我可以提交代码。
  • 我可以结帐代码。

Update

更新

Based on a discussion in the #svn IRC channel, I tried the following:

根据#svn IRC 频道中的讨论,我尝试了以下操作:

sudo svn mkdir file:///var/repo/SVN/TestFolder -m "Add test folder"

svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
testing

So this implies that the hook can work and may not be at fault at all. Still not sure what the problem is though, so can't totally rule out the hook (could be the hook is mostly fine, but something needs to be changed for it to work with this configuration). It seems likely that the problem lies elsewhere though. Any help is welcome.

所以这意味着钩子可以工作并且可能根本没有错。仍然不确定问题是什么,所以不能完全排除钩子(可能是钩子大部分都很好,但需要改变一些东西才能使用这个配置)。不过,问题似乎出在其他地方。欢迎任何帮助。

回答by Andreas Mattisson

Don't know what changes dos2unix will do, but in my case it was both UTF-8 and LF breaks that was the issue. I use the www-data as owner of the file and not the phpd user.

不知道 dos2unix 会做什么改变,但就我而言,问题是 UTF-8 和 LF 中断。我使用 www-data 作为文件的所有者而不是 phpd 用户。

My case was that created/edit the file tru WinSCP and notepad++, I used windows with CRLF breaks and encoding it on Windows with ANSI.

我的情况是创建/编辑文件 tru WinSCP 和记事本++,我使用带有 CRLF 中断的窗口并使用 ANSI 在 Windows 上对其进行编码。

I change the file to UTF-8 and for UNIX (LF breaks), then change the part that was encoding wrong (;amp, ;gth e.g.) after the encoding changes.

我将文件更改为 UTF-8 和 UNIX(LF 中断),然后在编码更改后更改编码错误的部分(;amp, ;gth eg)。

回答by Pang

I have svn server deployed on Centos6.5, and use client TortoiseSVN1.8.10 on Win7. When first time the pre-commit hook script is added, the message "Commit blocked by pre-commit hook (exit code 255) with no output" pops up in client when commit. I just solved it in my case with following action:

我在 Centos6.5 上部署了 svn 服务器,在 Win7 上使用客户端 TortoiseSVN1.8.10。首次添加预提交钩子脚本时,客户端会在提交时弹出消息“提交被预提交钩子阻止(退出代码255)且没有输出”。我刚刚通过以下操作解决了我的问题:

$ cd /data/svn/hooks/

$ cd /data/svn/hooks/

$ chmod +x ./pre-commit

$ chmod +x ./预提交

回答by Jawad Khan

For me, after investigating for an hour, I found that I haven't had kshas it was used in pre-commit file. When I installed it, all went smooth.

对我来说,经过一个小时的调查,我发现我没有,ksh因为它在预提交文件中使用过。当我安装它时,一切都很顺利。

回答by Lutorm

I had this exact same problem and by looking at what could cause an exit code of 255 (or -1) I determined that one of the operations that it tries to do after forking the process to execute any of the hooks is a completely useless "cd .". In my case, because the call to svnserve originated in a login by another user that was subsequently sudo'd to the user svnserve was supposed to execute as, it did not have permissions to cd to the directory it was in. Hence the call to "cd ." failed and the process exited without even attempting to execute the pre-commit hook.

我遇到了完全相同的问题,通过查看可能导致退出代码为 255(或 -1)的原因,我确定它在分叉进程以执行任何挂钩后尝试执行的操作之一是完全无用的“光盘。”。在我的例子中,因为对 svnserve 的调用源于另一个用户的登录,该用户随后被 sudo 到 svnserve 应该执行的用户,所以它没有权限 cd 到它所在的目录。因此调用“cd”。失败,进程甚至没有尝试执行预提交钩子就退出了。

Pretty obscure, since there's no indication that the cwd has anything to do with this.

相当晦涩,因为没有迹象表明 cwd 与此有关。

You don't say how svnserve is executed in your case, but another thing to check is that the user it runs as has permissions to access the cwd.

您没有说明在您的情况下如何执行 svnserve,但要检查的另一件事是它运行的用户是否有权访问 cwd。

回答by mcqueeeen

The following is my error message:

以下是我的错误信息:

aaaa@zgg:~/www/eval/webroot$ svn ci -m '' index.php
Sending index.php
Transmitting file data .done
Committing transaction...
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 255) with output:
*************************************************************************
* Please correct the following errors before committing these changes! *
*************************************************************************

aaaa@zgg:~/www/eval/webroot$ svn ci -m '' index.php
正在发送index.php正在
传输文件数据 .done 正在
提交事务...
svn: E165001: Commit failed (详情如下):
svn: E165001:提交被预提交钩子(退出代码 255)阻止,输出:
*********************************** **************************************
* 请在提交这些更改之前更正以下错误!*
***************************************************** ****************************

How I solve the problem:

我如何解决问题:

I just found some syntax error in the file that I want to commit (index.php), and I can successfully commit after I fixed the syntax error.

我刚刚在我要提交的文件(index.php)中发现了一些语法错误,修复语法错误后我可以成功提交。

Check if there any errors in your commit file. Good luck!

检查您的提交文件中是否有任何错误。祝你好运!