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?
From the hook chapter in the book:
So your executable can just check its current working directory to know the root directory of the repo on which it’s being called.