JGit pgm tests must quote paths on the command line
The JGit pgm tests parse the command line internally using Linux semantics, treating '\' as an escape. File paths therefore must be quoted, otherwise Windows paths are destroyed. See the attachment[1] on bug 548598. [1] https://bugs.eclipse.org/bugs/attachment.cgi?id=279387 Bug: 544326 Change-Id: If42e29c8e808b0983fba2843a34c3ea3dd0e9246 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
parent
81acf3b440
commit
5fe455c84f
|
@ -211,6 +211,14 @@ protected String escapeJava(String line) {
|
||||||
.replaceAll("\t", "\\\\t");
|
.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) {
|
protected void assertStringArrayEquals(String expected, String[] actual) {
|
||||||
// if there is more than one line, ignore last one if empty
|
// if there is more than one line, ignore last one if empty
|
||||||
assertEquals(1,
|
assertEquals(1,
|
||||||
|
|
|
@ -139,10 +139,6 @@ public void testDefaultFormatIsTar() throws Exception {
|
||||||
listTarEntries(result));
|
listTarEntries(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String shellQuote(String s) {
|
|
||||||
return "'" + s.replace("'", "'\\''") + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFormatOverridesFilename() throws Exception {
|
public void testFormatOverridesFilename() throws Exception {
|
||||||
File archive = new File(db.getWorkTree(), "format-overrides-name.tar");
|
File archive = new File(db.getWorkTree(), "format-overrides-name.tar");
|
||||||
|
|
|
@ -78,9 +78,9 @@ public void testClone() throws Exception {
|
||||||
File gitDir = db.getDirectory();
|
File gitDir = db.getDirectory();
|
||||||
String sourceURI = gitDir.toURI().toString();
|
String sourceURI = gitDir.toURI().toString();
|
||||||
File target = createTempDirectory("target");
|
File target = createTempDirectory("target");
|
||||||
StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI
|
String cmd = "git clone " + sourceURI + " "
|
||||||
+ " " + target.getPath());
|
+ shellQuote(target.getPath());
|
||||||
String[] result = execute(cmd.toString());
|
String[] result = execute(cmd);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"Cloning into '" + target.getPath() + "'...",
|
"Cloning into '" + target.getPath() + "'...",
|
||||||
"", "" }, result);
|
"", "" }, result);
|
||||||
|
@ -101,9 +101,9 @@ public void testCloneEmpty() throws Exception {
|
||||||
File gitDir = db.getDirectory();
|
File gitDir = db.getDirectory();
|
||||||
String sourceURI = gitDir.toURI().toString();
|
String sourceURI = gitDir.toURI().toString();
|
||||||
File target = createTempDirectory("target");
|
File target = createTempDirectory("target");
|
||||||
StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI
|
String cmd = "git clone " + sourceURI + " "
|
||||||
+ " " + target.getPath());
|
+ shellQuote(target.getPath());
|
||||||
String[] result = execute(cmd.toString());
|
String[] result = execute(cmd);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"Cloning into '" + target.getPath() + "'...",
|
"Cloning into '" + target.getPath() + "'...",
|
||||||
"warning: You appear to have cloned an empty repository.", "",
|
"warning: You appear to have cloned an empty repository.", "",
|
||||||
|
@ -125,8 +125,8 @@ public void testCloneIntoCurrentDir() throws Exception {
|
||||||
File gitDir = db.getDirectory();
|
File gitDir = db.getDirectory();
|
||||||
String sourceURI = gitDir.toURI().toString();
|
String sourceURI = gitDir.toURI().toString();
|
||||||
String name = new URIish(sourceURI).getHumanishName();
|
String name = new URIish(sourceURI).getHumanishName();
|
||||||
StringBuilder cmd = new StringBuilder("git clone ").append(sourceURI);
|
String cmd = "git clone " + sourceURI;
|
||||||
String[] result = execute(cmd.toString());
|
String[] result = execute(cmd);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"Cloning into '" + new File(target, name).getName() + "'...",
|
"Cloning into '" + new File(target, name).getName() + "'...",
|
||||||
"", "" }, result);
|
"", "" }, result);
|
||||||
|
@ -143,10 +143,10 @@ public void testCloneBare() throws Exception {
|
||||||
String sourcePath = gitDir.getAbsolutePath();
|
String sourcePath = gitDir.getAbsolutePath();
|
||||||
String targetPath = (new File(sourcePath)).getParentFile()
|
String targetPath = (new File(sourcePath)).getParentFile()
|
||||||
.getParentFile().getAbsolutePath()
|
.getParentFile().getAbsolutePath()
|
||||||
+ "/target.git";
|
+ File.separator + "target.git";
|
||||||
StringBuilder cmd = new StringBuilder("git clone --bare ")
|
String cmd = "git clone --bare " + shellQuote(sourcePath) + " "
|
||||||
.append(sourcePath + " " + targetPath);
|
+ shellQuote(targetPath);
|
||||||
String[] result = execute(cmd.toString());
|
String[] result = execute(cmd);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"Cloning into '" + targetPath + "'...", "", "" }, result);
|
"Cloning into '" + targetPath + "'...", "", "" }, result);
|
||||||
Git git2 = Git.open(new File(targetPath));
|
Git git2 = Git.open(new File(targetPath));
|
||||||
|
|
|
@ -80,7 +80,7 @@ public void setUp() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testLsRemote() throws Exception {
|
public void testLsRemote() throws Exception {
|
||||||
final List<String> result = CLIGitCommand.execute(
|
final List<String> result = CLIGitCommand.execute(
|
||||||
"git ls-remote " + db.getDirectory(), db);
|
"git ls-remote " + shellQuote(db.getDirectory()), db);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c HEAD",
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
||||||
|
@ -98,7 +98,8 @@ public void testLsRemote() throws Exception {
|
||||||
public void testLsRemoteHeads() throws Exception {
|
public void testLsRemoteHeads() throws Exception {
|
||||||
final List<String> result = CLIGitCommand.execute(
|
final List<String> result = CLIGitCommand.execute(
|
||||||
"git ls-remote --heads "
|
"git ls-remote --heads "
|
||||||
+ db.getDirectory(), db);
|
+ shellQuote(db.getDirectory()),
|
||||||
|
db);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
|
||||||
|
@ -108,7 +109,7 @@ public void testLsRemoteHeads() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testLsRemoteTags() throws Exception {
|
public void testLsRemoteTags() throws Exception {
|
||||||
final List<String> result = CLIGitCommand.execute(
|
final List<String> result = CLIGitCommand.execute(
|
||||||
"git ls-remote --tags " + db.getDirectory(), db);
|
"git ls-remote --tags " + shellQuote(db.getDirectory()), db);
|
||||||
assertArrayEquals(new String[] {
|
assertArrayEquals(new String[] {
|
||||||
"efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
|
"efc02078d83a5226986ae917323acec7e1e8b7cb refs/tags/tag1",
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/tags/tag1^{}",
|
||||||
|
@ -122,7 +123,8 @@ public void testLsRemoteTags() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testLsRemoteHeadsTags() throws Exception {
|
public void testLsRemoteHeadsTags() throws Exception {
|
||||||
final List<String> result = CLIGitCommand.execute(
|
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[] {
|
assertArrayEquals(new String[] {
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/master",
|
||||||
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
|
"d0b1ef2b3dea02bb2ca824445c04e6def012c32c refs/heads/test",
|
||||||
|
|
Loading…
Reference in New Issue