SVN pre-commit issue

你离开我真会死。 提交于 2019-12-22 11:35:17

问题


I found this script on the net and few ppl had said that it was working for their repository. The script is to allow a pre-commit check to enforce checking of comments while checking.. The problem is I added it to the hooks directory in SVN and now all commits (even the ones with comment) are failing with this error message "Commit blocked by pre-commit (exit code 255) with no output"

Now, I cannot change the script or delete it since I get the same error. Any suggestions on how to revert this pre-commit script ?


#!/bin/bash

#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)

REPOS="$1"
REV="$2"

@echo off
::
:: Stops commits that have empty log messages.
::

@echo off

setlocal

# rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2

# rem check for an empty log message
svnlook log %REPOS% -t %TXN% | findstr . > nul
if %errorlevel% gtr 0 (goto err) else exit 0

:err
echo. 1>&2
echo Your commit has been blocked because you didn't give any log message 1>&2
echo Please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1


回答1:


This means it isn't even executing your hook. Whenever you get an error like that, it can mean several things:

  • The shebang at the top of your script is incorrect. Maybe on your system, there's no BASH shell or that the BASH shell is located at /usr/local/bin/bash or /usr/share/bin/bash. Unlikely on a Linux system, but very likely on Solaris. Check this.
  • The script doesn't have the executable bit set. You need to do a chmod +x on your script.
  • The pre-commit shell script isn't able to call your script itself. Take a look at the pre-commit script inside the hook directory and make sure it's calling your script. Or, that you've renamed your script to pre-commit and put it in that directory.

Another possibility (looking more closely at your script) is that you've confused the pre-commit BASH script with the pre-commit.bat version for Windows shell. Your syntax is Windows shell in the second half of your script, but your top half is BASH shell.

Here's my pre-commit hook. It's in Perl, so it works with both Windows and Unix/Linux/Mac. You'll have to install ActivePerl or Strawberry Perl on your Windows box, but both are free and open source.

My pre-commit script can do several things such as make sure people don't accidentally change tags by allowing people to create tags, but not modify them.

My script also allows a bit more checking with the commit comment. For example, do you use a bug tracking system? You can set up my hook to require a bug tracking ID in the commit comment.

Another possibility (and something I'd really recommend) is to use a continuous build tool like Jenkins. Jenkins automatically does a build and will run tests with each commit. This makes sure that errors are caught early rather than say post-production.

The big advantage of Jenkins is that it presents a beautiful webpage with all sorts of information like who made the changes and what changes they made. Developers find this so helpful that they automatically start putting in good commit comments without being asked. It's amazing that I can go through a Subversion change log and pinpoint the exact moment I've started using Jenkins.

In your pre-commit script, you merely check for empty comments. If your developers don't feel like putting in comments, you'll start getting comments like changed code and adaadsdasdasda just to allow the commit to go through. With something like Jenkins, the developers actually start putting in good commit comments on their own.




回答2:


Have you checked to see that pre-commit is set to executable.

ls -l pre-commit

Note it must also be executable by the process that serves your svn repo, in my case httpd.



来源:https://stackoverflow.com/questions/7326587/svn-pre-commit-issue

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