From 75cfa03e163f72e8707e7f9126f17fbacb025b99 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 1 Nov 2013 15:59:57 +0100 Subject: [PATCH] Use absolute paths for file:// URIs in tests When run under Buck the repository paths may be relative. Request an absolute path to construct the URI, as relative paths are not supported in file:// style URIs. Change-Id: I85470d1db2f4e80cba30f1559c0d99bdfa8ac410 --- .../jgit/ant/tasks/GitCloneTaskTest.java | 4 +-- .../eclipse/jgit/api/BranchCommandTest.java | 2 +- .../eclipse/jgit/api/CloneCommandTest.java | 36 ++++++++++--------- .../eclipse/jgit/api/LsRemoteCommandTest.java | 12 ++++--- .../org/eclipse/jgit/api/PullCommandTest.java | 5 +-- .../jgit/api/PullCommandWithRebaseTest.java | 2 +- .../file/FileRepositoryBuilderTest.java | 6 ++-- .../jgit/submodule/SubmoduleWalkTest.java | 6 ++-- .../eclipse/jgit/transport/TransportTest.java | 2 +- 9 files changed, 44 insertions(+), 31 deletions(-) diff --git a/org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java b/org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java index 7cd5b7451..3ce066376 100644 --- a/org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java +++ b/org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java @@ -101,7 +101,7 @@ public void shouldRaiseErrorOnBadSourceURL() throws Exception { public void shouldCloneAValidGitRepository() throws Exception { Repository repo = createBareRepository(); File directory = repo.getDirectory(); - task.setUri("file://" + directory); + task.setUri("file://" + directory.getAbsolutePath()); task.execute(); assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED)); @@ -111,7 +111,7 @@ public void shouldCloneAValidGitRepository() throws Exception { public void shouldCreateABareCloneOfAValidGitRepository() throws Exception { Repository repo = createBareRepository(); File directory = repo.getDirectory(); - task.setUri("file://" + directory); + task.setUri("file://" + directory.getAbsolutePath()); task.setBare(true); task.execute(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index c2c8317d9..91ced0a59 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -121,7 +121,7 @@ private Git setUpRepoWithRemote() throws Exception { Git localGit = new Git(localRepository); StoredConfig config = localRepository.getConfig(); RemoteConfig rc = new RemoteConfig(config, "origin"); - rc.addURI(new URIish(remoteRepository.getDirectory().getPath())); + rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); rc.update(config); config.save(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 31f909a5f..56c120176 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -110,7 +110,7 @@ public void testCloneRepository() throws IOException, File directory = createTempDirectory("testCloneRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -142,7 +142,7 @@ public void testBareCloneRepository() throws IOException, CloneCommand command = Git.cloneRepository(); command.setBare(true); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertEquals(new RefSpec("+refs/heads/*:refs/heads/*"), @@ -162,7 +162,7 @@ public void testCloneRepositoryWithBranch() throws IOException, CloneCommand command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -177,7 +177,7 @@ public void testCloneRepositoryWithBranch() throws IOException, command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setNoCheckout(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -192,7 +192,7 @@ public void testCloneRepositoryWithBranch() throws IOException, command = Git.cloneRepository(); command.setBranch("refs/heads/master"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setBare(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -209,7 +209,7 @@ public void testCloneRepositoryWithBranchShortName() throws Exception { CloneCommand command = Git.cloneRepository(); command.setBranch("test"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -223,7 +223,7 @@ public void testCloneRepositoryWithTagName() throws Exception { CloneCommand command = Git.cloneRepository(); command.setBranch("tag-initial"); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -242,7 +242,7 @@ public void testCloneRepositoryOnlyOneBranch() throws IOException, command.setBranchesToClone(Collections .singletonList("refs/heads/master")); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -257,7 +257,7 @@ public void testCloneRepositoryOnlyOneBranch() throws IOException, command.setBranchesToClone(Collections .singletonList("refs/heads/master")); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setBare(true); git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -284,14 +284,14 @@ public void testCloneRepositoryWhenDestinationDirectoryExistsAndIsNotEmpty() File directory = createTempDirectory(dirName); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); // clone again command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); try { git2 = command.call(); // we shouldn't get here @@ -310,7 +310,7 @@ public void testCloneRepositoryWithMultipleHeadBranches() throws Exception { File directory = createTempDirectory("testCloneRepositoryWithMultipleHeadBranches"); CloneCommand clone = Git.cloneRepository(); clone.setDirectory(directory); - clone.setURI("file://" + git.getRepository().getWorkTree().getPath()); + clone.setURI(fileUri()); Git git2 = clone.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -343,7 +343,7 @@ public void testCloneRepositoryWithSubmodules() throws Exception { CloneCommand clone = Git.cloneRepository(); clone.setDirectory(directory); clone.setCloneSubmodules(true); - clone.setURI("file://" + git.getRepository().getWorkTree().getPath()); + clone.setURI(fileUri()); Git git2 = clone.call(); addRepoToClose(git2.getRepository()); assertNotNull(git2); @@ -458,7 +458,7 @@ public void testCloneWithAutoSetupRebase() throws Exception { File directory = createTempDirectory("testCloneRepository1"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); Git git2 = command.call(); addRepoToClose(git2.getRepository()); assertFalse(git2 @@ -476,7 +476,7 @@ public void testCloneWithAutoSetupRebase() throws Exception { directory = createTempDirectory("testCloneRepository2"); command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); git2 = command.call(); addRepoToClose(git2.getRepository()); assertTrue(git2 @@ -492,7 +492,7 @@ public void testCloneWithAutoSetupRebase() throws Exception { directory = createTempDirectory("testCloneRepository2"); command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); git2 = command.call(); addRepoToClose(git2.getRepository()); assertTrue(git2 @@ -502,4 +502,8 @@ public void testCloneWithAutoSetupRebase() throws Exception { ConfigConstants.CONFIG_KEY_REBASE, false)); } + + private String fileUri() { + return "file://" + git.getRepository().getWorkTree().getAbsolutePath(); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java index f31276dee..a853d6ab8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java @@ -82,7 +82,7 @@ public void testLsRemote() throws Exception { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -99,7 +99,7 @@ public void testLsRemoteWithTags() throws Exception { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -116,7 +116,7 @@ public void testLsRemoteWithHeads() throws Exception { File directory = createTempDirectory("testRepository"); CloneCommand command = Git.cloneRepository(); command.setDirectory(directory); - command.setURI("file://" + git.getRepository().getWorkTree().getPath()); + command.setURI(fileUri()); command.setCloneAllBranches(true); Git git2 = command.call(); addRepoToClose(git2.getRepository()); @@ -130,10 +130,14 @@ public void testLsRemoteWithHeads() throws Exception { @Test public void testLsRemoteWithoutLocalRepository() throws Exception { - String uri = "file://" + git.getRepository().getWorkTree().getPath(); + String uri = fileUri(); Collection refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call(); assertNotNull(refs); assertEquals(2, refs.size()); } + private String fileUri() { + return "file://" + git.getRepository().getWorkTree().getAbsolutePath(); + } + } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java index 8d22a1b58..c03ced563 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java @@ -139,7 +139,8 @@ public void testPullMerge() throws Exception { assertEquals(sourceCommit.getId(), mergedCommits[1]); RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult .getNewHead()); - String message = "Merge branch 'master' of " + db.getWorkTree(); + String message = "Merge branch 'master' of " + + db.getWorkTree().getAbsolutePath(); assertEquals(message, mergeCommit.getShortMessage()); } @@ -255,7 +256,7 @@ public void setUp() throws Exception { config .addURI(new URIish(source.getRepository().getWorkTree() - .getPath())); + .getAbsolutePath())); config.addFetchRefSpec(new RefSpec( "+refs/heads/*:refs/remotes/origin/*")); config.update(targetConfig); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java index 993e16f5e..25534fdda 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java @@ -319,7 +319,7 @@ public void setUp() throws Exception { config .addURI(new URIish(source.getRepository().getWorkTree() - .getPath())); + .getAbsolutePath())); config.addFetchRefSpec(new RefSpec( "+refs/heads/*:refs/remotes/origin/*")); config.update(targetConfig); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java index efdcfeb47..280d6040c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java @@ -129,7 +129,8 @@ public void absoluteGitDirRef() throws Exception { builder.setMustExist(true); Repository repo2 = builder.build(); - assertEquals(repo1.getDirectory(), repo2.getDirectory()); + assertEquals(repo1.getDirectory().getAbsolutePath(), repo2 + .getDirectory().getAbsolutePath()); assertEquals(dir, repo2.getWorkTree()); } @@ -167,7 +168,8 @@ public void scanWithGitDirRef() throws Exception { builder.setWorkTree(dir); builder.findGitDir(dir); - assertEquals(repo1.getDirectory(), builder.getGitDir()); + assertEquals(repo1.getDirectory().getAbsolutePath(), builder + .getGitDir().getAbsolutePath()); builder.setMustExist(true); Repository repo2 = builder.build(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java index 2b9c10777..383ff5011 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java @@ -171,8 +171,10 @@ public void apply(DirCacheEntry ent) { Repository subRepo = gen.getRepository(); addRepoToClose(subRepo); assertNotNull(subRepo); - assertEquals(modulesGitDir, subRepo.getDirectory()); - assertEquals(new File(db.getWorkTree(), path), subRepo.getWorkTree()); + assertEquals(modulesGitDir.getAbsolutePath(), + subRepo.getDirectory().getAbsolutePath()); + assertEquals(new File(db.getWorkTree(), path).getAbsolutePath(), + subRepo.getWorkTree().getAbsolutePath()); assertFalse(gen.next()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java index b9691836b..28a3f4428 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java @@ -231,7 +231,7 @@ public void testLocalTransportWithRelativePath() throws Exception { @Test public void testLocalTransportFetchWithoutLocalRepository() throws Exception { - URIish uri = new URIish("file://" + db.getWorkTree().getPath()); + URIish uri = new URIish("file://" + db.getWorkTree().getAbsolutePath()); transport = Transport.open(uri); FetchConnection fetchConnection = transport.openFetch(); try {