Bug solved in ClientExecutable.SetClientPath

Aug 25, 2011 at 2:53 PM
Edited Aug 25, 2011 at 2:54 PM


Thanks for "HG.net" - very useful!

I found a bug while trying to use a custom hg executable while tortoisehg was installed in my pc: despite I was explicitely calling ClientExecutable.SetClientPath("c:\mypath\hg.bat"), ClientPath's value inevitably reverts to "c:\program files\tortoisehg\hg.exe". This is because SetClientPath calls GetVersions which itself calls LazyInitialize which does a "ClientPath = LocateClient()".

The solution is trivial: in SetClientPath, just add one line "_LazyInitializationExecuted = true;" before to call the Initialize method. Full code is below.



public static void SetClientPath(string clientPath)
            if (StringEx.IsNullOrWhiteSpace(clientPath))
                throw new ArgumentNullException("clientPath");

            if (Directory.Exists(clientPath) && File.Exists(Path.Combine(clientPath, "hg.exe")))
                clientPath = Path.Combine(clientPath, "hg.exe");
            if (!File.Exists(clientPath))
                throw new ArgumentException("The specified path does not contain the Mercurial executable");
            ClientPath = clientPath;
            _LazyInitializationExecuted = true;

Aug 25, 2011 at 6:54 PM

Many thanks for this! I'll incorporate this bugfix into the codebase once I have created a unit-test to prevent this problem from cropping up in the future :)