颠覆提交后的钩子 [英] Subversion Post-Commit Hooks

查看:163
本文介绍了颠覆提交后的钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使提交后的钩子正常工作时遇到了一些问题.将更改的文件提交到存储库后,Subversion似乎不会触发我的提交后钩子.

I am having some issues getting post-commit hooks to work. Subversion doesn't appear to be triggering my post-commit hook when I commit a changed file to my repository.

我将TortoiseSVN和VisualSVN与Subversion一起使用,我能够进入VisualSVN用户界面并在其中工作,并创建了一个钩子,但是我想做的是在的hooks文件夹中使用提交后的可执行钩子.我的安装程序执行我的钩子.

I am using TortoiseSVN and VisualSVN with Subversion, I was able to go into the VisualSVN user interface and create a hook within there that worked however what I would like to do is use the post-commit executable hook in the hooks folder of my installation to execute my hook.

我已在存储库的/hooks文件夹中将名称从post-commit.tmpl更改为post-commit.bat,并且只是在批处理文件中进行了简单的更新:

I have changed the name from post-commit.tmpl to post-commit.bat in the /hooks folder of my repository and am just doing a simple update within the batch file:

"C:\Program Files\TortoiseSVN\bin\svn.exe" update "C:\mypath\myworkingcopy"

当我自己运行批处理文件时,它会更新我的工作文件夹,因此我认为由于某种原因提交时不会触发该文件.这似乎不是权限问题,因为一切都在我的计算机上本地完成,但是我将其设置为作为网络服务运行,但是仍然遇到相同的问题...有什么建议吗?

When I run the batch file on its own it updates my working folder so I am thinking it is not being triggered when I commit for some reason. It doesn't appear to be a permissions issue since everything is being done locally on my machine however I have set it to run as a network service but still experience the same problem...any suggestions?

推荐答案

首先,所有挂钩都在 SERVER 上执行,而不是在各种客户端计算机上执行.是服务器上的C:\mypath\myworkingcopy吗?如果没有,就不会更新.

First of all, all hooks are executed on the SERVER and not on the various client machines. Is that C:\mypath\myworkingcopy on the server? If not, it's not going to get updated.

第二,在钩子上做任何可能花费太多时间的事情都是不好的形式.如果您的钩子需要的内容不是svnlook,则可能是您做错了.例如,更新该工作副本需要多长时间? 10秒? 30秒?一分钟?那是开发人员必须坐下来等待Subversion提交完成的额外时间.

Second of all, it's bad form to do anything in a hook that might take too much time. If your hook needs something more than svnlook, chances are you're doing it wrong. For example, how long could it take to update that working copy? 10 seconds? 30 seconds? a minute? That's the added time a developer has to sit and wait for their Subversion commit to complete.

使用可以响应提交事件并执行诸如在提交后的钩子之外进行工作副本更新或部署到Web服务器之类的操作的东西要好得多.我强烈推荐 Jenkins 来完成这项工作.詹金斯(Jenkins)具有几个不错的功能:

It is much, much better to use something that can respond to commit events and have that do things like working copy updates or deployments to web servers outside of a post-commit hook. I highly recommend Jenkins for this job. Jenkins has several nice features:

  • 这是合算的(您无法免费获得)
  • 它得到了很好的支持(在Stackoverflow上发布问题并获得快速答复).
  • 设置和使用非常方便.

现在回到您的问题:

首先确保挂钩正在运行.将以下一行添加到批处理脚本的底部:

First make sure the hook is running. Add to the bottom of the batch script this one line:

 exit 2

这将使Subversion认为提交后挂钩失败,并且您应该在提交时收到错误消息.如果不是,则您的提交后脚本未运行.确保脚本可以由运行Subversion服务器的帐户执行.

That will make Subversion think the post-commit hook has failed and you should get an error message on commit. If not, your post-commit script isn't running. Make sure the script is executable by the account that's running the Subversion server.

如果收到错误消息,则说明脚本正在运行.但是,svn命令可能不会返回错误,而该错误已由提交后的过程获取.由于其局限性,我通常不建议使用Windows批处理编程语言编写钩子.使用Python或Perl或PowerShell.这些可以更好地检测错误情况,并且在检测到错误时可以退出脚本.

If you do get an error message, the script is running. However, the svn command may not be returning an error that's getting picked up by the post-commit process. I normally don't recommend writing hooks in Windows batch programming language because of its limitations. Use Python or Perl or PowerShell. These are better at detecting error conditions and you can exit out of your script when detected.

然后,一切运行正常,但是您看到的是错误的工作副本(计算机上的副本而不是服务器上的副本).当您在Subversion服务器外部运行挂钩进行测试时,请以运行服务器进程的Subversion用户的身份在服务器上运行它们.

Then again, things are working perfectly, but you're looking at the wrong working copy (the one on your machine and not the one on the server). When you run hooks outside of the subversion server for testing, run them on the server as the Subversion user running the server process.

尝试这些方法,看看是否可以解决您的问题.

Try these things and see if that corrects your problem.

我用svnadmin create创建了一个存储库,并使用svnserve运行它.我更新了svnserve.conf以允许我检出并提交代码.

I created a repository with svnadmin create and ran it using svnserve. I updated svnserve.conf to allow me to checkout and commit code.

我进入hooks目录,将pre-commit.tmpl重命名为pre-commit.bat并将其设置为:

I went into the hooks directory, renamed pre-commit.tmpl to pre-commit.bat and set it as:

set 1>&2
echo "Blocked my me!" 1>&2
exit 2

当我尝试提交更改时,我得到了:

When I attempted to commit my changes, I got:

Transmitting file data .svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 2) with output:
[...]
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW
PERL_JSON_BACKEND=JSON::XS
PERL_YAML_BACKEND=YAML
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2a07
[...]
"Blocked my me!"

该钩子 应该 用于删除环境(包括PATH),但是我想这仅适用于Unix,而不适用于Windows.您可以看到已定义PATHEXT.

然后我将pre-commit.bat重命名为pre-commit.tmpl并创建了一个post-commit.bat`,如下所示:

I then renamed pre-commit.bat to pre-commit.tmpl and created a post-commit.bat` that looks like this:

echo This post-commit hook shall fail! 1>&2
exit 2

在提交过程中,我得到了以下信息:

During a commit, I got the following:

Transmitting file data .
Committed revision 3.

Warning: post-commit hook failed (exit code 2) with output:
This post-commit shall fail!

看起来一切都按计划进行.我没有使用VisualSVN,也没有作为服务运行.我想知道您的PATHEXT环境变量是否可能有问题.

It looks like everything is working as planned. I'm not using VisualSVN, and I'm not running as a service. I wonder if there might be an issue with your PATHEXT environment variable.

也许看看在运行Subversion服务器的帐户中如何设置它,并查看其中是否有.BAT.

Maybe take a look how it is set on your account that's running the Subversion server and see if .BAT is in there.

我想不通其他任何事情.

I can't think of anything else right off hand.

这篇关于颠覆提交后的钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