Browse Source

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
tags/v3.2.0.201311130903-m3
Shawn Pearce 10 years ago
parent
commit
75cfa03e16

+ 2
- 2
org.eclipse.jgit.ant.test/src/org/eclipse/jgit/ant/tasks/GitCloneTaskTest.java View File

public void shouldCloneAValidGitRepository() throws Exception { public void shouldCloneAValidGitRepository() throws Exception {
Repository repo = createBareRepository(); Repository repo = createBareRepository();
File directory = repo.getDirectory(); File directory = repo.getDirectory();
task.setUri("file://" + directory);
task.setUri("file://" + directory.getAbsolutePath());
task.execute(); task.execute();


assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED)); assertTrue(RepositoryCache.FileKey.isGitRepository(new File(dest, ".git"), FS.DETECTED));
public void shouldCreateABareCloneOfAValidGitRepository() throws Exception { public void shouldCreateABareCloneOfAValidGitRepository() throws Exception {
Repository repo = createBareRepository(); Repository repo = createBareRepository();
File directory = repo.getDirectory(); File directory = repo.getDirectory();
task.setUri("file://" + directory);
task.setUri("file://" + directory.getAbsolutePath());
task.setBare(true); task.setBare(true);
task.execute(); task.execute();



+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java View File

Git localGit = new Git(localRepository); Git localGit = new Git(localRepository);
StoredConfig config = localRepository.getConfig(); StoredConfig config = localRepository.getConfig();
RemoteConfig rc = new RemoteConfig(config, "origin"); 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.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
rc.update(config); rc.update(config);
config.save(); config.save();

+ 20
- 16
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java View File

File directory = createTempDirectory("testCloneRepository"); File directory = createTempDirectory("testCloneRepository");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertNotNull(git2); assertNotNull(git2);
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBare(true); command.setBare(true);
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertEquals(new RefSpec("+refs/heads/*:refs/heads/*"), assertEquals(new RefSpec("+refs/heads/*:refs/heads/*"),
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBranch("refs/heads/master"); command.setBranch("refs/heads/master");
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());


command = Git.cloneRepository(); command = Git.cloneRepository();
command.setBranch("refs/heads/master"); command.setBranch("refs/heads/master");
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setNoCheckout(true); command.setNoCheckout(true);
git2 = command.call(); git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
command = Git.cloneRepository(); command = Git.cloneRepository();
command.setBranch("refs/heads/master"); command.setBranch("refs/heads/master");
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setBare(true); command.setBare(true);
git2 = command.call(); git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBranch("test"); command.setBranch("test");
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());


CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setBranch("tag-initial"); command.setBranch("tag-initial");
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());


command.setBranchesToClone(Collections command.setBranchesToClone(Collections
.singletonList("refs/heads/master")); .singletonList("refs/heads/master"));
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertNotNull(git2); assertNotNull(git2);
command.setBranchesToClone(Collections command.setBranchesToClone(Collections
.singletonList("refs/heads/master")); .singletonList("refs/heads/master"));
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setBare(true); command.setBare(true);
git2 = command.call(); git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
File directory = createTempDirectory(dirName); File directory = createTempDirectory(dirName);
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertNotNull(git2); assertNotNull(git2);
// clone again // clone again
command = Git.cloneRepository(); command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
try { try {
git2 = command.call(); git2 = command.call();
// we shouldn't get here // we shouldn't get here
File directory = createTempDirectory("testCloneRepositoryWithMultipleHeadBranches"); File directory = createTempDirectory("testCloneRepositoryWithMultipleHeadBranches");
CloneCommand clone = Git.cloneRepository(); CloneCommand clone = Git.cloneRepository();
clone.setDirectory(directory); clone.setDirectory(directory);
clone.setURI("file://" + git.getRepository().getWorkTree().getPath());
clone.setURI(fileUri());
Git git2 = clone.call(); Git git2 = clone.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertNotNull(git2); assertNotNull(git2);
CloneCommand clone = Git.cloneRepository(); CloneCommand clone = Git.cloneRepository();
clone.setDirectory(directory); clone.setDirectory(directory);
clone.setCloneSubmodules(true); clone.setCloneSubmodules(true);
clone.setURI("file://" + git.getRepository().getWorkTree().getPath());
clone.setURI(fileUri());
Git git2 = clone.call(); Git git2 = clone.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertNotNull(git2); assertNotNull(git2);
File directory = createTempDirectory("testCloneRepository1"); File directory = createTempDirectory("testCloneRepository1");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertFalse(git2 assertFalse(git2
directory = createTempDirectory("testCloneRepository2"); directory = createTempDirectory("testCloneRepository2");
command = Git.cloneRepository(); command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
git2 = command.call(); git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertTrue(git2 assertTrue(git2
directory = createTempDirectory("testCloneRepository2"); directory = createTempDirectory("testCloneRepository2");
command = Git.cloneRepository(); command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
git2 = command.call(); git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
assertTrue(git2 assertTrue(git2
ConfigConstants.CONFIG_KEY_REBASE, false)); ConfigConstants.CONFIG_KEY_REBASE, false));


} }

private String fileUri() {
return "file://" + git.getRepository().getWorkTree().getAbsolutePath();
}
} }

+ 8
- 4
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java View File

File directory = createTempDirectory("testRepository"); File directory = createTempDirectory("testRepository");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
File directory = createTempDirectory("testRepository"); File directory = createTempDirectory("testRepository");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());
File directory = createTempDirectory("testRepository"); File directory = createTempDirectory("testRepository");
CloneCommand command = Git.cloneRepository(); CloneCommand command = Git.cloneRepository();
command.setDirectory(directory); command.setDirectory(directory);
command.setURI("file://" + git.getRepository().getWorkTree().getPath());
command.setURI(fileUri());
command.setCloneAllBranches(true); command.setCloneAllBranches(true);
Git git2 = command.call(); Git git2 = command.call();
addRepoToClose(git2.getRepository()); addRepoToClose(git2.getRepository());


