# HG changeset patch # User Dmitry Neverov # Date 1293029801 -10800 # Node ID 43db29903d63ee5f63984be893fd6f1932ec002e # Parent 43dd4142b0f5f4a07ed4ffad5869cccc05d91abf# Parent 247273ec5e27c8230a00171ecec6c7619834b51a Merge: Fix problem with hg.cmd on Windows diff -r 43dd4142b0f5 -r 43db29903d63 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Wed Dec 22 11:39:14 2010 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Wed Dec 22 17:56:41 2010 +0300 @@ -16,6 +16,7 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; import com.intellij.execution.configurations.GeneralCommandLine; +import com.intellij.openapi.util.SystemInfo; import jetbrains.buildServer.ExecResult; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.VcsException; @@ -50,12 +51,37 @@ protected GeneralCommandLine createCommandLine() { GeneralCommandLine cli = new GeneralCommandLine(); - cli.setExePath(getSettings().getHgCommandPath()); + setupExecutable(cli); cli.setWorkDirectory(myWorkDirectory); cli.setPassParentEnvs(true); return cli; } + /** + * Since mercurial 1.7 on Windows the only file inside '/bin' is 'hg.cmd' + * which run hg.exe placed in the parent dir. GeneralCommandLine will not find hg.cmd, in the + * case when $PATH contains /bin and doesn't contain + * and hg executable is set to 'hg'. To fix it - run hg using windows shell which expand + * hg to hg.cmd correctly. + */ + private void setupExecutable(GeneralCommandLine cli) { + if (SystemInfo.isWindows && getSettings().getHgCommandPath().equals("hg")) { + setupCmd(cli); + } else { + setupHg(cli); + } + } + + private void setupCmd(GeneralCommandLine cli) { + cli.setExePath("cmd"); + cli.addParameter("/c"); + cli.addParameter("hg"); + } + + private void setupHg(GeneralCommandLine cli) { + cli.setExePath(getSettings().getHgCommandPath()); + } + protected ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException { return CommandUtil.runCommand(cli, getPrivateData()); }