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.
This commit is contained in:
Kirill Likhodedov
2011-12-19 14:14:41 +03:00
parent 2a3c4b4d2f
commit 84de0a9d25
@@ -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 <hg command> => 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<String>(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;
}
}