Mercurial挂钩:如何在提交时查找当前目录 [英] Mercurial hooks: how to find the current directory on commit

查看:82
本文介绍了Mercurial挂钩:如何在提交时查找当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#.NET创建与Mercurial SCM(hg)的钩子,以在提交或预提交时启动自定义C#应用程序.

I am trying to create a hook to Mercurial SCM (hg) using C# .NET, to launch a custom C# application on commit or pre-commit.

作为概念验证的原型,我在Mercurial.ini文件的[hooks]节中添加了自定义.exe的位置以进行预提交,并在另一个.exe中进行提交. 这些.exe应用程序会按预期在预提交和提交时打开.

As a proof-of-concept prototype, I added a location of my custom .exe to the Mercurial.ini file's [hooks] section for pre-commit, and another .exe for commit. Those .exe apps open on pre-commit and commit, as expected.

但是,到目前为止,这些可执行文件只是存根. 为了使他们能够执行我需要的工作,他们必须知道"即将发生(或已经发生)提交的当前目录. Mercurial.ini位于Windows上的用户配置文件目录中. 例如,当我从C:\ MyProjects \ TestProject中的Hg存储库中提交内容时,可执行文件需要知道工作正在C:\ MyProjects \ TestProject中完成.

However, those executables are only stubs so far. To make them do what I need, they have to "know" the current directory where the commit is about to occur (or has occurred). Mercurial.ini is located in my user profile directory on Windows. For example, when I do a commit from an Hg repository located in C:\MyProjects\TestProject, the executables need to know that the work is being done in C:\MyProjects\TestProject.

如何在运行时以编程方式从本地计算机上正在执行Mercurial命令的挂钩"可执行文件中查找?

How can I find out programmatically at runtime from a "hooked" executable where the Mercurial command is being executed on the local machine?

推荐答案

来自

可执行钩子始终在其当前目录设置为a的情况下运行 存储库的根目录.

An executable hook is always run with its current directory set to a repository's root directory.

因此,您的可执行文件可以仅检查其当前工作目录,以了解在其上被调用的存储库的根目录.

So your executable can just check its current working directory to know the root directory of the repo on which it's being called.

这篇关于Mercurial挂钩:如何在提交时查找当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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