@Test @Test
public void testLsRemoteWithoutLocalRepository() throws Exception { public void testLsRemoteWithoutLocalRepository() throws Exception {
String uri = "file://" + git.getRepository().getWorkTree().getPath();
String uri = fileUri();
Collection<Ref> refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call(); Collection<Ref> refs = Git.lsRemoteRepository().setRemote(uri).setHeads(true).call();
assertNotNull(refs); assertNotNull(refs);
assertEquals(2, refs.size()); assertEquals(2, refs.size());
} }


private String fileUri() {
return "file://" + git.getRepository().getWorkTree().getAbsolutePath();
}

} }

+ 3
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java View File

assertEquals(sourceCommit.getId(), mergedCommits[1]); assertEquals(sourceCommit.getId(), mergedCommits[1]);
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
.getNewHead()); .getNewHead());
String message = "Merge branch 'master' of " + db.getWorkTree();
String message = "Merge branch 'master' of "
+ db.getWorkTree().getAbsolutePath();
assertEquals(message, mergeCommit.getShortMessage()); assertEquals(message, mergeCommit.getShortMessage());
} }




config config
.addURI(new URIish(source.getRepository().getWorkTree() .addURI(new URIish(source.getRepository().getWorkTree()
.getPath()));
.getAbsolutePath()));
config.addFetchRefSpec(new RefSpec( config.addFetchRefSpec(new RefSpec(
"+refs/heads/*:refs/remotes/origin/*")); "+refs/heads/*:refs/remotes/origin/*"));
config.update(targetConfig); config.update(targetConfig);

+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java View File



config config
.addURI(new URIish(source.getRepository().getWorkTree() .addURI(new URIish(source.getRepository().getWorkTree()
.getPath()));
.getAbsolutePath()));
config.addFetchRefSpec(new RefSpec( config.addFetchRefSpec(new RefSpec(
"+refs/heads/*:refs/remotes/origin/*")); "+refs/heads/*:refs/remotes/origin/*"));
config.update(targetConfig); config.update(targetConfig);

+ 4
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java View File

builder.setMustExist(true); builder.setMustExist(true);
Repository repo2 = builder.build(); Repository repo2 = builder.build();


assertEquals(repo1.getDirectory(), repo2.getDirectory());
assertEquals(repo1.getDirectory().getAbsolutePath(), repo2
.getDirectory().getAbsolutePath());
assertEquals(dir, repo2.getWorkTree()); assertEquals(dir, repo2.getWorkTree());
} }




builder.setWorkTree(dir); builder.setWorkTree(dir);
builder.findGitDir(dir); builder.findGitDir(dir);
assertEquals(repo1.getDirectory(), builder.getGitDir());
assertEquals(repo1.getDirectory().getAbsolutePath(), builder
.getGitDir().getAbsolutePath());
builder.setMustExist(true); builder.setMustExist(true);
Repository repo2 = builder.build(); Repository repo2 = builder.build();



+ 4
- 2
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java View File

Repository subRepo = gen.getRepository(); Repository subRepo = gen.getRepository();
addRepoToClose(subRepo); addRepoToClose(subRepo);
assertNotNull(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()); assertFalse(gen.next());
} }



+ 1
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java View File

@Test @Test
public void testLocalTransportFetchWithoutLocalRepository() public void testLocalTransportFetchWithoutLocalRepository()
throws Exception { throws Exception {
URIish uri = new URIish("file://" + db.getWorkTree().getPath());
URIish uri = new URIish("file://" + db.getWorkTree().getAbsolutePath());
transport = Transport.open(uri); transport = Transport.open(uri);
FetchConnection fetchConnection = transport.openFetch(); FetchConnection fetchConnection = transport.openFetch();
try { try {

Loading…
Cancel
Save