changeset 141:43db29903d63 Eluru-6.0.x

Merge: Fix problem with hg.cmd on Windows
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 22 Dec 2010 17:56:41 +0300
parents 43dd4142b0f5 (current diff) 247273ec5e27 (diff)
children 0587a0235612
files mercurial.ipr
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 '<mercurial_install_dir>/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 <mercurial_install_dir>/bin and doesn't contain <mercurial_install_dir> 
+   * 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());
   }