diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/ShellCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/ShellCommand.java index 73603cc7d3ca..b47fa966d08c 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/execution/ShellCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/execution/ShellCommand.java @@ -15,7 +15,7 @@ package org.zmlx.hg4idea.execution; import com.intellij.execution.process.CapturingProcessHandler; import com.intellij.execution.process.ProcessOutput; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.text.StringUtil; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -44,8 +44,12 @@ public final class ShellCommand { if (myRunViaBash) { // run via bash -cl => need to escape bash special symbols // '-l' makes bash execute as a login shell thus reading .bash_profile - String hgCommand = StringUtil.join(commandLine, " "); - hgCommand = escapeBashControlCharacters(hgCommand); + StringBuilder hgCommandBuilder = new StringBuilder(); + for (String command : commandLine) { + hgCommandBuilder.append(escapeSpacesIfNeeded(command)); + hgCommandBuilder.append(" "); + } + String hgCommand = escapeBashControlCharacters(hgCommandBuilder.toString()); commandLine = new ArrayList(3); commandLine.add("bash"); commandLine.add("-cl"); @@ -100,4 +104,9 @@ public final class ShellCommand { return sb.toString(); } + @NotNull + private String escapeSpacesIfNeeded(@NotNull String s) { + return myRunViaBash ? s.replace(" ", "\\ ") : s; + } + }