从python钩子调用Mercurial命令("hg更新") [英] Call a mercurial command ("hg update") from a python hook

查看:106
本文介绍了从python钩子调用Mercurial命令("hg更新")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 2008 64位和IIS上设置了Mercurial hgweb.存储库的位置是网络共享.

I have Mercurial hgweb set up on Windows 2008 64 bit and IIS. The location of the repositories is a network share.

我想在存储库上创建一个钩子,以在changeroup上发出"hg update"命令.我不能使用外部挂钩,因为它将以网络共享作为工作目录启动cmd.exe(而cmd.exe不支持网络共享).

I want to create a hook on the repository to issue an "hg update" command on a changeroup. I cannot use the external hook as this would start cmd.exe with the network share as the working directory (and cmd.exe does not support network shares).

因此,我正在寻找一个示例示例,该示例调用一个mercurial命令的python钩子.我注意到有一个mercurial.commands模块,但是我在网上找不到任何示例,而且我对Python的使用也不是很熟练.

Therefore, I'm looking to find an example of a python hook that calls a mercurial command. I notice that there is a mercurial.commands module, but I cannot find any examples on the webs and I'm not very experienced with Python.

有没有使用Python钩子调用Mercurial命令的示例-是否有可能在hgrc中完成所有操作,还是我需要一个外部.py文件?

Are there any examples to call a mercurial command using a Python hook - and is it possible to do this all in the hgrc, or do I need an external .py file?

推荐答案

受马丁的回答启发,我认为我会尝试编写一些Python,这就是我设法使其工作的方式.我正在使用Mercurial 2.0.2和mercurial.commands模块(Mercurial Python软件包中包含AFAIK).

Inspired by Martin's answer, I thought I would attempt to write some Python, and here is how I managed to get it working. I am using Mercurial 2.0.2 and the mercurial.commands module (which, AFAIK, is included in the Mercurial Python package).

我在服务器上创建了一个myhook.py文件:

I created a myhook.py file on the server:

import mercurial.commands

def update(ui, repo, **kwargs):
    mercurial.commands.update(ui, repo)

然后,在服务器上的.hg/hgrc文件中,添加了以下内容:

Then, in my .hg/hgrc file on the server, I added the following:

[hooks]
changegroup = python:C:\path\to\my\myhook.py:update

我将更改执行命令的行,以专门更新为"tip".如果使用命名分支,则该命令将无效.我相信这样会更好: 命令.更新(ui,repo,repo ['tip'])

I would change the line where the command is executed to specifically update to the 'tip'. If you use named branches then as it is above the command will have no effect. I believe this would be better: commands.update(ui, repo, repo['tip'])

这篇关于从python钩子调用Mercurial命令("hg更新")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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