Developer 123
Developer 123

Reputation: 33

Mercurial hooks: how to find the current directory on commit

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.

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.

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.

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

Upvotes: 2

Views: 662

Answers (1)

Ry4an Brase
Ry4an Brase

Reputation: 78340

From the hook chapter in the book:

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.

Upvotes: 4

Related Questions