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

断了今生、忘了曾经 提交于 2019-12-10 23:58:13

问题


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:

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.

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.

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.
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:
foven@phabricator:~$ sudo getenforce
Disabled
  • I have run dos2unix on the pre-commit hook file:
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@phabricator ~]$ /var/repo/SVN/hooks/pre-commit
testing

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

[phd@phabricator ~]$ env -i /var/repo/SVN/hooks/pre-commit
testing
  • It seems like the script's shebang is correct:
[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:

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.


回答1:


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.

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.

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.




回答2:


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:

$ cd /data/svn/hooks/

$ chmod +x ./pre-commit




回答3:


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.

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

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.




回答4:


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




回答5:


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! *
*************************************************************************

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.

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



来源:https://stackoverflow.com/questions/33789148/svn-e165001-commit-blocked-by-pre-commit-hook-exit-code-255-with-no-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!