From 84de0a9d2517c266b9eba7997e6d1f34564e1794 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 19 Dec 2011 14:14:41 +0300 Subject: [PATCH] IDEA-78781 Fix hg for the case when there are spaces in the path to repository or in relative paths inside the repository. Escape paths for the case when hg is called via bash. For the standard call it is not needed. --- .../org/zmlx/hg4idea/execution/ShellCommand.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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; + } + }