diff options
4 files changed, 26 insertions, 20 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java index a830ff2849..befb7f62ac 100644 --- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java +++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java @@ -211,6 +211,14 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase { .replaceAll("\t", "\\\\t"); } + protected String shellQuote(String s) { + return "'" + s.replace("'", "'\\''") + "'"; + } + + protected String shellQuote(File f) { + return "'" + f.getPath().replace("'", "'\\''") + "'"; + } + protected void assertStringArrayEquals(String expected, String[] actual) { // if there is more than one line, ignore last one if empty assertEquals(1, diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java index e07fdd50d2..03aa469898 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java @@ -139,10 +139,6 @@ public class ArchiveTest extends CLIRepositoryTestCase { listTarEntries(result)); } - private static String shellQuote(String s) { - return "'" + s.replace("'", "'\\''") + "'"; - } - @Test public void testFormatOverridesFilename() throws Exception { File archive = new File(db.getWorkTree(), "format-overrides-name.tar"); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java index 2c0abd78a5..c31f28c256 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java @@ -78,9 +78,9 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); File target = createTempDirectory("target"); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI - + " " + target.getPath()); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI + " " + + shellQuote(target.getPath()); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + target.getPath() + "'...", "", "" }, result); @@ -101,9 +101,9 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); File target = createTempDirectory("target"); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI - + " " + target.getPath()); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI + " " + + shellQuote(target.getPath()); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + target.getPath() + "'...", "warning: You appear to have cloned an empty repository.", "", @@ -125,8 +125,8 @@ public class CloneTest extends CLIRepositoryTestCase { File gitDir = db.getDirectory(); String sourceURI = gitDir.toURI().toString(); String name = new URIish(sourceURI).getHumanishName(); - StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI); - String[] result = execute(cmd.toString()); + String cmd = "git clone " + sourceURI; + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + new File(target, name).getName() + "'...", "", "" }, result); @@ -143,10 +143,10 @@ public class CloneTest extends CLIRepositoryTestCase { String sourcePath = gitDir.getAbsolutePath(); String targetPath = (new File(sourcePath)).getParentFile() .getParentFile().getAbsolutePath() - + "/target.git"; - StringBuilder cmd = new StringBuilder("git clone --bare ") - .append(sourcePath + " " + targetPath); - String[] result = execute(cmd.toString()); + + File.separator + "target.git"; + String cmd = "git clone --bare " + shellQuote(sourcePath) + " " + + shellQuote(targetPath); + String[] result = execute(cmd); assertArrayEquals(new String[] { "Cloning into '" + targetPath + "'...", "", "" }, result); Git git2 = Git.open(new File(targetPath)); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java index ba6b771de5..fd3c383764 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/LsRemoteTest.java @@ -80,7 +80,7 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemote() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote " + db.getDirectory(), db); + "git ls-remote " + shellQuote(db.getDirectory()), db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", @@ -98,7 +98,8 @@ public class LsRemoteTest extends CLIRepositoryTestCase { public void testLsRemoteHeads() throws Exception { final List<String> result = CLIGitCommand.execute( "git ls-remote --heads " - + db.getDirectory(), db); + + shellQuote(db.getDirectory()), + db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test", @@ -108,7 +109,7 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemoteTags() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote --tags " + db.getDirectory(), db); + "git ls-remote --tags " + shellQuote(db.getDirectory()), db); assertArrayEquals(new String[] { "efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}", @@ -122,7 +123,8 @@ public class LsRemoteTest extends CLIRepositoryTestCase { @Test public void testLsRemoteHeadsTags() throws Exception { final List<String> result = CLIGitCommand.execute( - "git ls-remote --heads --tags " + db.getDirectory(), db); + "git ls-remote --heads --tags " + shellQuote(db.getDirectory()), + db); assertArrayEquals(new String[] { "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master", "d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test", |