Browse Source

Remove quoting of command over SSH

If the command contains spaces, it needs to be evaluated by the remote
shell.  Quoting the command breaks this, making it impossible to run a
remote command that needs additional options.

Bug: 336301
Change-Id: Ib5d88f0b2151df2d1d2b4e08d51ee979f6da67b5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.11
Shawn O. Pearce 14 years ago
parent
commit
0180946bc8
  1. 35
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java

35
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java

@ -115,44 +115,15 @@ public class TransportGitSsh extends SshTransport implements PackTransport {
return new JschConnection();
}
private static void sqMinimal(final StringBuilder cmd, final String val) {
if (val.matches("^[a-zA-Z0-9._/-]*$")) {
// If the string matches only generally safe characters
// that the shell is not going to evaluate specially we
// should leave the string unquoted. Not all systems
// actually run a shell and over-quoting confuses them
// when it comes to the command name.
//
cmd.append(val);
} else {
sq(cmd, val);
}
}
private static void sqAlways(final StringBuilder cmd, final String val) {
sq(cmd, val);
}
private static void sq(final StringBuilder cmd, final String val) {
if (val.length() > 0)
cmd.append(QuotedString.BOURNE.quote(val));
}
String commandFor(final String exe) {
String path = uri.getPath();
if (uri.getScheme() != null && uri.getPath().startsWith("/~"))
path = (uri.getPath().substring(1));
final StringBuilder cmd = new StringBuilder();
final int gitspace = exe.indexOf("git ");
if (gitspace >= 0) {
sqMinimal(cmd, exe.substring(0, gitspace + 3));
cmd.append(' ');
sqMinimal(cmd, exe.substring(gitspace + 4));
} else
sqMinimal(cmd, exe);
cmd.append(exe);
cmd.append(' ');
sqAlways(cmd, path);
cmd.append(QuotedString.BOURNE.quote(path));
return cmd.toString();
}
@ -178,7 +149,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport {
final StringBuilder pfx = new StringBuilder();
pfx.append("fatal: ");
sqAlways(pfx, path);
pfx.append(QuotedString.BOURNE.quote(path));
pfx.append(": ");
if (why.startsWith(pfx.toString()))
why = why.substring(pfx.length());

Loading…
Cancel
Save